zaplog

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MessageKey zap format message key
	MessageKey string = "msg"
	// TimeKey zap format time key
	TimeKey string = "time"
	// LevelKey zap format level key
	LevelKey string = "level"
	// NameKey zap format name key
	NameKey string = "logger"
	// CallerKey zap format caller key
	CallerKey string = "caller"
	// StacktraceKey zap format stacktrace key
	StacktraceKey string = "stacktrace"

	// LogFormatJSON log output with json type
	LogFormatJSON string = "json"

	// LogMaxSize max size of single log file
	LogMaxSize int = 100
	// LogMaxAge max save days of log files
	LogMaxAge int = 365
	// LogMaxBackups max backups of log files
	LogMaxBackups int = 500

	// DefaultLogAggregateDir default directory of log categories
	DefaultLogAggregateDir string = "logs"
	// DefaultLogFileSuffix default suffix string of log file
	DefaultLogFileSuffix string = "log"
)

Variables

This section is empty.

Functions

func GetInitialDelay added in v1.0.7

func GetInitialDelay(hour int, minute int, second int) (time.Duration, error)

GetInitialDelay returns the initial logRotateInitialDelay millisecond before the first event is logged. hour: hour of the day minute: minute of the hour second: second of the minute return: logRotateInitialDelay time.Duration of time.Now() and the input parse time. if the input parse time if Before the current time, return the Duration that between the current time and the input parse time add one day.

func GetLogger

func GetLogger(name string) logger.Logger

GetLogger returns a logger with the given name.

func GetLoggerWithOptions

func GetLoggerWithOptions(name string, opts ...Option) logger.Logger

GetLoggerWithOptions returns a logger with the given name and options.

func NewBudiler added in v1.0.9

func NewBudiler() *zapLoggerBuilder

NewBuilder returns a new zapLoggerBuilder.

func NewCustomProductionEncoderConfig

func NewCustomProductionEncoderConfig() zapcore.EncoderConfig

NewCustomProductionEncoderConfig return a custom zapcore encoder config

func NewCustomStdoutEncoderConfig

func NewCustomStdoutEncoderConfig() zapcore.EncoderConfig

NewCustomStdoutEncoderConfig return a custom zapcore encoder config

func ZapLogger

func ZapLogger(name string, opts ...Option) logger.Logger

ZapLogger returns a new zap logger.

Types

type ApplyFunc

type ApplyFunc func(zapOpts *options)

ApplyFunc zap logger options apply func

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option zap logger option interface

func AddCaller added in v1.0.1

func AddCaller() Option

AddCaller return logger with caller caller is a bool option that determines whether the line number of the caller is logged.

func Compress

func Compress(is bool) Option

Compress return logger if compress needed default is true

func FileName added in v1.0.7

func FileName(fileName string) Option

FileName return logger with logFileName

func LocalDateTime

func LocalDateTime(is bool) Option

LocalDateTime return logger with localDateTime default is true

func LogRotate added in v1.0.7

func LogRotate(is bool) Option

LogRotate return logger if logRotate needed default is true

func LogRotateCycle added in v1.0.7

func LogRotateCycle(cycle time.Duration) Option

LogRotateCycle return logger with logRotateCycleDuration

func LogRotateInitialDelay added in v1.0.7

func LogRotateInitialDelay(delay time.Duration) Option

LogRotateInitialDelay return logger with initial logRotateInitialDelay time.Duration if logRotate is true, initialDelay is the time to wait before the first log file rotation. The default is the Duration between time.Now() and the parse time of the time.Now().Hour():59:59.

func MaxAge added in v1.0.7

func MaxAge(maxAge int) Option

MaxAge return logger with maxAge

func MaxBackups added in v1.0.7

func MaxBackups(maxBackups int) Option

MaxBackups return logger with maxBackups

func MaxSize added in v1.0.7

func MaxSize(maxSize int) Option

MaxSize return logger with maxSize if logRotate is true, maxSize is the maximum size of the log file in megabytes. The default is 100 megabytes.

func Sampling added in v1.0.1

func Sampling(is bool) Option

Sampling return logger if sampling needed default is false

func WithCaller added in v1.0.1

func WithCaller(caller bool) Option

WithCaller return logger with caller option caller is a bool option that determines whether the line number of the caller is logged. The default is true.

func WithCallerSkip added in v1.0.1

func WithCallerSkip(skip int) Option

WithCallerSkip return logger with caller skip callerSkip is the number of stack frames to ascend, starting from zaplogger.go. The default is 1.

func WithCategory

func WithCategory(category string) Option

WithCategory return logger with category

func WithLevel

func WithLevel(level zap.AtomicLevel) Option

WithLevel return logger with the given level default is zap.NewAtomicLevel()

func WithRefPath

func WithRefPath(logRefPath string) Option

WithRefPath return logger with the given ref path

func WithStackTraceLevel added in v1.0.6

func WithStackTraceLevel(level zap.AtomicLevel) Option

WithStackTraceLevel return logger with stackTraceLevel stackTraceLevel is used to determine whether to include stack trace in the log output. The default is ErrorLevel.

Jump to

Keyboard shortcuts

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