Documentation ¶
Overview ¶
Package log direct use logger
Index ¶
- Variables
- func GetTraceIdWithCtx(ctx context.Context) string
- func NewTraceIdWithCtx(ctx context.Context) context.Context
- type Logger
- func (l *Logger) Debug(ctx context.Context, msg string, fields ...zap.Field)
- func (l *Logger) Error(ctx context.Context, msg string, fields ...zap.Field)
- func (l *Logger) Fatal(ctx context.Context, msg string, fields ...zap.Field)
- func (l *Logger) Info(ctx context.Context, msg string, fields ...zap.Field)
- func (l *Logger) SetLevel(level zapcore.Level)
- func (l *Logger) Warn(ctx context.Context, msg string, fields ...zap.Field)
- func (l *Logger) WithLoggerMetaFields(fields ...zapcore.Field) *Logger
- type LoggerOpt
- func (opt LoggerOpt) CreateDirectory() error
- func (opt LoggerOpt) GetLogFilePath() string
- func (opt LoggerOpt) WithConsoleLog(enable bool) LoggerOpt
- func (opt LoggerOpt) WithDirectory(path string) LoggerOpt
- func (opt LoggerOpt) WithLogLevel(level zapcore.Level) LoggerOpt
- func (opt LoggerOpt) WithLogRetention(maxSize int, maxBackups int, maxAge int) LoggerOpt
- func (opt LoggerOpt) WithTraceIDEnable(enable bool) LoggerOpt
Constants ¶
This section is empty.
Variables ¶
View Source
var (
// CommonLogOpt use to easliy construct custom log options
CommonLogOpt = defaultLogOpt
)
Functions ¶
func GetTraceIdWithCtx ¶
GetTraceIdWithCtx get trace id from ctx
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger self defined Logger
func GetDefaultLogger ¶
func GetDefaultLogger() *Logger
GetDefaultLogger get default logger if no default logger was initilized ** nil ** will be return
func NewFromLogger ¶
NewFromLogger new a logger from a logger
type LoggerOpt ¶
type LoggerOpt struct { LogLevel zapcore.Level Directory string // log file directory Name string // log file name TraceIDEnable bool // enable traceid field MaxSize int // Log File Max Size MB MaxBackups int // The number of backup log file MaxAge int // The days the log will be kept IsDefault bool // is defalut logger? ConsoleLogEnable bool // enable console log? }
LoggerOpt configures the logger
func (LoggerOpt) CreateDirectory ¶
CreateDirectory create logfile directory
func (LoggerOpt) GetLogFilePath ¶
GetLogFilePath get log dst file path
func (LoggerOpt) WithConsoleLog ¶
WithConsoleLog enable console log
func (LoggerOpt) WithDirectory ¶
WithDirectory setting log file directory
func (LoggerOpt) WithLogLevel ¶
WithLogLevel sets log level
func (LoggerOpt) WithLogRetention ¶
WithLogRetention sets log retention
func (LoggerOpt) WithTraceIDEnable ¶
WithTraceIDEnable setting traceid
Click to show internal directories.
Click to hide internal directories.