-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arrobo, Gabriel <[email protected]>
- Loading branch information
1 parent
0053836
commit d7ca287
Showing
8 changed files
with
66 additions
and
61 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 |
---|---|---|
@@ -1 +1 @@ | ||
1.5.2-dev | ||
2.0.0 |
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,47 +1,59 @@ | ||
// SPDX-FileCopyrightText: 2022-present Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package logger | ||
|
||
import ( | ||
"time" | ||
|
||
formatter "github.com/antonfisher/nested-logrus-formatter" | ||
"github.com/sirupsen/logrus" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
var ( | ||
log *logrus.Logger | ||
AppLog *logrus.Entry | ||
PfcpLog *logrus.Entry | ||
CfgLog *logrus.Entry | ||
log *zap.Logger | ||
AppLog *zap.SugaredLogger | ||
PfcpLog *zap.SugaredLogger | ||
CfgLog *zap.SugaredLogger | ||
atomicLevel zap.AtomicLevel | ||
) | ||
|
||
func init() { | ||
log = logrus.New() | ||
log.SetReportCaller(true) | ||
|
||
log.Formatter = &formatter.Formatter{ | ||
TimestampFormat: time.RFC3339, | ||
TrimMessages: true, | ||
NoFieldsSpace: true, | ||
HideKeys: true, | ||
FieldsOrder: []string{"component", "category"}, | ||
atomicLevel = zap.NewAtomicLevelAt(zap.InfoLevel) | ||
config := zap.Config{ | ||
Level: atomicLevel, | ||
Development: false, | ||
Encoding: "console", | ||
EncoderConfig: zap.NewProductionEncoderConfig(), | ||
OutputPaths: []string{"stdout"}, | ||
ErrorOutputPaths: []string{"stderr"}, | ||
} | ||
|
||
AppLog = log.WithFields(logrus.Fields{"component": "UADP", "category": "App"}) | ||
PfcpLog = log.WithFields(logrus.Fields{"component": "UADP", "category": "Pfcp"}) | ||
CfgLog = log.WithFields(logrus.Fields{"component": "UADP", "category": "Config"}) | ||
config.EncoderConfig.TimeKey = "timestamp" | ||
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder | ||
config.EncoderConfig.LevelKey = "level" | ||
config.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder | ||
config.EncoderConfig.CallerKey = "caller" | ||
config.EncoderConfig.EncodeCaller = zapcore.ShortCallerEncoder | ||
config.EncoderConfig.MessageKey = "message" | ||
config.EncoderConfig.StacktraceKey = "" | ||
|
||
var err error | ||
log, err = config.Build() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
log.SetLevel(logrus.DebugLevel) | ||
AppLog = log.Sugar().With("component", "UADP", "category", "App") | ||
PfcpLog = log.Sugar().With("component", "UADP", "category", "Pfcp") | ||
CfgLog = log.Sugar().With("component", "UADP", "category", "Config") | ||
} | ||
|
||
func SetLogLevel(level logrus.Level) { | ||
log.SetLevel(level) | ||
func GetLogger() *zap.Logger { | ||
return log | ||
} | ||
|
||
func SetReportCaller(set bool) { | ||
log.SetReportCaller(set) | ||
// SetLogLevel: set the log level (panic|fatal|error|warn|info|debug) | ||
func SetLogLevel(level zapcore.Level) { | ||
AppLog.Infoln("set log level:", level) | ||
atomicLevel.SetLevel(level) | ||
} |
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