gookit/event Go实现的轻量级的事件管理、调度程序库, 支持设置监听器的优先级, 支持使用通配符来进行一组事件的监听。
gookit/event - Go实现的轻量级的事件管理、调度程序库
· 4 min read
gookit/event Go实现的轻量级的事件管理、调度程序库, 支持设置监听器的优先级, 支持使用通配符来进行一组事件的监听。
gookit/config - Go应用配置管理,支持读取多种格式 JSON(默认), JSON5, INI, Properties, YAML, TOML, HCL, ENV, Flags,多文件加载,支持数据合并,解析环境变量名等等
cflag - wraps and extends Go flag build pertty CLI command
gitw - Git 命令包装器,生成 git 变更记录日志,获取 repo 信息和一些 git 命令工具。
git 命令git 命令git log 快速生成版本变更日志slog - a lightweight, configurable, extensible Go logging library

trace debug info notice warn error fatal panicHandler Formatter as neededHandler log processing at the same time, outputting logs to different placesFormatterjson text two log record formatting FormatterHandlerhandler.Config handler.Builder can easily and quickly build the desired log handlerconsole output logs to the console, supports color outputwriter output logs to the specified io.Writerfile output log to the specified file, optionally enable buffer to buffer writessimple output log to the specified file, write directly to the file without bufferingrotate_file outputs logs to the specified file, and supports splitting files by time and size, and buffer buffered writing is enabled by defaultbuffer for log writingtime and sizegzipBackupNum BackupTimego get github.com/gookit/slog
package main
import (
"github.com/gookit/slog"
)
func main() {
slog.Trace("this is a log message")
slog.Debug("this is a log message")
slog.Info("this is a log message")
slog.Notice("this is a log message")
slog.Warn("this is a log message")
slog.Error("this is a log message")
slog.Fatal("this is a log message")
}
output preview:

Using slog to output logs to files is very convenient, and supports multiple files, splitting by time, etc.
package main
import (
"github.com/gookit/slog"
"github.com/gookit/slog/handler"
"github.com/gookit/slog/rotatefile"
)
func main() {
defer slog.MustFlush()
// DangerLevels contains: slog.PanicLevel, slog.ErrorLevel, slog.WarnLevel
h1 := handler.MustRotateFile("/tmp/logs/app_error.log", rotatefile.EveryHour,
handler.WithLogLevels(slog.DangerLevels),
)
// NormalLevels contains: slog.InfoLevel, slog.NoticeLevel, slog.DebugLevel, slog.TraceLevel
h2 := handler.MustRotateFile("/tmp/logs/app_info.log", rotatefile.EveryHour,
handler.WithLogLevels(slog.NormalLevels),
)
slog.PushHandler(h1)
slog.PushHandler(h2)
// add logs
slog.Info("info message text")
slog.Error("error message text")
}
See logs dir:
$ ls /tmp/logs
app_error.log
app_info.log
More usage please see README