在Go語言世界中,日誌庫並不像Java世界那裏有一個具備統治力的日誌庫。在作新項目技術選型的時候,不免會遇到日誌庫的選擇問題,今天筆者就爲你們介紹一下在Github中stars數最多的Go日誌庫。git
logrus是我已知的Go語言日誌庫中在Github中stars數最多的日誌庫,功能強大,性能也不錯。另外值得一提的是logrus的一個fork庫gogap/logrus,能夠配置輸出到文件和graylog日誌系統,基礎的level、調用鏈、行號,文件切分都有,特點是結構化日誌能夠被統計和索引,藉助graylog就能夠作日誌分析,不過這個庫好久沒有維護了。github
zap是Go中一個快速,結構化,分級日誌庫,Uber出品。可以激活強大的ad-hoc分析, 靈活的儀表板, 其功能超過其餘工具ELK, Splunk, 和 Sentry. 全部日誌消息都是JSON-serialized。也是目前筆者使用的日誌庫之一。golang
zerolog也是一款性能至關好的日誌庫,有趣的是zerolog和zap都在自家的Github庫首頁中的性能對比數據裏戰勝了對方:)併發
Seelog是一個原生Go日誌庫,提供了靈活的異步調度、過濾和格式化。這也是筆者較早期使用的Go日誌庫之一。app
blog4go是高性能日誌庫。創新地使用「邊解析邊輸出」方法進行日誌輸出,同時支持回調函數、日誌淘汰和配置文件。能夠解決高併發,調用日誌函數頻繁的情境下,日誌庫形成的性能問題。異步
有一些Github庫star數並很少,可是功能卻不少,例如mkideal/log、go-log、alog等就是功能十分齊全的日誌庫,簡單易用。還有一些是對開發工程中有些小幫助的庫,例如happierall/l。async
下面是我整理的Go語言日誌庫列表,你們能夠依據本身項目的實際需求選擇(若是您還有好用的Go日誌庫推薦,請留言分享)。ide
Project Name | Stars | Forks | Description |
---|---|---|---|
logrus | 5471 | 775 | Structured, pluggable logging for Go. |
zap | 2761 | 175 | Blazing fast, structured, leveled logging in Go. |
oklog | 1914 | 61 | A distributed and coördination-free log management system |
glog | 1496 | 307 | Leveled execution logs for Go |
Seelog | 960 | 173 | Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting. |
log15 | 625 | 79 | Structured, composable logging for Go |
zerolog | 444 | 18 | Zero Allocation JSON Logger |
apex/log | 433 | 38 | Structured logging package for Go. |
log | 215 | 14 | Simple, configurable and scalable Structured Logging for Go. |
blog4go | 189 | 31 | BLog4go is an efficient logging library written in the Go programming language, providing logging hook, log rotate, filtering and formatting log message. |
logutils | 176 | 18 | Utilities for slightly better logging in Go (Golang). |
log4go | 161 | 109 | Logging package similar to log4j for the Go programming language |
fileLogger | 80 | 27 | fileLogger是一個基於Go開發的可自動分割文件進行備份的異步日誌庫 |
gogap/logrus | 75 | 775 | Obsolete, Please refer to gogap/logrus_mate |
ozzo-log | 74 | 17 | A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets. |
azer/logger | 74 | 9 | Minimalistic logging library for Go. |
alexcesaro/log | 42 | 4 | Logging packages for Go |
happierall/l | 33 | 3 | Golang Pretty Logger.Custom go logger for pretty print, log, debug, warn, error with colours and levels. |
mkideal/log | 33 | 2 | pluginable, fast,structrued and leveled logging package |
slf | 33 | 1 | Structured Logging Facade (SLF) for Go |
logex | 29 | 6 | An golang log lib, supports tracking and level, wrap by standard log lib |
gologger | 26 | 5 | Simple Logger for golang. Logs Into console, file or ElasticSearch. Simple, easy to use. |
go-log | 24 | 9 | A logger, for Go |
slog | 22 | 1 | The reference SLF (structured logging facade) implementation for Go |
cxr29/log | 18 | 14 | log - Go level and rotate log |
ulog | 15 | 2 | ulog - Structured and context based logging for golang |
siddontang/go-log | 14 | 5 | a golang log lib supports level and multi handlers |
ccpaging/log4go | 13 | 109 | Logging package similar to log4j for the Go programming language |
mlog | 11 | 9 | A simple logging module for go, with a rotating file feature and console logging. |
alog | 6 | 2 | Golang async log package |
golog | 5 | 1 | golog is a multilayer & leveled & structured logger for golang. |
szxp/log | 5 | 0 | A small structured logging library for Golang |
go-async-log | 4 | 2 | Golang異步日誌庫,支持異步批量寫入,按天或者小時自動切割,錯誤等級,多文件等 |
log | 1 | 1 | 一個基於Golang的日誌模塊 |
最後是兩個benchmark庫,提供的部分Go日誌庫的性能對比數據,供你們作技術選型時參考函數