36

In Google Stackdriver advanced filter I can insert something like:

resource.type="container"
resource.labels.cluster_name="mycluster"
textPayload!="Metric stackdriver_sink_successfully_sent_entry_count was not found in the cache."
severity="INFO"
textPayload:(helloworld)

The last rule means that the field textPayload should contain the string helloworld. But I'm not able to find a way to add a NOT operator.

I would use something like:

textPayload:!(helloworld)

but doesn't work

suikoy
  • 2,229
  • 3
  • 19
  • 23
  • Welcome to SO! Please take the [tour] and read "[ask]", "[Stack Overflow question checklist](https://meta.stackoverflow.com/questions/260648)", "[mre]" and their linked pages. Please explain what "doesn't work" mean in detail. – the Tin Man Mar 02 '22 at 23:25

3 Answers3

54

just add AND NOT between two rows:

resource.type="container"
resource.labels.cluster_name="mycluster"
textPayload!="Metric stackdriver_sink_successfully_sent_entry_count was not found in the cache."
severity="INFO" AND NOT
textPayload:(helloworld)
suikoy
  • 2,229
  • 3
  • 19
  • 23
  • I'm not sure what the difference is but for me I had to prefix the textPayload with a tilde like `~textPayload:" text I dont want"` for it to work – Max Carroll May 10 '21 at 16:13
16

You can use the filter-text:unicorn if you want to exclude entries containing the word "unicorn"

Source: https://cloud.google.com/logging/docs/view/basic-filters

javierdvalle
  • 2,473
  • 1
  • 13
  • 15
  • just fyi, this works. But if you try to create a metric with the same query and then see it in the metric explorer, it shows "Selected metric is invalid." error. So @suikoy's answer might work better for those who use log based metrics – Yasha May 08 '20 at 04:46
0

There is sometimes \n at the end by the way.

Also you can click on log, click sub entry and clik hide.

Mohamed
  • 1,251
  • 3
  • 15
  • 36