Skip to content

go-log is a simple and clear log framework. We can use it to replace the built-in log framework that is not easy to use. This framework is constantly improving.

Notifications You must be signed in to change notification settings

yuhao-jack/go-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-log

是一个简单明了的日志框架。我们可以使用它来替换不易使用的内置日志框架。这一框架正在不断改进中,如有疑问可Email:154826195@qq.com

注意

为保证缓冲区的日志不丢失,获取完日志实例应该使用defer调用Destroy()方法,如:

defaultGoLog := go_log.DefaultGoLog()
defer defaultGoLog.Destroy()

捐赠

扫我微信 扫我支付宝

快速开始

安装

go get github.com/yuhao-jack/go-log

example

func TestDemo1(t *testing.T) {
	logger := go_log.NewGoLog(&go_log.GoLogConfig{
		LogLevel:       go_log.LoglevelDebug, //指定日志级别,小于该级别日志不处理
		ShortLogEnable: true,//使用短日志(推荐)
		MsgChan:        make(chan string, 256),//缓冲长度
		Writer:         nil,
		ConsoleEnable:  true,//控制台输出
		ColorEnable:    true,//带颜色输出
	})
	defer logger.Destroy()//阻塞直到MsgChan中的消息消费完
	logger.Debug("hello world")
	logger.ColorEnable(false)
	logger.Info("hello world")
	logger.SetLogFormatter(logFormatter)
	logger.Warn("hello world")
	file, err := os.Create("test.log") //创建文件
	if err != nil {
		fmt.Println("create file failed,err:", err)
		os.Exit(1)
	}
	logger.SetLohWriter(file)//日志落盘
	logger.Error("hello world")
}

func logFormatter(entry *go_log.LogEntity) string {
	bytes, err := json.Marshal(entry)
	if err != nil {
		return "\n"
	}
	return string(bytes) + "\n"
}

点我查看更多示例参考

About

go-log is a simple and clear log framework. We can use it to replace the built-in log framework that is not easy to use. This framework is constantly improving.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages