How to use a dashboard variable into a line filter with LogQL

We can use dashboard variables with labels in the queries
For example:

{job="logs", Level=~"$Level"}

I am looking for a way to use a variable with a line filter like so:

{job="logs", Level=~"$Level"} |= `"User":"$User"`

My log is in json format (That’s why i’m doing a regex search with the " ")

I have found this forum: Using A Variable To Filter Loki Results but it has not helped me and I would need the “All” option to work.

Thank you!

If you want to use the all option, try:

  1. Set the variable all value to .+.
  2. Change your query to
{job="logs", Level=~"$Level"} |~ `"User":"$User"`

You might also consider adding the line start and end character ^ and $ so you don’t accidentally present partial matches.