Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: better logging settings, log client in certain logs #63

Merged
merged 1 commit into from
Sep 13, 2022

Conversation

brianluong
Copy link
Member

@brianluong brianluong commented Sep 13, 2022

Description

  • Logging client in certain logs is very helpful
  • Make the log formats between production/development mode the same. Single format allows for consistent ingestion on the Datadog side. Also format log timestamps as human readable timestamps instead of epoch millis.

Type of change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 😎 New feature (non-breaking change which adds functionality)
  • ⁉️ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • ⚒️ Refactor (no functional changes)
  • 📖 Documentation (updating or adding docs)

How Has This Been Tested?

-e ENV=production -e LOG_LEVEL=debug works

Copy link
Member

@dianwen dianwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client logging changes look good! Left a comment about the dev logging config.

} else {
logger, err = zap.NewDevelopment()
zapConfig := zap.NewDevelopmentConfig()
zapConfig.Encoding = "json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find JSON in development really hard to read, which makes developing slower.

Taking a step back, what's the use case for sending dev logs to datadog?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging is only controlled by the development/production flags atm. So to get debug logs we have to turn on development. We might want to do this for debugging issues.

Zap's baked in development config has more than just debug logs. For example it includes stack traces for anything above warn.

The better solution perhaps is to expose a parameter called log level, and pipe that into the zap logger's config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha.

Yeah, exposing log level as an env variable makes a lot of sense. No need to always couple the log level to the logging environment.

Copy link
Member

@dianwen dianwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 :shipit:!

func setupGlobalLogger(env, logLevel string) (logger *zap.Logger, err error) {
if env == "" || env == "production" {
if logLevel == "" {
logLevel = "info"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting into a defaultProductionLogLevel constant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same w/ development

@brianluong brianluong merged commit 6ca89fc into main Sep 13, 2022
@brianluong brianluong deleted the logging_improvements branch September 13, 2022 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants