Giter Site home page Giter Site logo

Confused with the slogr level about logr HOT 4 OPEN

zwpaper avatar zwpaper commented on August 16, 2024
Confused with the slogr level

from logr.

Comments (4)

pohly avatar pohly commented on August 16, 2024

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.

zwpaper avatar zwpaper commented on August 16, 2024

Let me detail my case more,

when I am logging, I have the following choices:

  1. Error() when error happened
  2. Info() when it should always be printed
  3. 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:

  1. logr.Error(): 5
  2. 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.

zwpaper avatar zwpaper commented on August 16, 2024

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.

  1. Info(): always logs all the info logs
  2. Error(): always print all leveled logs
  3. 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.

pohly avatar pohly commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.