logger

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: GPL-3.0 Imports: 11 Imported by: 7

Documentation

Overview

Package logger 日志专用写入器,可设置是否自动依据日期以及文件大小滚动日志文件

Index

Constants

View Source
const (

	// ShortTimeFormat 日志事件戳格式
	ShortTimeFormat = "15:04:05.000 "
)

Variables

This section is empty.

Functions

func NewWriter

func NewWriter(opt *OptLog) io.Writer

NewWriter 一个新的log写入器

opt: 日志写入器配置

Types

type Logger

type Logger interface {
	Debug(msg string)
	Info(msg string)
	Warning(msg string)
	Error(msg string)
	System(msg string)
	DebugFormat(f string, msg ...interface{})
	InfoFormat(f string, msg ...interface{})
	WarningFormat(f string, msg ...interface{})
	ErrorFormat(f string, msg ...interface{})
	DefaultWriter() io.Writer
}

Logger 日志接口

func NewConsoleLogger

func NewConsoleLogger() Logger

NewConsoleLogger 返回一个纯控制台日志输出器

func NewLogger

func NewLogger(d, f string, logLevel, logDays int) Logger

NewLogger init logger

d: 日志保存路径

f:日志文件名,为空时仅输出到控制台

logLevel 日志等级,1-输出到控制台,10-debug(输出到控制台和文件),20-info(输出到文件),30-warning(输出到文件),40-error(输出到控制台和文件),90-system(输出到控制台和文件)

logDays 日志文件保留天数

type NilLogger

type NilLogger struct{}

NilLogger 空日志

func (*NilLogger) Debug

func (l *NilLogger) Debug(msg string)

Debug Debug

func (*NilLogger) DebugFormat

func (l *NilLogger) DebugFormat(f string, msg ...interface{})

DebugFormat Debug

func (*NilLogger) DefaultWriter

func (l *NilLogger) DefaultWriter() io.Writer

DefaultWriter 返回日志Writer

func (*NilLogger) Error

func (l *NilLogger) Error(msg string)

Error Error

func (*NilLogger) ErrorFormat

func (l *NilLogger) ErrorFormat(f string, msg ...interface{})

ErrorFormat Error

func (*NilLogger) Info

func (l *NilLogger) Info(msg string)

Info Info

func (*NilLogger) InfoFormat

func (l *NilLogger) InfoFormat(f string, msg ...interface{})

InfoFormat Info

func (*NilLogger) System

func (l *NilLogger) System(msg string)

System System

func (*NilLogger) Warning

func (l *NilLogger) Warning(msg string)

Warning Warning

func (*NilLogger) WarningFormat

func (l *NilLogger) WarningFormat(f string, msg ...interface{})

WarningFormat Warning

type OptLog

type OptLog struct {
	// Filename 日志文件名,不需要扩展名,会自动追加时间戳以及.log扩展名,为空时其他参数无效,仅输出到控制台
	Filename string
	// FileDir 日志存放目录
	FileDir string
	// AutoRoll 是否自动滚动日志文件,true-依据MaxDays和MaxSize自动切分日志文件,日志文件名会额外追加日期时间戳‘yymmdd’和序号
	AutoRoll bool
	// MaxDays 日志最大保留天数,AutoRoll==true时有效
	MaxDays int
	// MaxSize 单个日志文件最大大小,AutoRoll==true时有效
	MaxSize int64
	// ZipFile 是否压缩旧日志文件,AutoRoll==true时有效
	ZipFile bool
	// SyncToConsole 同步输出到控制台
	SyncToConsole bool
	// DelayWrite 延迟写入,每秒检查写入缓存,并写入文件,非实时写入
	DelayWrite bool
}

OptLog OptLog

type StdLogger

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

StdLogger mx log

func (*StdLogger) Debug

func (l *StdLogger) Debug(msg string)

Debug writelog with level 10

func (*StdLogger) DebugFormat

func (l *StdLogger) DebugFormat(f string, msg ...interface{})

DebugFormat writelog with level 10

func (*StdLogger) DefaultWriter

func (l *StdLogger) DefaultWriter() io.Writer

DefaultWriter out

func (*StdLogger) Error

func (l *StdLogger) Error(msg string)

Error writelog with level 40

func (*StdLogger) ErrorFormat

func (l *StdLogger) ErrorFormat(f string, msg ...interface{})

ErrorFormat writelog with level 40

func (*StdLogger) Info

func (l *StdLogger) Info(msg string)

Info writelog with level 20

func (*StdLogger) InfoFormat

func (l *StdLogger) InfoFormat(f string, msg ...interface{})

InfoFormat writelog with level 20

func (*StdLogger) System

func (l *StdLogger) System(msg string)

System writelog with level 90

func (*StdLogger) Warning

func (l *StdLogger) Warning(msg string)

Warning writelog with level 30

func (*StdLogger) WarningFormat

func (l *StdLogger) WarningFormat(f string, msg ...interface{})

WarningFormat writelog with level 30

type Writer

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

Writer 自定义Writer

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write 异步写入日志,返回固定为 0, nil

Jump to

Keyboard shortcuts

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