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://go-lang.org.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 使用的文本格式。在使用主包的 logger 和 一个更简单的 logger 时提供 klog 输出路由,该 logger 只写入 stderr。slog/logr 和 go-logr/logr API 都支持。
- slogjson: 使用即将推出的 JSON v2 库进行格式化,可选单行美化打印: https://github.com/veqryn/slog-json
Logger 桥接
- Zap Handler, 一个使用 Zap 的 slog handler: https://github.com/chanchal1987/zaphandler
- zapr: 从 v1.3.0 开始,同一个 logger 实例同时支持 slog/logr 和 go-logr/logr API。
- GoKit 的 handler: https://github.com/tjhop/slog-gokit。
Logging Middleware (日志中间件)
- slogctx: 在 context 中存储属性或 logger, 从 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: slog logger 的 Gin 中间件: https://github.com/samber/slog-gin
- slog-echo: slog logger 的 Echo 中间件: https://github.com/samber/slog-echo
- slog-fiber: slog logger 的 Fiber 中间件: https://github.com/samber/slog-fiber
- slog-chi: slog logger 的 Chi 中间件: https://github.com/samber/slog-chi
Log sinks (日志接收器)
- 实验性示例,同时使用 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 (Handler)
- slog-multi:
slog.Handler
链 (管道, fanout, …): https://github.com/samber/slog-multi - 各种 handlers: https://github.com/galecore/xslog
其他
- jba 撰写的其他资源: https://github.com/jba/slog
- slog-sampling: 丢弃重复的日志条目: https://github.com/samber/slog-sampling
- slog-context: 添加从 context 读取值的功能: https://github.com/PumpkinSeed/slog-context
- slogassert: 用于测试代码发出的 slog 日志的 handle: 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 的一部分。