Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat logging #25

Merged
merged 7 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

# Dependency directories (remove the comment below to include it)
# vendor/
.vscode/
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ require (
github.com/go-chi/chi/v5 v5.0.7
github.com/go-redis/redis v6.15.9+incompatible
github.com/json-iterator/go v1.1.12
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/pires/go-proxyproto v0.6.2
github.com/sirupsen/logrus v1.8.1
github.com/skycoin/skycoin v0.27.1
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
)

require (
Expand All @@ -21,7 +23,6 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
Expand All @@ -31,8 +32,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cipher/cipher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

"github.com/skycoin/skycoin/src/util/logging"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdutil/service_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"unicode"

jsoniter "github.com/json-iterator/go"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdutil/sysloghook_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/sirupsen/logrus"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/skycoin/skywire-utilities/pkg/logging"
)

func (sf *ServiceFlags) sysLogHook(log *logging.Logger, sysLvl int) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdutil/sysloghook_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/skycoin/skywire-utilities/pkg/logging"
)

func (sf *ServiceFlags) sysLogHook(_ *logging.Logger, _ int) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/geo/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"

"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/skycoin/skywire-utilities/pkg/logging"

"github.com/skycoin/skywire-utilities/pkg/netutil"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/httpauth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"net/url"
"strings"

"github.com/skycoin/skycoin/src/util/logging"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/httputil"
"github.com/skycoin/skywire-utilities/pkg/logging"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/go-chi/chi/v5/middleware"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/skycoin/skywire-utilities/pkg/logging"
)

var json = jsoniter.ConfigFastest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/mgutz/ansi"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

const defaultTimestampFormat = time.RFC3339
Expand All @@ -26,6 +26,7 @@ var (
FatalLevelStyle: "red",
PanicLevelStyle: "red",
DebugLevelStyle: "blue",
TraceLevelStyle: "black",
PrefixStyle: "cyan",
TimestampStyle: "black+h",
CallContextStyle: "black+h",
Expand All @@ -38,6 +39,7 @@ var (
FatalLevelColor: ansi.ColorFunc(""),
PanicLevelColor: ansi.ColorFunc(""),
DebugLevelColor: ansi.ColorFunc(""),
TraceLevelColor: ansi.ColorFunc(""),
PrefixColor: ansi.ColorFunc(""),
TimestampColor: ansi.ColorFunc(""),
CallContextColor: ansi.ColorFunc(""),
Expand All @@ -58,6 +60,7 @@ type ColorScheme struct {
FatalLevelStyle string
PanicLevelStyle string
DebugLevelStyle string
TraceLevelStyle string
PrefixStyle string
TimestampStyle string
CallContextStyle string
Expand All @@ -71,6 +74,7 @@ type compiledColorScheme struct {
FatalLevelColor func(string) string
PanicLevelColor func(string) string
DebugLevelColor func(string) string
TraceLevelColor func(string) string
PrefixColor func(string) string
TimestampColor func(string) string
CallContextColor func(string) string
Expand Down Expand Up @@ -149,6 +153,7 @@ func compileColorScheme(s *ColorScheme) *compiledColorScheme {
FatalLevelColor: getCompiledColor(s.FatalLevelStyle, defaultColorScheme.FatalLevelStyle),
PanicLevelColor: getCompiledColor(s.PanicLevelStyle, defaultColorScheme.PanicLevelStyle),
DebugLevelColor: getCompiledColor(s.DebugLevelStyle, defaultColorScheme.DebugLevelStyle),
TraceLevelColor: getCompiledColor(s.TraceLevelStyle, defaultColorScheme.TraceLevelStyle),
PrefixColor: getCompiledColor(s.PrefixStyle, defaultColorScheme.PrefixStyle),
TimestampColor: getCompiledColor(s.TimestampStyle, defaultColorScheme.TimestampStyle),
CallContextColor: getCompiledColor(s.CallContextStyle, defaultColorScheme.CallContextStyle),
Expand All @@ -168,7 +173,7 @@ func (f *TextFormatter) init(entry *logrus.Entry) {
func (f *TextFormatter) checkIfTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
return terminal.IsTerminal(int(v.Fd()))
return term.IsTerminal(int(v.Fd()))
default:
return false
}
Expand Down Expand Up @@ -249,6 +254,8 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry, keys
levelColor = colorScheme.FatalLevelColor
case logrus.PanicLevel:
levelColor = colorScheme.PanicLevelColor
case logrus.TraceLevel:
levelColor = colorScheme.TraceLevelColor
default:
levelColor = colorScheme.DebugLevelColor
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ func (logger *MasterLogger) PackageLogger(moduleName string) *Logger {
}
}

// AddHook adds a logrus.Hook to the logger and its module loggers
func (logger *MasterLogger) AddHook(hook logrus.Hook) {
logger.Hooks.Add(hook)
}

// SetLevel sets the log level for the logger and its module loggers
func (logger *MasterLogger) SetLevel(level logrus.Level) {
logger.Level = level
}

// EnableColors enables colored logging
func (logger *MasterLogger) EnableColors() {
logger.Formatter.(*TextFormatter).DisableColors = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func LevelFromString(s string) (logrus.Level, error) {
return logrus.FatalLevel, nil
case "panic":
return logrus.PanicLevel, nil
case "trace":
return logrus.TraceLevel, nil
default:
return logrus.DebugLevel, errors.New("could not convert string to log level")
}
Expand Down Expand Up @@ -68,6 +70,11 @@ func SetLevel(level logrus.Level) {
log.SetLevel(level)
}

// GetLevel returns the logger level
func GetLevel() logrus.Level {
return log.GetLevel()
}

// SetOutputTo sets the logger's output to an io.Writer
func SetOutputTo(w io.Writer) {
log.Out = w
Expand Down
9 changes: 7 additions & 2 deletions pkg/netutil/retrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package netutil
import (
"context"
"errors"
"fmt"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -36,14 +37,16 @@ type Retrier struct {

// NewRetrier returns a retrier that is ready to call Do() method
func NewRetrier(log logrus.FieldLogger, initBO, maxBO time.Duration, tries int64, factor float64) *Retrier {
logger := log.WithField("func", "retrier")
if log != nil {
log = log.WithField("func", "retrier")
}
return &Retrier{
initBO: initBO,
maxBO: maxBO,
tries: tries,
factor: factor,
errWl: make(map[error]struct{}),
log: logger,
log: log,
}
}

Expand Down Expand Up @@ -82,6 +85,8 @@ func (r *Retrier) Do(ctx context.Context, f RetryFunc) error {
case <-t.C:
if r.log != nil {
r.log.WithError(err).WithField("current_backoff", bo).Warn("Retrying...")
} else {
fmt.Printf("func = retrier, current_backoff = %v Retrying...\n", bo)
}
t.Reset(bo)
continue
Expand Down
3 changes: 0 additions & 3 deletions vendor/golang.org/x/crypto/AUTHORS

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/golang.org/x/crypto/CONTRIBUTORS

This file was deleted.

27 changes: 0 additions & 27 deletions vendor/golang.org/x/crypto/LICENSE

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/golang.org/x/crypto/PATENTS

This file was deleted.

76 changes: 0 additions & 76 deletions vendor/golang.org/x/crypto/ssh/terminal/terminal.go

This file was deleted.

Loading