Add and remove torrents from web interface ()

This commit is contained in:
Antonio Navarro Perez 2021-11-16 13:13:58 +01:00 committed by GitHub
parent 02842b1917
commit 2f18213660
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 996 additions and 1170 deletions

27
log/badger.go Normal file
View 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
View 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())
}