I noticed this package is deprecated, per the documentation here: https://cloud.google.com/appengine/docs/standard/go/go-differences
What is the correct way to log on Go 1.12+ without losing log levels by simply printing? (DEBUG/INFO/WARNING/ERROR/CRITICAL/etc.)
You have at least 2 solutions :
logrus
) and a special Stackdriver adapter to have logs with the right format and right level in Stackdriver loggingUse cloud.google.com/go/logging
This is the default solution I think :
But it can be tedious to create an
Entry
object every time you want to log something. If you want to just writelog.Debug
,log.Info
, of course you can create functionslogDebug
,logInfo
, etc, but you can also use another solution (based on logrus).Use logrus and Stackdriver adapter
As I said, you can use
logrus
) which is pretty common for logging in Go projects. But you need to make a small modification to transform the default text log to a log entry format that Stackdriver can understand.Result is the following (notice the right levels) :