dologger

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 5 Imported by: 0

README

DoLogger 搞定日志

如何使用

//在服务开始的时候初始化日志
InitLogger(&LoggerOptions{
    LogDebug: true,
    LogPath: "log/test-access.log",
    LogErrorPath: "log/test-error.log",
})

//在任何地方调用日志
Debugf(ctx, fmt.Sprintf("debug msg:%v", errors.New("params error.")))
Infof(ctx, fmt.Sprintf("info msg:%v", errors.New("params error.")))
Warnf(ctx, fmt.Sprintf("warm msg:%v", errors.New("params error.")))
Errorf(ctx, fmt.Sprintf("error msg:%v", errors.New("params error.")))
Logf(1, fmt.Sprintf("error msg:%v", errors.New("params error.")))

//在任何地方调用日志
Debug("params error.")
Info("params error.")
Warn("params error.")
Error("params error.")
Log(1,"params error.")

//获取实例
GetLogger().Log(1, "failed.") //level=fatal
GetLogger().Log(2, "failed.") //level=error
GetLogger().Log(3, "failed.") //level=warning
GetLogger().Log(4, "failed.") //level=info
GetLogger().Log(5, "failed.") //level=debug

测试示例

dologger_test.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalLogger *logrus.Logger

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(ctx context.Context, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(ctx context.Context, args ...interface{})

func GetLogger

func GetLogger() *logrus.Logger

获取logger实例,直接使用原方法

func Info

func Info(args ...interface{})

func Infof

func Infof(ctx context.Context, args ...interface{})

func InitLogger

func InitLogger(options *LoggerOptions)

初始化日志 在服务开始的时候进行初始化

func Log

func Log(level logrus.Level, args ...interface{})

func Logf

func Logf(level logrus.Level, format string, args ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(ctx context.Context, args ...interface{})

Types

type Logger

type Logger struct {
}

type LoggerOptions

type LoggerOptions struct {
	//开启Debug
	LogDebug bool
	//日志路径
	LogPath string
	//错误日志路径
	LogErrorPath string
	//文件名后缀格式,例如:"%Y%m%d"
	PathFormat string
	//分割时间,例如:24
	RotationTime uint
}

Jump to

Keyboard shortcuts

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