log

package
v0.0.0-...-3b96972 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FileNameDateFormat = "%Y%m%d"
	TimestampFormat    = "2006-01-02 15:04:05.000"
	Text               = "text"
	JSON               = "json"
	DataKey            = "data"
	Func               = "func"
)

Variables

This section is empty.

Functions

func Debug

func Debug(message string, args ...interface{})

func DoInit

func DoInit()

func Error

func Error(message string, args ...interface{})

func Fatal

func Fatal(message string, args ...interface{})

func Flush

func Flush() error

func GetCustomLog

func GetCustomLog(k string, v interface{}) *logrus.Entry

GetCustomLog return log entry with context set by custom k,v. note: no need release

func GetLogger

func GetLogger() *logrus.Logger

func Info

func Info(message string, args ...interface{})

func InitLogger

func InitLogger(option *Option)

func Panic

func Panic(message string, args ...interface{})

func SetLogLevel

func SetLogLevel(level string)

SetLogLevel set log level, we need when server hot-reload for debug

func StderrFatalf

func StderrFatalf(message string, args ...interface{})

func Warn

func Warn(message string, args ...interface{})

func Writer

func Writer() io.Writer

Types

type AsyncRotaLog

type AsyncRotaLog struct {
	// contains filtered or unexported fields
}

func NewRotaLogWriter

func NewRotaLogWriter(o *Option) *AsyncRotaLog

func (*AsyncRotaLog) Close

func (al *AsyncRotaLog) Close() error

func (*AsyncRotaLog) Write

func (al *AsyncRotaLog) Write(p []byte) (n int, err error)

type DefaultFormatter

type DefaultFormatter struct {
	TextFormatter *logrus.TextFormatter
	FmtTpl        string
	FileInfoField string
	Color         bool
}

func (*DefaultFormatter) Format

func (df *DefaultFormatter) Format(entry *logrus.Entry) ([]byte, error)

type DefaultHook

type DefaultHook struct {
}

func (*DefaultHook) Fire

func (h *DefaultHook) Fire(entry *logrus.Entry) error

func (*DefaultHook) Levels

func (h *DefaultHook) Levels() []logrus.Level

type Level

type Level uint32
const (
	PANIC Level = iota
	FATAL
	ERROR
	WARN
	INFO
	DEBUG
)

type Option

type Option struct {
	// log目录
	LogFolder string
	// log文件名
	LogFile string
	// 日志类型 json|text
	LogType string
	// 文件名的日期格式
	FileNameDateFormat string
	// 日志中日期时间格式
	TimestampFormat string
	// 日志级别
	LogLevel string
	// 是否打印到控制台
	Log2Console bool
	// 是否异步刷新
	Async bool
	// 日志最长保存多久
	MaxAge time.Duration
	// 日志默认多长时间轮转一次
	RotationTime time.Duration
	// 是否开启记录文件名和行号
	IsEnableRecordFileInfo bool
	// 文件名和行号字段名
	FileInfoField string
	// json日志是否美化输出
	JSONPrettyPrint bool
	// json日志条目中 数据字段都会作为该字段的嵌入字段
	JSONDataKey string
	// Text模式下日志打印的格式字符串,两个占位符:caller、message内容
	TextFmtTpl string
}

func DefaultOption

func DefaultOption() *Option

Jump to

Keyboard shortcuts

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