forked from TrueCloudLab/frostfs-http-gw
parent
d1bdef6f83
commit
d891c13cb3
6 changed files with 60 additions and 76 deletions
57
main.go
57
main.go
|
@ -2,12 +2,13 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/nspcc-dev/neofs-sdk-go/logger"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -21,25 +22,45 @@ func main() {
|
|||
app.Wait()
|
||||
}
|
||||
|
||||
// newLogger constructs a zap.Logger instance for current application.
|
||||
// Panics on failure.
|
||||
//
|
||||
// Logger is built from zap's production logging configuration with:
|
||||
// * parameterized level (debug by default)
|
||||
// * console encoding
|
||||
// * ISO8601 time encoding
|
||||
//
|
||||
// Logger records a stack trace for all messages at or above fatal level.
|
||||
//
|
||||
// See also zapcore.Level, zap.NewProductionConfig, zap.AddStacktrace.
|
||||
func newLogger(v *viper.Viper) *zap.Logger {
|
||||
options := []logger.Option{
|
||||
logger.WithLevel(v.GetString(cfgLoggerLevel)),
|
||||
logger.WithTraceLevel(v.GetString(cfgLoggerTraceLevel)),
|
||||
logger.WithFormat(v.GetString(cfgLoggerFormat)),
|
||||
logger.WithSamplingInitial(v.GetInt(cfgLoggerSamplingInitial)),
|
||||
logger.WithSamplingThereafter(v.GetInt(cfgLoggerSamplingThereafter)),
|
||||
logger.WithAppName(v.GetString(cfgApplicationName)),
|
||||
logger.WithAppVersion(v.GetString(cfgApplicationVersion)),
|
||||
}
|
||||
if v.GetBool(cfgLoggerNoCaller) {
|
||||
options = append(options, logger.WithoutCaller())
|
||||
}
|
||||
if v.GetBool(cfgLoggerNoDisclaimer) {
|
||||
options = append(options, logger.WithoutDisclaimer())
|
||||
}
|
||||
l, err := logger.New(options...)
|
||||
var lvl zapcore.Level
|
||||
lvlStr := v.GetString(cfgLoggerLevel)
|
||||
err := lvl.UnmarshalText([]byte(lvlStr))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(fmt.Sprintf("incorrect logger level configuration %s (%v), "+
|
||||
"value should be one of %v", lvlStr, err, [...]zapcore.Level{
|
||||
zapcore.DebugLevel,
|
||||
zapcore.InfoLevel,
|
||||
zapcore.WarnLevel,
|
||||
zapcore.ErrorLevel,
|
||||
zapcore.DPanicLevel,
|
||||
zapcore.PanicLevel,
|
||||
zapcore.FatalLevel,
|
||||
}))
|
||||
}
|
||||
|
||||
c := zap.NewProductionConfig()
|
||||
c.Level = zap.NewAtomicLevelAt(lvl)
|
||||
c.Encoding = "console"
|
||||
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
|
||||
l, err := c.Build(
|
||||
zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)),
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("build zap logger instance: %v", err))
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue