apsystole / log

Go logging library for GCP App Engine, Cloud Run, Cloud Functions
MIT License
14 stars 1 forks source link

Feature request: improve logging UX locally #6

Open steebchen opened 2 years ago

steebchen commented 2 years ago

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:

{"message":"asdf","severity":"CRITICAL","Field":"sup"}
{"message":"asdf","severity":"INFO"}
{"message":"asdf","severity":"ERROR"}
{"message":"asdf","severity":"ALERT"}

First, it would be nice if locally there would be no escape characters displayed:

image

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):

⚠️ asdf
❌ asdf
❗ asdf { "Field": "sup" }
jabielecki commented 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.

steebchen commented 2 years ago

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.

jabielecki commented 2 years ago

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]

steebchen commented 2 years ago

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!