mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-06-07 18:24:25 -04:00
move logger out of go-i2p so we can re-use it without importing the entire module
This commit is contained in:
1
go.mod
1
go.mod
@ -7,6 +7,7 @@ require (
|
||||
github.com/emirpasic/gods v1.18.1
|
||||
github.com/eyedeekay/go-unzip v0.0.0-20240201194209-560d8225b50e
|
||||
github.com/flynn/noise v1.1.0
|
||||
github.com/go-i2p/logger v0.0.0-20241121221545-ce7ceeba699a
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/spf13/viper v1.19.0
|
||||
|
2
go.sum
2
go.sum
@ -17,6 +17,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/go-i2p/logger v0.0.0-20241121221545-ce7ceeba699a h1:z19Zzn9uX/bGxzQ0XTSrXe+bl29XW60n6kUpg1elscA=
|
||||
github.com/go-i2p/logger v0.0.0-20241121221545-ce7ceeba699a/go.mod h1:qMpzyCtcUAeVIe38fKEmJyWoyGfLN2N9MmgiM6iQBdQ=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
// log "github.com/sirupsen/logrus"
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
)
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ package destination
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/keys_and_cert"
|
||||
|
@ -30,7 +30,7 @@ payload :: data
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/certificate"
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/certificate"
|
||||
. "github.com/go-i2p/go-i2p/lib/common/key_certificate"
|
||||
|
@ -4,7 +4,7 @@ package lease_set
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/certificate"
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/go-i2p/go-i2p/lib/common/key_certificate"
|
||||
. "github.com/go-i2p/go-i2p/lib/common/keys_and_cert"
|
||||
"github.com/go-i2p/go-i2p/lib/crypto"
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/crypto"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
. "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
|
@ -2,7 +2,7 @@
|
||||
package session_tag
|
||||
|
||||
import (
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ package signature
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/spf13/viper"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"crypto/cipher"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
common "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
"github.com/go-i2p/go-i2p/lib/common/session_key"
|
||||
"github.com/go-i2p/go-i2p/lib/tunnel"
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
)
|
||||
|
||||
var log = logger.GetGoI2PLogger()
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/eyedeekay/go-unzip/pkg/unzip"
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/bootstrap"
|
||||
|
@ -3,7 +3,7 @@ package router
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/config"
|
||||
|
@ -79,7 +79,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -3,7 +3,7 @@ package transport
|
||||
import (
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_identity"
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
)
|
||||
|
||||
var log = logger.GetGoI2PLogger()
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
|
||||
"github.com/flynn/noise"
|
||||
)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/flynn/noise"
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
)
|
||||
|
||||
var log = logger.GetGoI2PLogger()
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
|
||||
common "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||
"github.com/go-i2p/logger"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -1,129 +0,0 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
log *Logger
|
||||
once sync.Once
|
||||
failFast string
|
||||
)
|
||||
|
||||
// Logger wraps logrus.Logger and adds the ability to make all warnings fatal
|
||||
type Logger struct {
|
||||
*logrus.Logger
|
||||
}
|
||||
|
||||
// Entry wraps logrus.Entry and enables it to use our Logger
|
||||
type Entry struct {
|
||||
Logger
|
||||
entry *logrus.Entry
|
||||
}
|
||||
|
||||
// Warn wraps logrus.Warn and logs a fatal error if failFast is set
|
||||
func (l *Logger) Warn(args ...interface{}) {
|
||||
warnFatal(args)
|
||||
l.Logger.Warn(args...)
|
||||
}
|
||||
|
||||
// Warnf wraps logrus.Warnf and logs a fatal error if failFast is set
|
||||
func (l *Logger) Warnf(format string, args ...interface{}) {
|
||||
warnFatalf(format, args...)
|
||||
l.Logger.Warnf(format, args...)
|
||||
}
|
||||
|
||||
// Error wraps logrus.Error and logs a fatal error if failFast is set
|
||||
func (l *Logger) Error(args ...interface{}) {
|
||||
warnFatal(args)
|
||||
l.Logger.Error(args...)
|
||||
}
|
||||
|
||||
// Errorf wraps logrus.Errorf and logs a fatal error if failFast is set
|
||||
func (l *Logger) Errorf(format string, args ...interface{}) {
|
||||
warnFatalf(format, args...)
|
||||
l.Logger.Errorf(format, args...)
|
||||
}
|
||||
|
||||
// WithField wraps logrus.WithField and returns an Entry
|
||||
func (l *Logger) WithField(key string, value interface{}) *Entry {
|
||||
entry := l.Logger.WithField(key, value)
|
||||
return &Entry{*l, entry}
|
||||
}
|
||||
|
||||
// WithFields wraps logrus.WithFields and returns an Entry
|
||||
func (l *Logger) WithFields(fields logrus.Fields) *Entry {
|
||||
entry := l.Logger.WithFields(fields)
|
||||
return &Entry{*l, entry}
|
||||
}
|
||||
|
||||
// WithError wraps logrus.WithError and returns an Entry
|
||||
func (l *Logger) WithError(err error) *Entry {
|
||||
entry := l.Logger.WithError(err)
|
||||
return &Entry{*l, entry}
|
||||
}
|
||||
|
||||
func warnFatal(args ...interface{}) {
|
||||
if failFast != "" {
|
||||
log.Fatal(args)
|
||||
}
|
||||
}
|
||||
|
||||
func warnFatalf(format string, args ...interface{}) {
|
||||
if failFast != "" {
|
||||
log.Fatalf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func warnFail() {
|
||||
if failFast != "" {
|
||||
log.Error("FATAL ERROR")
|
||||
}
|
||||
}
|
||||
|
||||
// InitializeGoI2PLogger sets up all the necessary logging
|
||||
func InitializeGoI2PLogger() {
|
||||
once.Do(func() {
|
||||
log = &Logger{}
|
||||
log.Logger = logrus.New()
|
||||
// We do not want to log by default
|
||||
log.SetOutput(io.Discard)
|
||||
log.SetLevel(logrus.PanicLevel)
|
||||
// Check if DEBUG_I2P is set
|
||||
if logLevel := os.Getenv("DEBUG_I2P"); logLevel != "" {
|
||||
failFast = os.Getenv("WARNFAIL_I2P")
|
||||
if failFast != "" && logLevel == "" {
|
||||
logLevel = "debug"
|
||||
}
|
||||
log.SetOutput(os.Stdout)
|
||||
switch strings.ToLower(logLevel) {
|
||||
case "debug":
|
||||
log.SetLevel(logrus.DebugLevel)
|
||||
case "warn":
|
||||
log.SetLevel(logrus.WarnLevel)
|
||||
case "error":
|
||||
log.SetLevel(logrus.ErrorLevel)
|
||||
default:
|
||||
log.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
log.WithField("level", log.GetLevel()).Debug("Logging enabled.")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// GetGoI2PLogger returns the initialized Logger
|
||||
func GetGoI2PLogger() *Logger {
|
||||
if log == nil {
|
||||
InitializeGoI2PLogger()
|
||||
}
|
||||
return log
|
||||
}
|
||||
|
||||
func init() {
|
||||
InitializeGoI2PLogger()
|
||||
}
|
Reference in New Issue
Block a user