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

Structured Logging #30

Merged
merged 6 commits into from
Feb 26, 2018
Merged

Structured Logging #30

merged 6 commits into from
Feb 26, 2018

Conversation

thommay
Copy link
Contributor

@thommay thommay commented Jan 19, 2018

We do two things here:

  • create child loggers. This means we can create a new logger for a subsystem such as ohai, give it new metadata, but still only manage one set of logging outputs.
  • attach a metadata hash to each message.

Thom May added 2 commits January 4, 2018 12:27
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>
Thom May added 2 commits February 15, 2018 14:13
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
Copy link
Contributor

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.

@@ -0,0 +1,103 @@
require "logger"

# A subclass of Ruby's stdlib Logger with all the mutex and logrotation stuff
Copy link
Contributor

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?

Copy link
Contributor

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...

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. 😢

SEV_LABEL[sev + 1] || -"ANY"
end
end
include Severity
Copy link
Contributor

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...

# 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__)
Copy link
Contributor

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>
@thommay thommay merged commit 2b9b724 into master Feb 26, 2018
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.

4 participants