logger

package
v0.0.0-...-b700ed5 Latest Latest
Warning

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

Go to latest
Published: May 14, 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

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