logger

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 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 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.Logger
	ZapLogger    *zap.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(level zapcore.Level, namespace string, logFilePath string, hook []logrus.Hook) (*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 打印致命错误日志,打印后立即退出程序。

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 级别日志。

type ZapField added in v0.15.0

type ZapField zapcore.Field

func (ZapField) MatchValue added in v0.15.0

func (f ZapField) MatchValue() any

Jump to

Keyboard shortcuts

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