slog

package
v0.0.0-...-659f766 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEBUG = iota
	INFO
	WARN
	ERROR
)
View Source
const (
	Ldate         = log.Ldate
	Ltime         = log.Ltime
	Lmicroseconds = log.Lmicroseconds
	Llongfile     = log.Llongfile
	Lshortfile    = log.Lshortfile
	LUTC          = log.LUTC
	Lmsgprefix    = log.Lmsgprefix
	LstdFlags     = log.LstdFlags
)
View Source
const DefaultFileName = "./logs/app.log"

默认日志文件路径

View Source
const DefaultFlags = LstdFlags

默认日志flag (Ldate | Ltime)

View Source
const DefaultLevel = INFO

默认打印级别

Variables

This section is empty.

Functions

This section is empty.

Types

type SLogger

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

func Default

func Default() *SLogger

获取默认日志打印对象, 多次获取为同一个日志对象

func New

func New(file *lumberjack.Logger, logFlags, level int) *SLogger

创建新的日志的打印对象 错误级别为ERROR以上时, 会增加Lshortfile参数 此方法被调用后log的默认设置也会被改变

New(&lumberjack.Logger{
	Filename:   DefaultFileName, // 日志文件路径
	MaxSize:    10,              // 单个文件大小(MB)
	MaxAge:     30,              // 备份保存天数
	MaxBackups: 100,             // 备份保存的个数
	LocalTime:  true,            // 是否使用本地时间,false为UTC时间
	Compress:   false,           // 备份是否进行压缩
}, DefaultFlags, // 日志打印flag,参照log包下的flag说明
DefaultLevel) // 日志的打印级别

func (*SLogger) Close

func (l *SLogger) Close() error

关闭日志文件输出流

func (*SLogger) Debug

func (l *SLogger) Debug(msg ...interface{})

打印Debug日志 当前级别小于默认日志级别时,日志会被忽略

func (*SLogger) Error

func (l *SLogger) Error(msg ...interface{})

打印Error日志 当前级别小于默认日志级别时,日志会被忽略

func (*SLogger) ErrorDepth

func (l *SLogger) ErrorDepth(depth int, msg ...interface{})

打印Error日志 当前级别小于默认日志级别时,日志会被忽略

func (*SLogger) GetLog

func (l *SLogger) GetLog(level int) *log.Logger

获取golang的log

func (*SLogger) GetOutput

func (l *SLogger) GetOutput() io.Writer

获取输出流

func (*SLogger) Info

func (l *SLogger) Info(msg ...interface{})

打印Info日志 当前级别小于默认日志级别时,日志会被忽略

func (*SLogger) Log

func (l *SLogger) Log(level int, msg ...interface{})

打印指定级别的日志 指定的级别小于默认日志级别时,日志会被忽略

func (*SLogger) SetLevel

func (l *SLogger) SetLevel(level int)

获取输出流

func (*SLogger) Warn

func (l *SLogger) Warn(msg ...interface{})

打印Warn日志 当前级别小于默认日志级别时,日志会被忽略

Jump to

Keyboard shortcuts

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