!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" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"github.com/sirupsen/logrus"
"io" "io"
"io/ioutil"
"net" "net"
"os" "os"
"strings" "strings"
@ -19,8 +21,40 @@ import (
var ( var (
i2pB64enc *base64.Encoding = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~") i2pB64enc *base64.Encoding = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~")
i2pB32enc *base32.Encoding = base32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567") 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() // If you set this to true, Addr will return a base64 String()
var StringIsBase64 bool var StringIsBase64 bool

5
go.mod
View File

@ -1,3 +1,8 @@
module github.com/eyedeekay/i2pkeys module github.com/eyedeekay/i2pkeys
go 1.17 go 1.17
require (
github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
)