Go 高性能日志库 blog4go

码农软件 · 软件分类 · 日志工具(Logging) · 2019-09-20 08:13:33

软件介绍

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

特性:

  • Partially write to the bufio.Writer as soon as posible while formatting message to improve performance

  • 支持将不同日志级别数据写到不同文件

  • 支持使用 XML 格式的配置文件

  • 可配置的日志循环策略

  • 每次日志动作都可异步调用用户自定义的钩子

  • 可调整日志格式

  • 无需重启更改日志行为

  • 日志启动时使用环境变量的配置

  • 后台记录

  • 可根据配置文件制定文件写操作

  • 不同的输出渠道

    • 控制台

    • 文件

    • Socket 套接字

快速开始:

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>

本文地址:https://codercto.com/soft/d/14989.html

The Intersectional Internet

The Intersectional Internet

Safiya Umoja Noble、Brendesha M. Tynes / Peter Lang Publishing / 2016

From race, sex, class, and culture, the multidisciplinary field of Internet studies needs theoretical and methodological approaches that allow us to question the organization of social relations that ......一起来看看 《The Intersectional Internet》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试