!WIP! - added logging
This commit is contained in:
34
I2PAddr.go
34
I2PAddr.go
@ -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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user