-
Notifications
You must be signed in to change notification settings - Fork 74
[WIP] Move resource id param to logger initialize #570
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
base: master
Are you sure you want to change the base?
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 |
---|---|---|
@@ -1,31 +1,32 @@ | ||
module ManageIQ | ||
module AutomationEngine | ||
class Logger < ManageIQ::Loggers::Base | ||
attr_reader :automation_log_wrapper | ||
attr_reader :automation_log_wrapper, :resource_id | ||
|
||
def initialize(*args, automation_log_wrapper:, **kwargs) | ||
def initialize(*args, automation_log_wrapper:, resource_id: nil, **kwargs) | ||
@automation_log_wrapper = automation_log_wrapper | ||
@resource_id = resource_id | ||
|
||
super(*args, **kwargs) | ||
end | ||
|
||
def self.create_log_wrapper(io = File::NULL) | ||
def self.create_log_wrapper(io: File::NULL, automation_log_wrapper: nil, resource_id: nil) | ||
# We modify the interface of logger methods such as info/warn/etc. to allow the keyword argument | ||
# resource_id. Therefore, we need to wrap all client logger calls to these methods to process the resource_id, | ||
# cut the request_log entry and forward the remaining arguments to the logger. | ||
new(io, :progname => "automation", :automation_log_wrapper => Vmdb::Loggers.create_logger("automation.log")) | ||
new(io, :progname => "automation", :automation_log_wrapper => automation_log_wrapper || Vmdb::Loggers.create_logger("automation.log"), :resource_id => resource_id) | ||
end | ||
|
||
private def add_to_db(severity, message = nil, progname = nil, resource_id: nil) | ||
return [severity, message, progname] unless resource_id | ||
private | ||
|
||
def add(severity, message = nil, progname = nil, &block) | ||
automation_log_wrapper.add(severity, message, progname, &block) | ||
|
||
severity ||= Logger::UNKNOWN | ||
return true if severity < @level | ||
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. Do we want our level, or the level of our wrapped log? (that is the whole 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. Maybe we sync the |
||
|
||
progname ||= @progname | ||
|
||
# Adapted from Logger#add | ||
severity ||= UNKNOWN | ||
if severity < level | ||
return [severity, message, progname] | ||
end | ||
if progname.nil? | ||
progname = @progname | ||
end | ||
if message.nil? | ||
if block_given? | ||
message = yield | ||
|
@@ -37,43 +38,7 @@ def self.create_log_wrapper(io = File::NULL) | |
|
||
RequestLog.create(:message => message, :severity => format_severity(severity), :resource_id => resource_id) if resource_id | ||
|
||
[severity, message, progname] | ||
end | ||
|
||
def info(progname = nil, resource_id: nil, &block) | ||
severity, message, progname = add_to_db(INFO, nil, progname, resource_id: resource_id, &block) | ||
automation_log_wrapper.add(severity, message, progname, &block) | ||
add(severity, message, progname, &block) | ||
end | ||
|
||
def debug(progname = nil, resource_id: nil, &block) | ||
severity, message, progname = add_to_db(DEBUG, nil, progname, resource_id: resource_id, &block) | ||
automation_log_wrapper.add(severity, message, progname, &block) | ||
add(severity, message, progname, &block) | ||
end | ||
|
||
def warn(progname = nil, resource_id: nil, &block) | ||
severity, message, progname = add_to_db(WARN, nil, progname, resource_id: resource_id, &block) | ||
automation_log_wrapper.add(severity, message, progname, &block) | ||
add(severity, message, progname, &block) | ||
end | ||
|
||
def error(progname = nil, resource_id: nil, &block) | ||
severity, message, progname = add_to_db(ERROR, nil, progname, resource_id: resource_id, &block) | ||
automation_log_wrapper.add(severity, message, progname, &block) | ||
add(severity, message, progname, &block) | ||
end | ||
|
||
def fatal(progname = nil, resource_id: nil, &block) | ||
severity, message, progname = add_to_db(FATAL, nil, progname, resource_id: resource_id, &block) | ||
automation_log_wrapper.add(severity, message, progname, &block) | ||
add(severity, message, progname, &block) | ||
end | ||
|
||
def unknown(progname = nil, resource_id: nil, &block) | ||
severity, message, progname = add_to_db(UNKNOWN, nil, progname, resource_id: resource_id, &block) | ||
automation_log_wrapper.add(severity, message, progname, &block) | ||
add(severity, message, progname, &block) | ||
super | ||
end | ||
end | ||
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.
think this wants to be after we resolve
message
?Doesn't seem optimal if we
message ||= yield
and then haveautomation_log_wrapper
have to do the same thingThere 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.
I was thinking of the wrapped logger had a different progname that it wanted to use this would allow that
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.
Plus I think this matches the existing behavior because it used to call the wrapped logger directly from
def info
as opposed to fromadd