Coder Social home page Coder Social logo

Comments (7)

makkes avatar makkes commented on June 19, 2024

@thockin as discussed on Slack.

from logr.

thockin avatar thockin commented on June 19, 2024

Pasting (slightly edited) short note from sloack so I don't lose it:

So you can't tell if they intentionally gave you a Discard() or just "don't care". You're right that this change had an unforeseen breaking implication. Sorry about that! I updated the release notes.

We probably don't want to revert that change, so let's think.

Logger is a value and we've (intentionally) made the zero value useful. If you need a caller has to pass something in, I would either make the argument a *Logger (so it can be nil) or ask them to pass Discard() explicitly.

Discard logger already returns false for Enabled(). We could maybe add something like Logger.IsImplemented(), which is only true if you go through New(). I kind of hate it. Open to ideas.

from logr.

pohly avatar pohly commented on June 19, 2024

logr.Logger{} != logr.Discard()

I don't think we ever promised that logr.Discard() is or is not equal to the zero value. The API only guaranteed that the Logger value can be compared and that logr.Discard always returns an equal value.

There is a comment that pointer to a logger should be used when detecting "no logger" is important:

logr/logr.go

Lines 130 to 133 in 5d57712

// Calling methods with the null logger (Logger{}) as instance will crash
// because it has no LogSink. Therefore this null logger should never be passed
// around. For cases where passing a logger is optional, a pointer to Logger
// should be used.

Ignore the comment in that section about the null logger, that is out-dated. But it doesn't change the recommendation.

from logr.

thockin avatar thockin commented on June 19, 2024

from logr.

pohly avatar pohly commented on June 19, 2024

-> #182

from logr.

thockin avatar thockin commented on June 19, 2024

@makkes - Given that we don't want to revert this - the options are either

a) you use *Logger to indicate optional Logger
b) you don't make it optional, and user says what they mean
c) we add API surface to indicate a difference between Logger{} and Discard(), which I think we don't want to do.

Are we OK to close this?

from logr.

makkes avatar makkes commented on June 19, 2024

We already fixed our code and removed the conditional, basically opting for case b) you gave above.

Thanks for the clarification on expectations here, everyone!

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.