-
Notifications
You must be signed in to change notification settings - Fork 26
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
Structured Logging #30
Conversation
Signed-off-by: Thom May <thom@chef.io>
Child loggers mean that we can create new instances of a logger for subsystems or specific classes, but still only have a single set of outputs. Signed-off-by: Thom May <thom@chef.io>
Signed-off-by: Thom May <thom@chef.io>
Signed-off-by: Thom May <thom@chef.io>
Signed-off-by: Thom May <thom@chef.io>
def add(severity, message = nil, progname = nil, data: {}, &block) | ||
data = metadata.merge(data) if data.kind_of?(Hash) | ||
parent.send(:pass, severity, message, progname, data: data, &block) | ||
end |
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.
this whole class is nifty.
lib/mixlib/log/logger.rb
Outdated
@@ -0,0 +1,103 @@ | |||
require "logger" | |||
|
|||
# A subclass of Ruby's stdlib Logger with all the mutex and logrotation stuff |
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.
wouldn't some customers be relying on the logrotation stuff?
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.
nevermind, i see the big block of red where this was copied from monologger in the other PR...
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.
wouldn't some customers be relying on the logrotation stuff?
@lamont-granquist you should have trusted your instincts, yes at least one of your customers misses log rotation in Windows. 😢
lib/mixlib/log/logging.rb
Outdated
SEV_LABEL[sev + 1] || -"ANY" | ||
end | ||
end | ||
include Severity |
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.
defining the module only to include it seems a bit unusual here... if there's a reason, could use a comment...
lib/mixlib/log/logging.rb
Outdated
# No need to incur method_missing overhead on every log call. | ||
[:trace, :debug, :info, :warn, :error, :fatal].each do |method_name| | ||
level = LEVELS[method_name] | ||
class_eval(<<-METHOD_DEFN, __FILE__, __LINE__) |
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.
probably use define_method
here, its faster an i still don't understand why class_eval
would be any better, plus i think you need __LINE__+1
...
Signed-off-by: Thom May <thom@chef.io>
We do two things here: