Hi folks,
I'm not sure if this is more applicable for golang-nuts or golang-dev, so starting here.
I know that the issue of logging has been discussed many times, and there is concern about expanding the base log package. Building a light logging package on top of it is a good compromise.
Currently, any logging wrapper will need to use the log.Output function for the following reason:
- All the log.XXX methods eventually call log.Output with a calldepth of 2. For any wrapper, that calldepth will be wrong.
However, a logging package which wants to log messages asynchronously, or outside the call stack, will run into issues. I built a simple logging package where clients send log records over a channel, and the logging package receives and records them. This scenario presents the following issues:
- timestamp on the messages is wrong (if there's some buffering on the channel)
- PC information (file, line) is not available
Looking at the log.go source, this can easily be remedied by adding a log.Output method variant as below:
func (l *Logger) OutputR(nanoseconds int64, file string, line int, message string) os.Error
func (l *Logger) Output(calldepth int, s string) os.Error
log.go will refactor Output to call OutputR, and wrappers can call log.OutputR directly.
Wrappers can then package the PC info (file, line) along with a timestamp (nanoseconds) in a log record (along with message format and parameters), and pass this to log.OutputR at logging time.
Is this something that the GO team is willing to do?