2021-11-16 12:13:58 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/anacrolix/log"
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
)
|
|
|
|
|
2023-09-05 15:05:27 +00:00
|
|
|
var _ log.Handler = &Torrent{}
|
2021-11-16 12:13:58 +00:00
|
|
|
|
|
|
|
type Torrent struct {
|
|
|
|
L zerolog.Logger
|
|
|
|
}
|
|
|
|
|
2023-09-05 15:05:27 +00:00
|
|
|
func (l *Torrent) Handle(r log.Record) {
|
2021-11-16 12:13:58 +00:00
|
|
|
e := l.L.Info()
|
2023-09-05 15:05:27 +00:00
|
|
|
switch r.Level {
|
2021-11-16 12:13:58 +00:00
|
|
|
case log.Debug:
|
|
|
|
e = l.L.Debug()
|
|
|
|
case log.Info:
|
|
|
|
e = l.L.Debug().Str("error-type", "info")
|
|
|
|
case log.Warning:
|
|
|
|
e = l.L.Warn()
|
|
|
|
case log.Error:
|
|
|
|
e = l.L.Warn().Str("error-type", "error")
|
|
|
|
case log.Critical:
|
|
|
|
e = l.L.Warn().Str("error-type", "critical")
|
|
|
|
}
|
|
|
|
|
2023-09-05 15:05:27 +00:00
|
|
|
// TODO set log values somehow
|
|
|
|
|
|
|
|
e.Msgf(r.Text())
|
2021-11-16 12:13:58 +00:00
|
|
|
}
|