forked from omec-project/udr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
77 lines (68 loc) · 2.55 KB
/
logger.go
File metadata and controls
77 lines (68 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-FileCopyrightText: 2024 Intel Corporation
// SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org>
// Copyright 2019 free5GC.org
//
// SPDX-License-Identifier: Apache-2.0
package logger
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var (
log *zap.Logger
AppLog *zap.SugaredLogger
InitLog *zap.SugaredLogger
CfgLog *zap.SugaredLogger
HandlerLog *zap.SugaredLogger
DataRepoLog *zap.SugaredLogger
UtilLog *zap.SugaredLogger
HttpLog *zap.SugaredLogger
ConsumerLog *zap.SugaredLogger
GinLog *zap.SugaredLogger
PollConfigLog *zap.SugaredLogger
NrfRegistrationLog *zap.SugaredLogger
atomicLevel zap.AtomicLevel
)
func init() {
atomicLevel = zap.NewAtomicLevelAt(zap.InfoLevel)
config := zap.Config{
Level: atomicLevel,
Development: false,
Encoding: "console",
EncoderConfig: zap.NewProductionEncoderConfig(),
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
}
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)
}
AppLog = log.Sugar().With("component", "UDR", "category", "App")
InitLog = log.Sugar().With("component", "UDR", "category", "Init")
CfgLog = log.Sugar().With("component", "UDR", "category", "CFG")
HandlerLog = log.Sugar().With("component", "UDR", "category", "HDLR")
DataRepoLog = log.Sugar().With("component", "UDR", "category", "DRepo")
UtilLog = log.Sugar().With("component", "UDR", "category", "Util")
HttpLog = log.Sugar().With("component", "UDR", "category", "HTTP")
ConsumerLog = log.Sugar().With("component", "UDR", "category", "Consumer")
GinLog = log.Sugar().With("component", "UDR", "category", "GIN")
PollConfigLog = log.Sugar().With("component", "UDR", "category", "PollConfig")
NrfRegistrationLog = log.Sugar().With("component", "UDR", "category", "NrfRegistration")
}
func GetLogger() *zap.Logger {
return log
}
// SetLogLevel: set the log level (panic|fatal|error|warn|info|debug)
func SetLogLevel(level zapcore.Level) {
CfgLog.Infoln("set log level:", level)
atomicLevel.SetLevel(level)
}