Code Monkey home page Code Monkey logo

go-log's Introduction

go-log

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

注意

为保证缓冲区的日志不丢失,获取完日志实例应该使用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"
}

点我查看更多示例参考

go-log's People

Contributors

yuhao-jack avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.