Go Wiki:slog 资源
此页面链接到使用或增强 slog
(标准库的结构化日志包)的项目。
日志格式化
- slog-formatter:slog 的常用格式化工具 + 用于构建您自己的格式化工具的助手: https://github.com/samber/slog-formatter
- ConsoleHandler(类似于 Zap 的 ConsoleEncoder): https://gist.github.com/wijayaerick/de3de10c47a79d5310968ba5ff101a19
- logf(属性 {key} 插值,丰富的 tty 输出): https://pkg.go.dev/github.com/AndrewHarrisSPU/logf (使用延迟 Handler 存储: https://golang.ac.cn/play/p/psdD7KDF5fp )
- slogd - 带持续时间的 slog https://github.com/kaihendry/slogd 带视频 https://youtu.be/IsPa11N5pzI
- tinted(彩色)输出: https://pkg.go.dev/github.com/lmittmann/tint
- humane:一个对人类友好的(但仍主要是结构化的)slog Handler: https://github.com/telemachus/humane
- slug:一个为人类打印彩色日志的 handler: https://github.com/dotse/slug
- slogor:一个彩色的 slog handler: https://gitlab.com/greyxor/slogor
- klog:Kubernetes 使用的文本格式。在使用 main 包的日志器时提供 klog 输出路由,并提供一个更简单的日志器,只写入到 stderr。支持 slog/logr 和 go-logr/logr API。
- slogjson:使用即将推出的JSON v2 库进行格式化,可选单行美化打印: https://github.com/veqryn/slog-json
日志器桥接
- Zap Handler,一个使用 Zap 的 slog Handler: https://github.com/chanchal1987/zaphandler
- zapr:从 v1.3.0 开始,同一个日志器实例同时支持 slog/logr 和 go-logr/logr API。
- GoKit 的 Handler: https://github.com/tjhop/slog-gokit。
日志中间件
- slogctx:在上下文(context)中存储属性或日志器,从上下文中读取任何自定义值: https://github.com/veqryn/slog-context
- slog-context/otel:自动读取 OpenTelemetry TraceID 和 SpanID 并添加到日志中,并可以设置 Span 错误码: github.com/veqryn/slog-context/otel
- slogdedup:属性键的去重和排序,支持多种策略,对 JSON 日志记录很有用。提供便捷方法输出到 Stackdriver、Graylog 等: https://github.com/veqryn/slog-dedup
HTTP 服务器中间件
- slog-gin:Gin 框架的 slog 日志器中间件: https://github.com/samber/slog-gin
- slog-echo:Echo 框架的 slog 日志器中间件: https://github.com/samber/slog-echo
- slog-fiber:Fiber 框架的 slog 日志器中间件: https://github.com/samber/slog-fiber
- slog-chi:Chi 框架的 slog 日志器中间件: https://github.com/samber/slog-chi
日志接收器
- 使用 OpenTelemetry 和
slog
的实验性示例: https://github.com/justinsb/experiments-slog - 带有 OpenTelemetry 追踪的简单 slog handler: https://github.com/ttys3/slogsimple/tree/main
- slog-datadog:一个用于 Datadog 的
slog.Handler
: https://github.com/samber/slog-datadog - slog-rollbar:一个用于 Rollbar 的
slog.Handler
: https://github.com/samber/slog-rollbar - slog-sentry:一个用于 Sentry 的
slog.Handler
: https://github.com/samber/slog-sentry - slog-syslog:一个用于 Syslog 的
slog.Handler
: https://github.com/samber/slog-syslog - slog-logstash:一个用于 Logstash 的
slog.Handler
: https://github.com/samber/slog-logstash - slog-fluentd:一个用于 Fluentd 的
slog.Handler
: https://github.com/samber/slog-fluentd - slog-graylog:一个用于 Graylog 的
slog.Handler
: https://github.com/samber/slog-graylog - slog-loki:一个用于 Loki 的
slog.Handler
: https://github.com/samber/slog-loki - slog-slack:一个用于 Slack 的
slog.Handler
: https://github.com/samber/slog-slack - slog-telegram:一个用于 Telegram 的
slog.Handler
: https://github.com/samber/slog-telegram - slog-mattermost:一个用于 Mattermost 的
slog.Handler
: https://github.com/samber/slog-mattermost - slog-microsoft-teams:一个用于 Microsoft Teams 的
slog.Handler
: https://github.com/samber/slog-microsoft-teams - slog-webhook:一个用于 Webhook 的
slog.Handler
: https://github.com/samber/slog-webhook - slog-kafka:一个用于 Kafka 的
slog.Handler
: https://github.com/samber/slog-kafka - slogbugsnag:一个用于 Bugsnag 的
slog.Handler
: https://github.com/veqryn/slog-bugsnag - slogdriver:一个用于 Stackdriver Logging / GCP Cloud Logging 的
slog.Handler
: https://github.com/jussi-kalliokoski/slogdriver
Handlers
- slog-multi:
slog.Handler
链(管道、扇出等): https://github.com/samber/slog-multi - 各种 handler: https://github.com/galecore/xslog
其他
- jba 编写的额外资源: https://github.com/jba/slog
- slog-sampling:丢弃重复的日志条目: https://github.com/samber/slog-sampling
- slog-context:添加从上下文读取值的支持: https://github.com/PumpkinSeed/slog-context
- slogassert:用于测试代码发出的 slog 日志的 handler: https://github.com/thejerf/slogassert
- sloggen:为
log/slog
生成各种辅助函数: https://github.com/go-simpler/sloggen - sloglint:在使用
log/slog
时确保一致的代码风格: https://github.com/go-simpler/sloglint
此内容是 Go Wiki 的一部分。