Giter Club home page Giter Club logo

golog's Introduction

golog

a simple logger for go. 一个简易的日志库,对标准库中的log进行了封装,提供了如下实用功能:

  • 日志级别 Log level
  • 日志轮转 Log rotate
  • 日志压缩 Gzip compress

引用

go get -u github.com/jiyu93/golog

范例

直接输出到控制台(全局默认)

代码示例:

golog.Info("hello world")

输出结果:

2020/01/01 00:00:00 test.go:10: [I] hello world

输出到单个文件(修改全局默认输出)

代码示例:

// 创建一个日志轮转器Rotater,设置文件名、单个文件大小(MB)、日志备份总数、旧文件是否压缩
w := golog.NewRotater("log/app.log",256,10,false)
// 将这个Rotater作为默认的Writer使用
golog.SetDefaultOutput(w)
golog.Info("hello world")

运行结果:

# cat log/app.log
2020/01/01 00:00:00 test.go:10: [I] hello world

输出到多个文件

代码示例:

loggerA :=  golog.NewLogger(golog.NewRotater("log/moduleA.log",256,10,false),golog.LevelDebug)
loggerB :=  golog.NewLogger(golog.NewRotater("log/moduleB.log",256,10,false),golog.LevelDebug)

loggerA.Info("aaa")
loggerB.Info("bbb")

运行结果:

# ls log/
moduleA.log moduleB.log

# cat moduleA.log
2020/01/01 00:00:00 test.go:10: [I] aaa

# cat moduleB.log
2020/01/01 00:00:00 test.go:10: [I] bbb

golog's People

Contributors

jiyu93 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

yihuishou

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.