Comments (6)
记录下 args 也可以,我下个版本在 record 加个 Fmt, Args
备份。
from slog.
handler 这里拿不到了, args 已经被格式化到 record.Message 了
from slog.
handler 这里拿不到了, args 已经被格式化到 record.Message 了
是否有别的方法可以拿到,便于判断是否需要做通知 @inhere
from slog.
这种情况应该设置 context data 或者 extra 数据, 使用更方便:
// add log
slog.WithData(slog.M{"notify": true}).Info("some message")
// in handler
func (n *notify) Handle(record *slog.Record) error {
notify := record.Data["notify"]
if notify {
// do something ...
}
return nil
}
from slog.
这种情况应该设置 context data 或者 extra 数据, 使用更方便:
// add log slog.WithData(slog.M{"notify": true}).Info("some message") // in handler func (n *notify) Handle(record *slog.Record) error { notify := record.Data["notify"] if notify { // do something ... } return nil }
@inhere
1、那这样就需要在所有地方都加上.WithData(slog.M{"notify": true})
,
2、对于那些返回自定义error
的有附加数据得map[string]any
,那我还需要把map[string]any
转成slog.M
需要做以上两个处理才可以。
如果能在record 拿到args,那改动就很小,slog.Error(err)
只需在record拿到参数断言判断下就可以做很多事情。
from slog.
发了 v0.5.2, logger 新增了选项:
// BackupArgs backup log input args to Record.Args
BackupArgs bool
from slog.
Related Issues (20)
- record中的Time time.Time HOT 8
- 能在 golang 1.10 版本下使用吗 HOT 1
- Setting channel name cross multiple loggers HOT 3
- Level handling is non-obvious HOT 3
- slog 运行时不会限制备份数量和压缩备份文件 HOT 3
- 在Console模式下也支持类似withfield功能 HOT 6
- syslog 能否增加 facility 支持? HOT 7
- [Bug] RotateTime.level() HOT 2
- Run rotate
- gorm support HOT 2
- 内建的 rotate 机制有多个bug HOT 2
- 需要一个动态设置日志级别的接口
- 按日期滚动 如果当天时间节点的日志文件已存在 不会append 会直接替换 HOT 1
- 日志按everyday自动滚动,文件名的日期对应的是前一天的日志 HOT 7
- 自定义模板报 invalid memory address or nil pointer dereference HOT 4
- NewFlushCloseHandler bytes.Buffer does not implement handler.FlushCloseWriter HOT 1
- syslog severity mapping problem
- Isn't `slog.Fatal()` meant to call `os.Exit(1)`? HOT 4
- slog: failed to handle log, error: write ./logs/info.log: file already closed HOT 2
- 设置日志颜色,支持只设置 tag,不设置日志内容颜色 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slog.