Documentation ¶
Index ¶
- Constants
- Variables
- func FromContext(ctx context.Context) *zap.Logger
- func InitFileLogger(logLevel LogLevel, filePath string, ...) error
- func InitStderrLogger(logLevel LogLevel) error
- func InitStdoutLogger(logLevel LogLevel) error
- func IntoContext(ctx context.Context, logger *zap.Logger) context.Context
- 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 FromContext ¶ added in v0.0.4
FromContext returns a logger with predefined values from a context.Context.
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 IntoContext ¶ added in v0.0.4
IntoContext takes a context and sets the logger as one of its values. Use FromContext function to retrieve the logger.
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
type LogFormat ¶
type LogFormat string
LogFormat is a type help you choose the log output format, which supports "json" and "console".
type LogLevel ¶
LogMode is a type help you choose the log level.