Documentation ¶
Index ¶
- Constants
- Variables
- func InitFileLogger(logLevel LogLevel, filePath string, ...) error
- func InitStderrLogger(logLevel LogLevel) error
- func InitStdoutLogger(logLevel LogLevel) error
- func NewLoggerWithOption(format LogFormat, outputMode LogMode, fileOutputOption *FileOutputOption, ...) (*zap.Logger, error)
- type FileOutputOption
- type LogFormat
- type LogLevel
- type LogMode
Constants ¶
const ( DefaultLogFilePath = "/tmp/cni.log" // MaxSize = 100 // MB DefaultLogFileMaxSize int = 100 // MaxAge = 30 // days (no limit) DefaultLogFileMaxAge = 30 // MaxBackups = 10 // no limit DefaultLogFileMaxBackups = 10 )
const ( DebugLevel = zapcore.DebugLevel InfoLevel = zapcore.InfoLevel WarnLevel = zapcore.WarnLevel ErrorLevel = zapcore.ErrorLevel PanicLevel = zapcore.PanicLevel FatalLevel = zapcore.FatalLevel )
Variables ¶
Pre-define log instance with default info level.
Functions ¶
func InitFileLogger ¶
func InitFileLogger(logLevel LogLevel, filePath string, fileMaxSize, fileMaxAge, fileMaxBackups int) error
InitFileLogger sets LoggerFile configuration for 'file output' usage. fileMaxSize unit MB, fileMaxAge unit days, fileMaxBackups unit counts.
func InitStderrLogger ¶
InitStderrLogger create LoggerStderr instance for 'stderr' usage, it's ConsoleLogFormat. It wouldn't provide 'time prefix', 'function caller suffix' and 'log level prefix' in output.
func InitStdoutLogger ¶
InitStdoutLogger create Logger instance with default configuration for 'stdout' usage, it's JsonLogFormat.
func NewLoggerWithOption ¶
func NewLoggerWithOption(format LogFormat, outputMode LogMode, fileOutputOption *FileOutputOption, addTimePrefix, addLogLevelPrefix, addFuncCallerSuffix bool, logLevel LogLevel) (*zap.Logger, error)
NewLoggerWithOption provides the ability to custom log with options. You can choose 'output format', 'output mode' and decide to use 'time prefix', 'function caller suffix' 'log level prefix' or not. If you choose 'file output mode', you can use 'stdout and file' or 'stderr and file' together with '|'. The param fileOutputOption should be a pointer for FileOutputOption , and it could be nill. If the param isn't nil, the FileOutputOption.MaxSize, FileOutputOption.MaxAge, and FileOutputOption.MaxBackups have to be nonnegative number, or they will be set to default value.
Types ¶
type FileOutputOption ¶
FileOutputOption supports the configuration for log file