The client supports logging debug information via go's standard logger. This logger should be configurable to ensure things like buffering work and the log output of an application stays consistent.
Attempted Solutions
One could write an adapter for stdlog that implements io.Writer and writes to the logger used in that application. This has 2 downsides IMO:
Log format differs from application logger since it just redirects what stdlog would write normally
Has to be implemented for each application or library using the SDK
Proposal
Use an interface as logger and allow users to set it. The logger could be a package variable or a field in the client struct. The default would remain stdlog.
Here's a rough draft:
import "log"
type Logger interface {
Printf(format string, args ...interface{})
}
var logger Logger = log.Default()
func SetLogger(l Logger) {
logger = l
}
func (c *APIClient) SetLogger(l Logger) {
c.logger = l
}
...
if c.cfg.Debug {
c.logger.Printf("debug output")
}
Loggers that don't implement a Printf would still need an adapter, but at least the output would be uniform.
Current SDK Version
Use-cases
The client supports logging debug information via go's standard logger. This logger should be configurable to ensure things like buffering work and the log output of an application stays consistent.
Attempted Solutions
One could write an adapter for stdlog that implements
io.Writer
and writes to the logger used in that application. This has 2 downsides IMO:Proposal
Use an interface as logger and allow users to set it. The logger could be a package variable or a field in the client struct. The default would remain stdlog.
Here's a rough draft:
Loggers that don't implement a
Printf
would still need an adapter, but at least the output would be uniform.References