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

Can't stop Gin from writing to stderr and stdout #1901

Open
jfxio opened this issue Aug 3, 2021 · 0 comments
Open

Can't stop Gin from writing to stderr and stdout #1901

jfxio opened this issue Aug 3, 2021 · 0 comments

Comments

@jfxio
Copy link

jfxio commented Aug 3, 2021

Warn and Depcrecated in internal/log.go are initialized with their own instances of log.Logger hardwired to write to os.stderr and os.stdout. This is a problem for applications 1) wanting logs in a log file, 2) using a different logging system, or 3) formatting log entries in JSON.

It would be useful if pg/internal/log.c were moved to pg/log.c so they could be overriden. Alternatively, they could be initialized with the global log.Logger so that the mechanisms for override that would work for go-pg too. Or is there some other mechanism for configuring logging?

Expected Behavior

It should be possible to prevent go-pg from writing to stdout and stderr or at least control the formatting.

Current Behavior

The internal Warn() and Deprecate methods are hardwired via custom log.Logger instances to write plain text to stdout and stderr.

Possible Solution

  • Option 1: move pg/internal/log.c to pg/log.c allowing Warn and Deprecate to overridden
  • Option 2: initiialize them with "lib"'s global log.Logger allowing overrides there to work for go-pg
  • Option 3: have Warn & Deperate use gin.DefaultWriter and gin.DefaultErrorWriter insteand of their own (these can be overridden)

Context (Environment)

We want to emit JSON logs that we consume with a log aggregator. It breaks on non-JSON being emitted by Gin.

Possible Implementation

Options 1, 2 or 3 above.

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

No branches or pull requests

1 participant