!WIP! - added logging

This commit is contained in:
Haris Khan
2024-10-14 23:28:25 -04:00
parent 0ef26b9207
commit c1b05d6ede
2 changed files with 39 additions and 0 deletions

View File

@ -10,7 +10,9 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/sirupsen/logrus"
"io"
"io/ioutil"
"net"
"os"
"strings"
@ -19,8 +21,40 @@ import (
var (
i2pB64enc *base64.Encoding = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~")
i2pB32enc *base32.Encoding = base32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")
log *logrus.Logger
)
func init() {
log = logrus.New()
// We do not want to log by default
log.SetOutput(ioutil.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 "trace":
log.SetLevel(logrus.TraceLevel)
case "debug":
log.SetLevel(logrus.DebugLevel)
case "info":
log.SetLevel(logrus.InfoLevel)
case "warn":
log.SetLevel(logrus.WarnLevel)
case "error":
log.SetLevel(logrus.ErrorLevel)
default:
log.SetLevel(logrus.WarnLevel)
}
log.WithField("level", log.GetLevel()).Info("Logging enabled.")
}
}
// If you set this to true, Addr will return a base64 String()
var StringIsBase64 bool