Documentation
¶
Index ¶
- Constants
- func CustomLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func InitSugarLogger(logConfig *LogConfig, writer ...io.Writer) (*zap.SugaredLogger, zap.AtomicLevel)
- type LOG_LEVEL
- type LogConfig
- type LoggerInterface
Constants ¶
View Source
const ( DEBUG = "DEBUG" INFO = "INFO" WARN = "WARN" ERROR = "ERROR" )
日志级别,配置文件定义的常量
View Source
const ( DEFAULT_MAX_AGE = 365 // 日志最长保存时间,单位:天 DEFAULT_ROTATION_TIME = 6 // 日志滚动间隔,单位:小时 DEFAULT_ROTATION_SIZE = 100 // 默认的日志滚动大小,单位:MB )
日志切割默认配置
View Source
const ( ColorBlack color = iota + 30 ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite )
View Source
const (
ROTATION_SIZE_MB = 1024 * 1024
)
日志滚动单位
Variables ¶
This section is empty.
Functions ¶
func CustomLevelEncoder ¶
func CustomLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
func CustomTimeEncoder ¶
func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
func InitSugarLogger ¶
func InitSugarLogger(logConfig *LogConfig, writer ...io.Writer) (*zap.SugaredLogger, zap.AtomicLevel)
Types ¶
type LogConfig ¶
type LogConfig struct {
Module string // module: module name
ChainId string // chainId: chain id
LogPath string // logPath: log file save path
LogLevel LOG_LEVEL // logLevel: log level
MaxAge int // maxAge: the maximum number of days to retain old log files
RotationTime int // RotationTime: rotation time
RotationSize int64 // RotationSize: rotation size Mb
JsonFormat bool // jsonFormat: log file use json format
ShowLine bool // showLine: show filename and line number
LogInConsole bool // logInConsole: show logs in console at the same time
ShowColor bool // if true, show color log
IsBrief bool // if true, only show log, won't print log level、caller func and line
// StackTraceLevel record a stack trace for all messages at or above a given level.
// Empty string or invalid level will not open stack trace.
StackTraceLevel string
}
type LoggerInterface ¶
type LoggerInterface interface {
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
}
Source Files
¶
- log.go
- logger_interface.go
Click to show internal directories.
Click to hide internal directories.