logutils

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultLogFilePath = "/tmp/cni.log"
	// MaxSize    = 100 // MB
	DefaultLogFileMaxSize int = 100
	// MaxAge     = 30 // days (no limit)
	DefaultLogFileMaxAge = 30
	// MaxBackups = 10 // no limit
	DefaultLogFileMaxBackups = 10
)
View Source
const (
	DebugLevel = zapcore.DebugLevel
	InfoLevel  = zapcore.InfoLevel
	WarnLevel  = zapcore.WarnLevel
	ErrorLevel = zapcore.ErrorLevel
	PanicLevel = zapcore.PanicLevel
	FatalLevel = zapcore.FatalLevel
)

Variables

View Source
var (
	Logger       *zap.Logger
	LoggerStderr *zap.Logger
	LoggerFile   *zap.Logger
)

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

func InitStderrLogger(logLevel LogLevel) error

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

func InitStdoutLogger(logLevel LogLevel) error

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

type FileOutputOption struct {
	Filename   string
	MaxSize    int
	MaxAge     int
	MaxBackups int
}

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".

const (
	JsonLogFormat    LogFormat = "json"
	ConsoleLogFormat LogFormat = "console"
)

type LogLevel

type LogLevel = zapcore.Level

LogMode is a type help you choose the log level.

type LogMode

type LogMode uint32

LogMode is a type help you choose the log output mode, which supports "stderr","stdout","file".

const (
	OUTPUT_FILE   LogMode = 1 // 0001
	OUTPUT_STDERR LogMode = 2 // 0010
	OUTPUT_STDOUT LogMode = 4 // 0100
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL