logger

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package logger 日志包,用于日志输出和打印

Package logger 日志包,用于日志输出和打印

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadLogLevelFromEnv added in v1.1.3

func ReadLogLevelFromEnv() (zapcore.Level, error)

func SetCallFrame

func SetCallFrame(entry *logrus.Entry, namespace string, skip int)

SetCallFrame 设定调用栈。

func SetCallerFrameWithFileAndLine

func SetCallerFrameWithFileAndLine(entry *logrus.Entry, namespace, functionName, file string, line int)

SetCallerFrameWithFileAndLine 设定调用栈。

Types

type LogFileFormatter

type LogFileFormatter struct {
	logrus.TextFormatter
	MinimumCallerDepth int
}

LogFileFormatter defines the format for log file.

func NewLogFileFormatter

func NewLogFileFormatter() *LogFileFormatter

NewLogFileFormatter return the log format for log file.

eg: 2023-06-01T12:00:00 [info] [controllers/some_controller/code_file.go:99] foo key=value

func (*LogFileFormatter) Format

func (f *LogFileFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format renders a single log entry for log file

the original file log format is defined here: github.com/sirupsen/logrus/text_formatter.TextFormatter{}.Format().

type Logger

type Logger struct {
	LogrusLogger *logrus.Entry
	ZapLogger    *zap.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(callOpts ...NewLoggerCallOption) (*Logger, error)

NewLogger 按需创建 logger 实例。

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zapcore.Field)

Debug 打印 debug 级别日志。

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...zapcore.Field)

Error 打印错误日志。

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...zapcore.Field)

Fatal 打印致命错误日志,打印后立即退出程序。

NOTICE: 该方法会调用 os.Exit(1) 退出程序。而且会优先执行 logrus 的 Fatal 方法,然后再执行 zap 的 Fatal 方法。

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zapcore.Field)

Info 打印 info 级别日志。

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...zapcore.Field)

Warn 打印 warn 级别日志。

func (*Logger) With added in v1.2.0

func (l *Logger) With(fields ...zapcore.Field) *Logger

With 创建一个新的 logger 实例,该实例会继承当前 logger 的上下文信息。 添加到新 logger 实例的字段,不会影响当前 logger 实例。

func (*Logger) WithAndSkip added in v1.5.0

func (l *Logger) WithAndSkip(skip int, fields ...zapcore.Field) *Logger

With 创建一个新的 logger 实例,该实例会继承当前 logger 的上下文信息。 添加到新 logger 实例的字段,不会影响当前 logger 实例。

type NewLoggerCallOption added in v1.5.0

type NewLoggerCallOption func(*newLoggerOptions)

func WithAppName added in v1.5.0

func WithAppName(appName string) NewLoggerCallOption

func WithCallFrameSkip added in v1.5.0

func WithCallFrameSkip(skip int) NewLoggerCallOption

func WithHook added in v1.5.0

func WithHook(hook logrus.Hook) NewLoggerCallOption

func WithInitialFields added in v1.5.0

func WithInitialFields(fields map[string]any) NewLoggerCallOption

func WithLevel added in v1.5.0

func WithLevel(level zapcore.Level) NewLoggerCallOption

func WithLogFilePath added in v1.5.0

func WithLogFilePath(logFilePath string) NewLoggerCallOption

func WithNamespace added in v1.5.0

func WithNamespace(namespace string) NewLoggerCallOption

type ZapField

type ZapField zapcore.Field

func (ZapField) MatchValue

func (f ZapField) MatchValue() any

Jump to

Keyboard shortcuts

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