-
Notifications
You must be signed in to change notification settings - Fork 748
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
Re-use logger instance #2029
Re-use logger instance #2029
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,22 +47,17 @@ type Logger interface { | |
|
||
// Get returns an default instance of the zap logger | ||
func Get() Logger { | ||
var logf = &structuredLogger{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing this structuredLogger reference? and isEmpty() call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here logf will always be empty, hence it was removed. But I am thinking should we instead implement isEmpty() for the global variable and assign the local variable to global variable if the global is empty. Just to keep the code readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wont be isEmpty() be handled by the library itself? I was curious both by the presence and now is removal.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing logic was
Through log messages, it was confirmed that each package was obtaining it's own logger instance:
Thus, the extra method was removed and nil check was moved in-line, keeping the code simple and easy to read. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood, and that was the only place it was used, so helps to remove it. Thank you. |
||
if logf.isEmpty() { | ||
if log == nil { | ||
logConfig := LoadLogConfig() | ||
log = New(logConfig) | ||
return log | ||
log.Info("Initialized new logger as an existing instance was not found") | ||
} | ||
log = logf | ||
return log | ||
} | ||
|
||
func (logf *structuredLogger) isEmpty() bool { | ||
return logf.zapLogger == nil | ||
} | ||
|
||
//New logger initializes logger | ||
func New(inputLogConfig *Configuration) Logger { | ||
log = inputLogConfig.newZapLogger() | ||
log.Info("Constructed new logger instance") | ||
return log | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since, we go through this only during initial bootup - the leaked file handles show up only if the
aws-node
pod on the node goes through a restart for some reason? I thought we've a known issue in the upstream logger lib and so curious why we are not running in to that? Would be good to expand on this in the PR description.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the upstream issue of natefinch/lumberjack#81, it is not directly applicable in case of ipamd as transient goroutines holding on to logger instances were not observed (using dlv).