-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(logging)_: switch to zap.Logger as central logger
Set zap.Logger as the primary logger for status-go. All geth logs are now proxied through zap.Logger. closes: #6029
- Loading branch information
Showing
19 changed files
with
227 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,12 @@ import ( | |
var logger = log.New("package", "status-go/cmd/node-canary") | ||
|
||
var ( | ||
staticEnodeAddr = flag.String("staticnode", "", "checks if static node talks waku protocol (e.g. enode://[email protected]:30303)") | ||
minPow = flag.Float64("waku.pow", params.WakuMinimumPoW, "PoW for messages to be added to queue, in float format") | ||
ttl = flag.Int("waku.ttl", params.WakuTTL, "Time to live for messages, in seconds") | ||
homePath = flag.String("home-dir", ".", "Home directory where state is stored") | ||
logLevel = flag.String("log", "INFO", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`) | ||
logFile = flag.String("logfile", "", "Path to the log file") | ||
logWithoutColors = flag.Bool("log-without-color", false, "Disables log colors") | ||
staticEnodeAddr = flag.String("staticnode", "", "checks if static node talks waku protocol (e.g. enode://[email protected]:30303)") | ||
minPow = flag.Float64("waku.pow", params.WakuMinimumPoW, "PoW for messages to be added to queue, in float format") | ||
ttl = flag.Int("waku.ttl", params.WakuTTL, "Time to live for messages, in seconds") | ||
homePath = flag.String("home-dir", ".", "Home directory where state is stored") | ||
logLevel = flag.String("log", "INFO", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`) | ||
logFile = flag.String("logfile", "", "Path to the log file") | ||
) | ||
|
||
func main() { | ||
|
@@ -58,12 +57,12 @@ func main() { | |
func init() { | ||
flag.Parse() | ||
|
||
colors := !(*logWithoutColors) | ||
if colors { | ||
colors = terminal.IsTerminal(int(os.Stdin.Fd())) | ||
} | ||
|
||
if err := logutils.OverrideRootLog(*logLevel != "", *logLevel, logutils.FileOptions{Filename: *logFile}, colors); err != nil { | ||
err := logutils.OverrideRootLoggerWithConfig(logutils.LogSettings{ | ||
Enabled: *logLevel != "", | ||
Level: *logLevel, | ||
File: *logFile, | ||
}) | ||
if err != nil { | ||
stdlog.Fatalf("Error initializing logger: %s", err) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,52 @@ | ||
package logutils | ||
|
||
import ( | ||
"io" | ||
"sync" | ||
"time" | ||
|
||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/status-im/status-go/protocol/zaputil" | ||
) | ||
|
||
var ( | ||
_zapLogger *zap.Logger | ||
_initZapLogger sync.Once | ||
) | ||
|
||
// ZapLogger creates a custom zap.Logger which will forward logs | ||
// to status-go logger. | ||
func ZapLogger() *zap.Logger { | ||
_initZapLogger.Do(func() { | ||
var err error | ||
_zapLogger, err = NewZapLoggerWithAdapter(log.Root()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_zapLogger = defaultLogger() | ||
|
||
// forward geth logs to zap logger | ||
_gethLogger := _zapLogger.Named("geth") | ||
log.Root().SetHandler(gethAdapter(_gethLogger)) | ||
}) | ||
return _zapLogger | ||
} | ||
|
||
func defaultLogger() *zap.Logger { | ||
core := NewCore( | ||
defaultEncoder(), | ||
zapcore.AddSync(io.Discard), | ||
zap.NewAtomicLevelAt(zap.InfoLevel), | ||
) | ||
return zap.New(core) | ||
} | ||
|
||
func defaultEncoder() zapcore.Encoder { | ||
encoderConfig := zap.NewDevelopmentEncoderConfig() | ||
encoderConfig.EncodeTime = utcTimeEncoder(encoderConfig.EncodeTime) | ||
encoderConfig.EncodeCaller = zapcore.FullCallerEncoder | ||
|
||
return zaputil.NewConsoleHexEncoder(encoderConfig) | ||
} | ||
|
||
func utcTimeEncoder(encoder zapcore.TimeEncoder) zapcore.TimeEncoder { | ||
return func(t time.Time, enc zapcore.PrimitiveArrayEncoder) { | ||
encoder(t.UTC(), enc) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.