Open steebchen opened 2 years ago
I would welcome such pull request, emojis are definitely in scope. :slightly_smiling_face: (Sorry for the delayed response @steebchen , in future it'll be better. As of now I'm back at it!)
I don't think heuristics over well-known env vars would work predictably - the lib is not specific to Cloud Run only.
Fair enough, I'm not sure how one could detect a local environment. Maybe via a custom env var 'ENV=development', which you could just set in your dev scripts if you wanted to.
I'm thinking to leave the environment variable to the caller, and instead create a setup func. A snippet for users would be like:
if os.GetEnv("MY_APP_ENV") == "development" {
log.SetFormatter(log.FormatForTerminalWithEmoji)
}
The default would be log.FormatForGoogle
if that naming makes sense. It's a func
so user could bring their own as well.
~And I don't think that the logging library is responsible for cleaning \u0026
, but the formatter for terminal use doesn't need to escape these sequences. It can print them exactly as they are, I mean &
.~ [Moved to #15]
I'm thinking to leave the environment variable to the caller, and instead create a setup func.
Ah, that is a smart idea. I like it!
This may be out of scope, but I was thinking if the logs could maybe render more beautiful locally. Instead of this, which looks not very readable:
First, it would be nice if locally there would be no escape characters displayed:
Second, I am thinking if this would be more useful to log locally (one could check if some env var is set, like an automatically set in cloud run /k8s or a custom one):