Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Func log method #321

Merged
merged 1 commit into from
May 19, 2021
Merged

Add Func log method #321

merged 1 commit into from
May 19, 2021

Commits on May 19, 2021

  1. Add Func log method

    This is adds the Func log method to log using an anonymous function
    only if the level is currently enabled.
    
    The use case is for when you don't own an object and therefore can't
    create your own marshaller but need to do some translation prior to
    logging.
    
    For example, this:
    
    msg := log.Debug()
    if msg.Enabled() {
      msg.Str("complicated_thing", makeBinaryThingLoggable(thing))
    }
    msg.Msg("Sending complicated thing")
    
    Turns into this:
    
    log.Debug().
      Func(func(e *Event) { e.Str("complicated_thing", makeBinaryThingLoggable(thing)) }).
      Msg("Sending complicated thing")
    marwatk committed May 19, 2021
    Configuration menu
    Copy the full SHA
    e4f24c8 View commit details
    Browse the repository at this point in the history