mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
c0f100f1b5
* Add add adapter between io.Writer and log.Logger * Add phantomjs output to grafana log * Unexport LogWriterImpl * Add test for LogWriter * Make it possible to get phantomjs debug output * Make it possible to get the configured log level
40 lines
604 B
Go
40 lines
604 B
Go
package log
|
|
|
|
import (
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
type logWriterImpl struct {
|
|
log Logger
|
|
level Lvl
|
|
prefix string
|
|
}
|
|
|
|
func NewLogWriter(log Logger, level Lvl, prefix string) io.Writer {
|
|
return &logWriterImpl{
|
|
log: log,
|
|
level: level,
|
|
prefix: prefix,
|
|
}
|
|
}
|
|
|
|
func (l *logWriterImpl) Write(p []byte) (n int, err error) {
|
|
message := l.prefix + strings.TrimSpace(string(p))
|
|
|
|
switch l.level {
|
|
case LvlCrit:
|
|
l.log.Crit(message)
|
|
case LvlError:
|
|
l.log.Error(message)
|
|
case LvlWarn:
|
|
l.log.Warn(message)
|
|
case LvlInfo:
|
|
l.log.Info(message)
|
|
default:
|
|
l.log.Debug(message)
|
|
}
|
|
|
|
return len(p), nil
|
|
}
|