-
Notifications
You must be signed in to change notification settings - Fork 2
Patch logger to match Superlogger format, insert instrumentation logs #68
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
ActiveSupport::LogSubscriber.colorize_logging = false | ||
|
||
class ActiveSupport::Logger::SimpleFormatter | ||
def call(severity, time, progname, msg) | ||
formatted_severity = severity[0] | ||
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3) | ||
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. Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
caller_location = get_caller_location | ||
args = format_args(msg) | ||
|
||
"#{formatted_time} | CMEvaluator | CMEvaluator | #{formatted_severity} | #{caller_location} | #{args}\n" | ||
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. Line is too long. [108/100] |
||
end | ||
|
||
def format_args(args) | ||
output = if args.is_a?(Hash) | ||
# Format args in key=value pair, separated by pipes | ||
args.map do |key, value| | ||
"#{key}=#{value}" | ||
end.join(' | ') | ||
else | ||
args.to_s.gsub(/\033\[1;4;32m(.*)\033\[0m/, '\1') | ||
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 need to add that this is 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. This follows the behaviour of Superlogger: If it receives a hash it will print out as |
||
end | ||
output.squish | ||
end | ||
|
||
def get_caller_location | ||
location = caller_locations(6, 1).first | ||
|
||
# Extract filename without file extension from location.path | ||
# eg. superlogger/lib/superlogger/logger.rb | ||
file = location.path.split('/').last.split('.').first | ||
|
||
"#{file}:#{location.lineno}" | ||
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.
Unused method argument - progname. If it's necessary, use _ or _progname as an argument name to indicate that it won't be used.