Comments (4)
I'm not sure I am following. Are you trying to configure a logr backend so that it prints slog Warning
calls, but not slog Info
calls?
That is indeed not possible because the level range from logr is more limited than the one from slog. slog supports levels that go towards negative infinity (= less important) and towards positive infinity (= more important). logr only has "less important than info/error".
from logr.
Let me detail my case more,
when I am logging, I have the following choices:
- Error() when error happened
- Info() when it should always be printed
- Debug, or some leveled choice, when it should only be printed when manually enabled
when doing Debug logs, the Info()
logs should also be printed, right?
In the slogr case I read, It matches the following levels:
- logr.Error(): 5
- logr.Info(): 0
I can only use 1-4 for other levels logging,
but when I increase the enabled level, the default Info() logs will be gone
from logr.
I have tried locally and believed that I found the correct usage.
we should pass the level to slog using 0-level
, and this will let us use the logr like the original way.
- Info(): always logs all the info logs
- Error(): always print all leveled logs
- V(N): logs as Debug and controlled by the
level
we set
just like this, if I set the level=-4:
Jul 26 16:37:34.595 INF draft-go/main.go:28 hello world
Jul 26 16:37:34.596 ERR draft-go/main.go:29 hello world, err
Jul 26 16:37:34.596 INF draft-go/main.go:31 hello level level=0
Jul 26 16:37:34.596 DBG+3 draft-go/main.go:31 hello level level=1
Jul 26 16:37:34.596 DBG+2 draft-go/main.go:31 hello level level=2
Jul 26 16:37:34.596 DBG+1 draft-go/main.go:31 hello level level=3
Jul 26 16:37:34.596 DBG draft-go/main.go:31 hello level level=4
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=0
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=1
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=2
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=3
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=4
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=5
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=6
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=7
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=8
Jul 26 16:37:34.596 ERR draft-go/main.go:34 hello level err level=9
is that right? if this is the correct usage, it may be worth raising a PR to add an example and docs, and I am glad to help
from logr.
I'm getting lost when you say Error
without being specific whether that is a logr or slog method. I am also not sure I understand what "level
we set" refers to.
A PR with example and docs might help to clarify, so yes, please create one.
from logr.
Related Issues (20)
- Hash-pin workflow dependencies
- add support for slog.LogValuer
- Consider changing how keys are namespaced
- Consider a "group" construct to match slog
- Consider allowing timestamp to be passed into LogSink
- Consider allowing PC to be passed into Handler HOT 3
- Bump min Go version to at least 18? HOT 1
- TODO: Write a nice doc on logr <-> slog
- Enabled + stack unwinding HOT 7
- contextual logging for slog HOT 31
- funcr Feature Request: Add LogInfoLevel Option to skip logging level in the info log HOT 6
- TODO circa Go 1.24: Remove non-slog code and consolidate files
- Cut a new release (v1.4.0?) HOT 7
- Typesafe API HOT 4
- Unable to print Warn Logs when using logr/zapr HOT 6
- Metrics for logged messages HOT 5
- Methods to Interact With Sink Attributes HOT 3
- funcr: slog output omits intermediate groups HOT 7
- I am facing log/slog is no in std (/usr/local/go/src/log/slog) HOT 5
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 logr.