Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Remove field slice in nulllogger to make it comparable #108

Merged
merged 2 commits into from Oct 25, 2017
Merged

Conversation

xichen2020
Copy link
Contributor

@xichen2020 xichen2020 commented Oct 22, 2017

cc @cw9 @robskillington @prateek @jeromefroe

This PR makes null logger a pointer type.

@coveralls
Copy link

coveralls commented Oct 22, 2017

Coverage Status

Coverage remained the same at 80.493% when pulling e76dc88 on xichen-nulllogger into 2552847 on master.

log/logger.go Outdated
@@ -155,7 +155,7 @@ func (l nullLogger) WithFields(newFields ...Field) Logger {
fields = append(fields, existingFields.ValueAt(i))
}
fields = append(fields, newFields...)
return nullLogger{Fields(fields)}
return &nullLogger{Fields(fields)}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we return a new logger here, don't we lose the ability to compare NullLoggers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point, in that case I'll remove the fields from the NullLogger struct since it's not logging anything regardless.

log/logger.go Outdated

func (l nullLogger) WithFields(newFields ...Field) Logger {
func (*nullLogger) Enabled(_ Level) bool { return false }
func (*nullLogger) Fatalf(msg string, args ...interface{}) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

why not os.Exit(1) here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, that wasn't my change, I can add it however.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good

log/logger.go Outdated
func (l nullLogger) WithFields(newFields ...Field) Logger {
func (*nullLogger) Enabled(_ Level) bool { return false }
func (*nullLogger) Fatalf(msg string, args ...interface{}) {}
func (*nullLogger) Fatal(msg string) { os.Exit(1) }
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe log the message before exiting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if that's consistent with what the null logger does, IMO null logger shouldn't log anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just feels weird to be crashing the process without any indication why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd think in that case the user should not be using the null logger and instead use a normal logger like SimpleLogger.

Copy link
Contributor

@jeromefroe jeromefroe left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@cw9 cw9 left a comment

Choose a reason for hiding this comment

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

LGTM, might want to update the title of the pr as well

@cw9 cw9 changed the title Make null logger a pointer type Remove field slice in nulllogger to make it comparable Oct 25, 2017
@cw9 cw9 merged commit 515e303 into master Oct 25, 2017
@cw9 cw9 deleted the xichen-nulllogger branch October 25, 2017 15:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants