GithubHelp home page GithubHelp logo

blog4go's Introduction

Introduction

BLog4go is an efficient logging library written in the Go programming language, providing logging hook, log rotate, filtering and formatting log message.

BLog4go 是高性能日志库。创新地使用“边解析边输出”方法进行日志输出,同时支持回调函数、日志淘汰和配置文件。可以解决高并发,调用日志函数频繁的情境下,日志库造成的性能问题。

Build Status Coverage Status GoDoc

Features

  • Partially write to the bufio.Writer as soon as posible while formatting message to improve performance
  • Support different logging output file for different logging level
  • Support configure with files in xml format
  • Configurable logrotate strategy
  • Call user defined hook in asynchronous mode for every logging action
  • Adjustable message formatting
  • Configurable logging behavier when looging on the fly without restarting
  • Suit configuration to the environment when logging start
  • Try best to get every done in background
  • File writer can be configured according to given config file
  • Different output writers
    • Console writer
    • File writer
    • Socket writer

Quick-start

package main

import (
	log "github.com/YoungPioneers/blog4go"
	"fmt"
	"os"
)

// optionally set user defined hook for logging
type MyHook struct {
	something string
}

// when log-level exceed level, call the hook
// level is the level associate with that logging action.
// message is the formatted string already written.
func (self *MyHook) Fire(level log.Level, message string) {
	fmt.Println(message)
}

func main() {
	// init a file write using xml config file
	err := log.NewFileWriterFromConfigAsFile("config.xml")
	if nil != err {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	defer log.Close()

	// initialize your hook instance
	hook := new(MyHook)
	log.SetHook(hook) // writersFromConfig can be replaced with writers
	log.SetHookLevel(log.INFO)

	// optionally set output colored
	log.SetColored(true)

	log.Debugf("Good morning, %s", "eddie")
	log.Warn("It's time to have breakfast")

}

config.xml

<blog4go minlevel="info">
	<filter levels="trace">
		<rotatefile path="trace.log" type="time"></rotatefile>
	</filter>
	<filter levels="debug,info" colored="true">
		<file path="debug.log"></file>
	</filter>
	<filter levels="error,critical">
		<rotatefile path="error.log" type="size" rotateSize="50000000" rotateLines="8000000"></rotatefile>
	</filter>
</blog4go>

Installation

If you don't have the Go development environment installed, visit the Getting Started document and follow the instructions. Once you're ready, execute the following command:

go get -u github.com/YoungPioneers/blog4go

Benchmark

I do some benchmark on a HDD disk comparing amoung fmt,blog4go,seelog,logrus. Benchmark Code

BenchmarkBlog4goSingleGoroutine-4               	 1000000	      1087 ns/op
BenchmarkBlog4goMultiGoroutine-4                	   30000	     56569 ns/op
BenchmarkFmtFormatSingleGoroutine-4             	  300000	      5104 ns/op
BenchmarkFmtFormatWithTimecacheSingleGoroutine-4	  300000	      4256 ns/op
BenchmarkFmtFormatWithTimecacheMultiGoroutine-4 	    3000	    509579 ns/op
BenchmarkLogrusSingleGoroutine-4                	  100000	     13757 ns/op
BenchmarkLogrusWithTimecacheSingleGoroutine-4   	  100000	     12752 ns/op
BenchmarkLogrusWithTimecacheMultiGoroutine-4    	    1000	   2049809 ns/op
BenchmarkSeelogSingleGoroutine-4                	   50000	     32846 ns/op
BenchmarkSeelogMultiGoroutine-4                 	    1000	   3191334 ns/op

It shows that blog4go can write log very fast, especially in situation with multi goroutines running at the same time~

Documentation

TODO

Examples

Full examples please view EXAMPLES

Changelog

CHANGELOG

blog4go's People

Contributors

hjweddie avatar

Watchers

 avatar  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.