grafana-lokilogql

How to search multiple strings in same entry in Loki


Im trying to filter out log entries which matche two strings given. The log entries are not json compatible so it cannot be parsed to json. Example log entry looks like

[INFO ] (-Worker-10) com.xx.yy.logging.UserLog  Ys5morE1Kd8AkGxysKiNQgAAAsY - [customer : 20] some other text[player : 123456] 

I'm trying to filter all the entries which has both customer: 20 and player : 123456.

I tried

{app="xx",filename="xx.log"} |~ "(.*customer : 20 | player : 123456.*)" 
{app="xx",filename="xx.log"} |~ "(customer : 20 | player : 123456)" 
{app="xx",filename="xx.log"} |~ ".*customer : 20.* .*player : 123456*." 

but none of these above helped me to get the entries which has both these values. any idea ? Thanks


Solution

  • To query for multiple terms with LogQL do the following

    {job="JOB_NAME"} |= `KEY_TERM_1` |= `KEY_TERM_2`
    
    

    Or in your specific case

    {app="xx",filename="xx.log"} |= "customer : 20" |= "player : 123456"