Files
go-sam-go/log.go
Call me Phil 0e35eb2df3 Clean up and fixes
-  Define and use a few constants for the sake of code maintainability
- Change log package name to logger so it better reflects its purpose
- Fix depredations
-  Drop unused private methods and constants
- Create an auxiliary func newFromPrimary() to reduce code duplicacy. Also straight away type conversion doesn't seem to type-check. Got to explicitly create a new struct instance.
2025-03-12 21:39:23 +00:00

53 lines
1005 B
Go

// package sam3 wraps the original sam3 API from github.com/go-i2p/sam3
package sam3
import (
"io"
"os"
"strings"
"sync"
"github.com/sirupsen/logrus"
)
var (
log *logrus.Logger
once sync.Once
)
func InitializeSAM3Logger() {
once.Do(func() {
log = 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 != "" {
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.")
}
})
}
// GetSAM3Logger returns the initialized logger
func GetSAM3Logger() *logrus.Logger {
if log == nil {
InitializeSAM3Logger()
}
return log
}
func init() {
InitializeSAM3Logger()
}