grafana/pkg/log/log_writer.go
Mikael Olenfalk c0f100f1b5 Improve logging in the phantomjs renderer (#10697)
* 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
2018-02-01 14:04:52 +01:00

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
}