logrusKit

package
v3.0.94 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewLfsHook func(output interface{}, formatter logrus.Formatter) *lfshook.LfsHook = lfshook.NewHook

NewLfsHook

使用场景: (1) 指定日志级别(s),可以也输出到其它输出,不影响原输出.

Functions

func DisableQuote

func DisableQuote(logger *logrus.Logger)

DisableQuote

PS: 输出中存在 换行字符(\n) 的话,只有禁掉双引号才会生效.

func DisableQuoteTemporarily

func DisableQuoteTemporarily(logger *logrus.Logger, callback func(logger *logrus.Logger))

DisableQuoteTemporarily 临时禁用双引号(")

@param logger (1) 可以为nil(此时将采用logrus.StandardLogger())

(2) 只有当formatter为 *logrus.TextFormatter 类型,DisableQuote才会生效

func DisposeLogger

func DisposeLogger(logger *logrus.Logger) error

DisposeLogger 释放资源(主要针对文件日志)

func EnableQuote

func EnableQuote(logger *logrus.Logger)

func GetLocation added in v3.0.43

func GetLocation(f *runtime.Frame) string

func MustSetUp

func MustSetUp(config *Config)

func NewDefaultTextFormatter

func NewDefaultTextFormatter() *logrus.TextFormatter

func NewFileAndStdoutLogger

func NewFileAndStdoutLogger(filePath string, options ...LoggerOption) (*logrus.Logger, error)

NewFileAndStdoutLogger 同时输出到 文件(not rotatable) 和 os.Stdout.

@param filePath (1) 如果文件不存在,会自动创建;

(2) 如果文件存在,会自动追加内容.

func NewFileLogger

func NewFileLogger(filePath string, options ...LoggerOption) (*logrus.Logger, error)

NewFileLogger 输出到 文件(not rotatable).

@param filePath (1) 如果文件不存在,会自动创建;

(2) 如果文件存在,会自动追加内容.

func NewLogger

func NewLogger(options ...LoggerOption) *logrus.Logger

NewLogger

PS: (1) 默认输出到 控制台(os.Stderr); (2) 如果希望 输出到文件(可选是否rotatable),可以使用 WithOutput(),详见下例.

@param options 可以什么都不配置(此时输出到控制台)

func NewTextFormatter

func NewTextFormatter(timestampFormat string) *logrus.TextFormatter

NewTextFormatter

PS: 外部在调用此方法后,建议调用: Logger.SetReportCaller(true)!!!

@param timestampFormat 可以为""(将采用默认值)

e.g. 日志输出 time=2023-03-23 16:46:23.398+08:00 level=info msg=[CHIMERA, PROCESS] pid: [8579]. func=PrintBasicDetails(logrusKit/basicDetails.go:17) time=2023-03-23 16:46:23.398+08:00 level=info msg=[CHIMERA, OS] os: [darwin]. func=PrintBasicDetails(logrusKit/basicDetails.go:20) time=2023-03-23 16:46:23.398+08:00 level=info msg=[CHIMERA, OS] arch: [arm64]. func=PrintBasicDetails(logrusKit/basicDetails.go:21)

func NewTruncFileAndStdoutLogger added in v3.0.50

func NewTruncFileAndStdoutLogger(filePath string, options ...LoggerOption) (*logrus.Logger, error)

NewTruncFileAndStdoutLogger

@param filePath (1) 如果不存在,会自动创建;

(2) 如果 已经存在 && 是个文件,会截断该文件的内容.

func NewTruncFileLogger added in v3.0.50

func NewTruncFileLogger(filePath string, options ...LoggerOption) (*logrus.Logger, error)

NewTruncFileLogger

@param filePath (1) 如果不存在,会自动创建;

(2) 如果 已经存在 && 是个文件,会截断该文件的内容.

func PrintBasicDetails

func PrintBasicDetails(logger *logrus.Logger)

PrintBasicDetails 输出服务器的基本信息(以便于甩锅)

func SetUp

func SetUp(config *Config) error

SetUp

PS: 可以多次调用.

@param config 可以为nil(debug级别、禁用双引号、不输出基本信息)

func StringToLevel

func StringToLevel(str string) (logrus.Level, error)

StringToLevel string => logrus.Level

PS: 默认日志级别 Debug.

Types

type Config

type Config struct {
	// Level 日志级别,默认: debug
	Level string `json:"level" yaml:"level"`

	// EnableQuote 是否允许日志内容的双引号?
	EnableQuote bool `json:"enableQuote" yaml:"enableQuote"`

	// PrintBasic 是否打印基本信息?
	PrintBasic bool `json:"printBasic" yaml:"printBasic"`
}

type LoggerOption

type LoggerOption func(opts *loggerOptions)

func WithDisableQuote

func WithDisableQuote(disableQuote bool) LoggerOption

func WithFormatter

func WithFormatter(formatter logrus.Formatter) LoggerOption

func WithLevel

func WithLevel(level logrus.Level) LoggerOption

func WithMsgPrefix

func WithMsgPrefix(msgPrefix string) LoggerOption

func WithOutput

func WithOutput(output io.Writer) LoggerOption

func WithReportCaller

func WithReportCaller(reportCaller bool) LoggerOption

Jump to

Keyboard shortcuts

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