-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add log level error #16
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 |
---|---|---|
|
@@ -13,6 +13,8 @@ class Logger | |
def_delegators(*([:@logger] + ::Logger.instance_methods(false))) | ||
|
||
DEFAULT_EVENT_NAME = "log" | ||
LOG_ERROR = "ERROR" | ||
ERROR_STATUS = 500 | ||
|
||
FORMATTER = proc do |severity, time, event_name, data| | ||
entry = | ||
|
@@ -54,8 +56,11 @@ class Logger | |
entry.merge!(data) | ||
elsif !data.nil? | ||
entry[:message] = data.to_s | ||
entry[:status] = ERROR_STATUS if data.to_s.downcase.include?(LOG_ERROR) | ||
end | ||
|
||
entry[:level] = LOG_ERROR if entry[:status].to_i.between?(400, 599) | ||
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 formatter should not be coupled to HTTP, as it is also used in background jobs that do not adhere to HTTP's statuses. 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. Also, log level is already passed in from the outside as 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.
Log level that is passed from the outside, sets the log level at app level e.g.
I need to set the level as in string so it can be filtered in datadog logs. 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.
For this reason, I custom set the |
||
|
||
# Save some disk space | ||
entry.reject! { |_, value| value.nil? } | ||
|
||
|
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 is a rather weak condition, as it's entirely possible to get a log body with a word
error
over the course of a successful request.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.
I tested with different scenarios and it comes in the else statement only in case of an error. I haven't found any success case that was in the else statement.