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

Fix common logging #316

Merged
merged 8 commits into from
Sep 25, 2019
Merged

Fix common logging #316

merged 8 commits into from
Sep 25, 2019

Conversation

julio-lopez
Copy link
Contributor

Change Overview

Send log messages to a common logger instead of creating a new logger for every message.

In the future, this will allow implementing additional functionality such as:

  • Setting the log level (at the package level) for the entire process
  • Setting logging destinations and options.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature

Copy link
Contributor

@tdmanv tdmanv left a comment

Choose a reason for hiding this comment

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

LGTM, but I'll let @SupriyaKasten take a look

return l
}

func (l *logger) WithError(err error) Logger {
l.err = err
l.entry = l.entry.WithError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

@julio-lopez how are we planning to propagate the error from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Let me fix it and add tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SupriyaKasten Addressed the issue and started adding a minimal set of tests. This particular issue is not covered by the current set of tests. I'll add more. Feel free to block the PR until enough test coverage is included.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @julio-lopez, will block it, so that mergify does not merges it automatically before it is ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SupriyaKasten Expanded the tests, it should cover the basic functionality that is currently implemented. PTAL and LMK if I missed anything. Thanks.

Copy link
Contributor

@SupriyaKasten SupriyaKasten left a comment

Choose a reason for hiding this comment

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

Blocking this PR.... waiting on tests.

Leverage Log(level, args ...) function
Covers basic functionality.
The tests are dependent on the implementation since the
output of logging is not directly "visible" to the caller
and instead sent to a specific logging sink. The tests
in this PR leverage implementation-specific hooks to
check the expected behavior.
@julio-lopez
Copy link
Contributor Author

@SupriyaKasten Expanded test coverage. PTAL.

}

func (l *logger) WithContext(ctx context.Context) Logger {
l.ctx = ctx
l.entry = l.entry.WithContext(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

@julio-lopez What do you think about setting the logrus.entry.Context using: entry =entry.WithContext(l.ctx) in the func (l *logger) Print(msg string){} ? We do extract the context fields though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issues is that it would require keeping the entry around, instead of the context.
We may want to change the approach in the future and set the context in the entry, as you suggest, and then get the fields from the context at a much later stage, in the "hooks" or the "formatters".
There is no need to set the context in the entry and keep it around, given the current approach where the fields are extracted and added to the entry before calling Log(level, ...), as you point out. The fields need to be explicitly extracted, since logrus does not do anything special with the context itself. In particular, there is no context specific information in the log messages sent by default to stderr. This is because there is no general way to discover what values have been set in a context.

@SupriyaKasten
Copy link
Contributor

PR looks great! Thanks @julio-lopez 🚀

@mergify mergify bot merged commit f65084f into master Sep 25, 2019
@mergify mergify bot deleted the fix-common-logging branch September 25, 2019 17:24
@julio-lopez
Copy link
Contributor Author

Thanks @SupriyaKasten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants