3

I have a third-party go based app that is writing logs to stderr. Even though the log message is written as an INFO message stackdriver classifies it as ERROR because the log message is written to stderr (which seems to be default for golang logger).

Below is an example of an INFO message, but logged as ERROR

textPayload: "2022-04-05T16:41:38.369Z INFO controller.CertificateRequest CertificateRequest is Ready, ignoring. {"certificaterequest": "elasticsearch/es-http-tls-trs4t", "cr": {"namespace": "elasticsearch", "name": "es-http-tls-trs4t"}} "

Is it possible reclassify log messages based on payload tags?

I would like to classify above message as an Info rather than error so my logging alerts doesn't go crazy

RandomQuests
  • 635
  • 4
  • 16
  • 1
    Interesting question. Your hypothesis is accurate. By default, Golang `log`s are sent to `stderr`. I'm going to check whether Log Router permits mapping logs like this (I think it doesn't) as that would be a way to intercept logs before their shipped to Cloud Logging. However (!) fortunately, you're using GKE and it uses an agent for (container) log collection. I think you **may** be able to (I've not done this) customize your cluster's logging agent to map these log entries. – DazWilkin Apr 06 '22 at 23:04
  • Your application logs must have a json field **Severity** defined as [INFO](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity) in order to appear as an INFO message. Here's an [example](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) of a LogEntry with the "severity" field. – Alex G Apr 07 '22 at 11:37
  • @AlexG the third-party app is spitting logs as text message, not a JSON. – RandomQuests Apr 10 '22 at 00:51

1 Answers1

0

Here is an interesting link:

https://huynvk.dev/blog/4-tips-for-logging-on-gcp-using-golang-and-logrus

You should use logrus and hooks. They work the same way as aspect-oriented programming in java. Anyway logrus is in maintenance status on github. Otherwise you could refer to Zap or Apex (logrus design based).

https://github.com/uber-go/zap

https://github.com/apex/log

Saxon
  • 739
  • 3
  • 6
  • If I am doing an app I will pickup logrus or update golang logger to log info, warning and debug to stdout and errors to stderr. Since this is a third-party app I don't have control on logger choice – RandomQuests Apr 11 '22 at 17:10