go-pg / pg

Golang ORM with focus on PostgreSQL features and performance
https://pg.uptrace.dev/
BSD 2-Clause "Simplified" License
5.67k stars 404 forks source link

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

Open jfxio opened 3 years ago

jfxio commented 3 years ago

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

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.