forked from TrueCloudLab/frostfs-http-gw
NSPCC-493 Separate repository for NeoFS GW
- Update dependencies - Update README (configuration: flags section) - Add gRPC logger and flag to enable gRPC connection debugging - Refactored settings (add flags, use defaults instead of yaml representation)
This commit is contained in:
parent
2bebf38a18
commit
97d1a99f58
8 changed files with 425 additions and 209 deletions
64
logger.go
64
logger.go
|
@ -3,11 +3,17 @@ package main
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"google.golang.org/grpc/grpclog"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
type zapLogger struct {
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
const (
|
||||
formatJSON = "json"
|
||||
formatConsole = "console"
|
||||
|
@ -16,6 +22,14 @@ const (
|
|||
defaultSamplingThereafter = 100
|
||||
)
|
||||
|
||||
func gRPCLogger(l *zap.Logger) grpclog.LoggerV2 {
|
||||
return &zapLogger{
|
||||
log: l.WithOptions(
|
||||
// skip gRPCLog + zapLogger in caller
|
||||
zap.AddCallerSkip(2)),
|
||||
}
|
||||
}
|
||||
|
||||
func safeLevel(lvl string) zap.AtomicLevel {
|
||||
switch strings.ToLower(lvl) {
|
||||
case "debug":
|
||||
|
@ -87,3 +101,53 @@ func newLogger(v *viper.Viper) (*zap.Logger, error) {
|
|||
zap.String("app_name", name),
|
||||
zap.String("app_version", version)), nil
|
||||
}
|
||||
|
||||
func (z *zapLogger) Info(args ...interface{}) {
|
||||
z.log.Sugar().Info(args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Infoln(args ...interface{}) {
|
||||
z.log.Sugar().Info(args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Infof(format string, args ...interface{}) {
|
||||
z.log.Sugar().Infof(format, args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Warning(args ...interface{}) {
|
||||
z.log.Sugar().Warn(args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Warningln(args ...interface{}) {
|
||||
z.log.Sugar().Warn(args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Warningf(format string, args ...interface{}) {
|
||||
z.log.Sugar().Warnf(format, args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Error(args ...interface{}) {
|
||||
z.log.Sugar().Error(args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Errorln(args ...interface{}) {
|
||||
z.log.Sugar().Error(args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Errorf(format string, args ...interface{}) {
|
||||
z.log.Sugar().Errorf(format, args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Fatal(args ...interface{}) {
|
||||
z.log.Sugar().Fatal(args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Fatalln(args ...interface{}) {
|
||||
z.log.Sugar().Fatal(args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) Fatalf(format string, args ...interface{}) {
|
||||
z.log.Sugar().Fatalf(format, args...)
|
||||
}
|
||||
|
||||
func (z *zapLogger) V(int) bool { return z.log.Core().Enabled(zapcore.DebugLevel) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue