Add and remove torrents from web interface (#84)
This commit is contained in:
parent
02842b1917
commit
2f18213660
49 changed files with 996 additions and 1170 deletions
27
log/badger.go
Normal file
27
log/badger.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Badger struct {
|
||||
L zerolog.Logger
|
||||
}
|
||||
|
||||
func (l *Badger) Errorf(m string, f ...interface{}) {
|
||||
l.L.Error().Msgf(strings.ReplaceAll(m, "\n", ""), f...)
|
||||
}
|
||||
|
||||
func (l *Badger) Warningf(m string, f ...interface{}) {
|
||||
l.L.Warn().Msgf(strings.ReplaceAll(m, "\n", ""), f...)
|
||||
}
|
||||
|
||||
func (l *Badger) Infof(m string, f ...interface{}) {
|
||||
l.L.Info().Msgf(strings.ReplaceAll(m, "\n", ""), f...)
|
||||
}
|
||||
|
||||
func (l *Badger) Debugf(m string, f ...interface{}) {
|
||||
l.L.Debug().Msgf(strings.ReplaceAll(m, "\n", ""), f...)
|
||||
}
|
39
log/torrent.go
Normal file
39
log/torrent.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"github.com/anacrolix/log"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
var _ log.LoggerImpl = &Torrent{}
|
||||
|
||||
type Torrent struct {
|
||||
L zerolog.Logger
|
||||
}
|
||||
|
||||
func (l *Torrent) Log(m log.Msg) {
|
||||
level, ok := m.GetLevel()
|
||||
|
||||
e := l.L.Info()
|
||||
|
||||
if !ok {
|
||||
level = log.Debug
|
||||
}
|
||||
|
||||
switch level {
|
||||
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")
|
||||
case log.Fatal:
|
||||
e = l.L.Warn().Str("error-type", "fatal")
|
||||
}
|
||||
|
||||
e.Msgf(m.String())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue