photoprism/internal/event/log_writer.go
Michael Mayer cab5efba36 Logging: Add output writer wrapper so the default logger can use Logrus
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-12-23 01:35:59 +01:00

24 lines
413 B
Go

package event
import "github.com/sirupsen/logrus"
// LogWriter is an output writer wrapper for using Logrus with the standard logger.
type LogWriter struct {
Log Logger
Level logrus.Level
}
// Write implements io.Writer.
func (w *LogWriter) Write(b []byte) (int, error) {
n := len(b)
if n > 0 && b[n-1] == '\n' {
b = b[:n-1]
}
if w.Log != nil {
w.Log.Log(w.Level, string(b))
}
return n, nil
}