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

support hijacking other-than-"std" log.logger #344

Closed
wants to merge 0 commits into from

Conversation

flisky
Copy link
Contributor

@flisky flisky commented Mar 3, 2017

Sometimes other library requires a log.Logger instance,
but the builtin log doesn't expose the std variable.

@mention-bot
Copy link

@flisky, thanks for your PR! By analyzing the history of the files in this pull request, we identified @peter-edge, @akshayjshah and @skipor to be potential reviewers.

@CLAassistant
Copy link

CLAassistant commented Mar 3, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @flisky - this looks great. I've left a few nits - once they're cleaned up, we can land this.

Note to myself: before landing this, we'll also need to reword the documentation comment for RedirectStdLog to clarify that it only works for the package-global standard logger.

global_test.go Outdated
assert.Equal(t, []observer.LoggedEntry{{
Entry: zapcore.Entry{Message: "redirected"},
Context: []zapcore.Field{},
}}, logs.AllUntimed(), "Unexpected global log output.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the output here isn't global. Please adjust the error message to clarify :)

global.go Outdated
const (
stdLogDefaultDepth = 4
loggerWriterDepth = 1
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we're using these constants in two places, let's make them global. Please remember that this project's style underscore-prefixes globals, so this will be

const (
  _stdLogDefaultDepth = 4
  _loggerWriterDepth = 1
)

@flisky
Copy link
Contributor Author

flisky commented Mar 7, 2017

Thank you, and please take another look.

@akshayjshah
Copy link
Contributor

Hrm, GitHub appears to be interpreting raw git actions oddly. Will re-open in another PR and merge.

akshayjshah added a commit that referenced this pull request Mar 7, 2017
In addition to letting users redirect the output of the standard library's package-global log functions, we should also support wrapping a zap logger in a log.Logger.

This is the same PR as #344, which I somehow closed by mistake :/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants