Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

easylog 是一个基于 lumberjack 和 zap 封装的的golang日志库, 已在生产环境使用。

Notifications You must be signed in to change notification settings

logerror/easylog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

5 Commits

Repository files navigation

easylog

easylog 是一个基于 lumberjackzap 封装的的golang日志库, 已在生产环境使用。

How To Use

直接使用

import (
	"github.com/logerror/easylog"
	"github.com/logerror/easylog/pkg/option"
)
easylog.Warn("123")

InitGlobalLogger接收一个可变参数,你可以根据需求配置

定义日志级别

log := easylog.InitGlobalLogger(option.WithLogLevel("error"))
defer log.Sync()
easylog.Info("some error to log")

配置日志文件路径,大小

支持配置文件路径,文件大小,是否归档压缩日志文件

log := easylog.InitGlobalLogger(
	option.WithLogLevel("info"), 
	option.WithLogFile("2.log", 1, false),
)
defer log.Sync()
easylog.Info(" some error to log")

如果在将日志写入到文件是不希望在控制台同步输出,则使用option.WithConsole参数

logger = easylog.InitGlobalLogger(
 option.WithLogLevel("info"),
 option.WithLogFile(logFilePath, 5, 0, 0, false),
 option.WithConsole(false),
)

如果你需要在使用过程中改变日志的参数可以重新 InitGlobalLogger 然后将返回参数作为ReplaceLogger的参数

easylog.ReplaceLogger(logger)

配置CallerSkip,用于控制展示的call信息

// AddCallerSkip increases the number of callers skipped by caller annotation
// (as enabled by the AddCaller option). When building wrappers around the
// Logger and SugaredLogger, supplying this Option prevents zap from always
// reporting the wrapper code as the caller.
log := drlog.InitGlobalLogger(option.WithCallerSkip(1))
defer log.Sync()
drlog.Info(" some error to log")

About

easylog 是一个基于 lumberjack 和 zap 封装的的golang日志库, 已在生产环境使用。

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /