日志
1. 日志配置
dubbogo 3.0 默认使用 zap 日志库。如果未在配置文件中添加 logger 配置,日志将打印到控制台。默认级别为 debug。您还可以在配置文件中配置日志级别。您可以配置 zap-config 和 lumberjack-config 如下来自定义日志输出。
dubbo:
logger:
zap-config:
level: debug # log level
development: false
disableCaller: false
disableStacktrace: false
encoding: "console"
# zap encoder configuration
encoderConfig:
messageKey: "message"
levelKey: "level"
timeKey: "time"
nameKey: "logger"
callerKey: "caller"
stacktraceKey: "stacktrace"
lineEnding: ""
levelEncoder: "capitalColor"
timeEncoder: "iso8601"
durationEncoder: "seconds"
callerEncoder: "short"
nameEncoder: ""
outputPaths:
- "stderr"
errorOutputPaths:
- "stderr"
lumberjack-config:
# Write the log file name
filename: "logs.log"
# The maximum size of each log file length, in MiB. Default 100MiB
maxSize: 1
# The maximum number of days to keep the log (only keep the log of the last few days)
maxAge: 3
# Only how many recent log files are kept to control the size of the total log of the program
maxBackups: 5
# Whether to use local time or not, UTC time is used by default
localTime: true
# Whether to compress the log file, compression method gzip
compress: false
2. 日志 API 和自定义日志记录
日志接口
type Logger interface {
Info(args...interface{})
Warn(args ... interface{})
Error(args...interface{})
Debug(args...interface{})
Fatal(args...interface{})
Infof(fmt string, args...interface{})
Warnf(fmt string, args...interface{})
Errorf(fmt string, args...interface{})
Debugf(fmt string, args...interface{})
Fatalf(fmt string, args ... interface{})
}
日志 API
import "dubbo.apache.org/dubbo-go/v3/common/logger"
logger.SetLoggerLevel(warn) // Set the log level in the main function
logger.SetLogger(myLogger) // Set a custom logger in the main function
- 日志 API 不能在 Init 阶段使用,否则可能会出现意外问题。
上次修改时间:2024 年 1 月 17 日: 修复损坏的链接 (6651e217e73)