-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #640 from PRX/feat/json_logging
Init json logging
- Loading branch information
Showing
9 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ capybara-*.html | |
/.bundle | ||
/vendor/bundle | ||
/log/* | ||
!/log/.keep | ||
/tmp/* | ||
/db/*.sqlite3 | ||
/public/system/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Date::DATE_FORMATS[:default] = Date::DATE_FORMATS[:iso8601] | ||
Time::DATE_FORMATS[:default] = Time::DATE_FORMATS[:iso8601] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class CmsLogger < Ougai::Logger | ||
# include ActiveSupport::LoggerThreadSafeLevel | ||
# include ActiveSupport::LoggerSilence | ||
|
||
def create_formatter | ||
if Rails.env.development? || Rails.env.test? | ||
color_config = Ougai::Formatters::Colors::Configuration.new | ||
formatter = Ougai::Formatters::Customizable.new( | ||
format_msg: proc do |severity, datetime, _progname, data| | ||
format( | ||
'%<severity>s %<datetime>s: %<msg>s %<data>s', | ||
severity: color_config.color(:severity, severity, severity), | ||
datetime: color_config.color(:datetime, datetime, severity), | ||
msg: color_config.color(:msg, data.delete(:msg).try(:squish), severity), | ||
data: data.ai(multiline: false) | ||
) | ||
end, | ||
# this appears to be redundant with format_msg, so just no-op | ||
format_data: proc { |_data| } | ||
) | ||
formatter.datetime_format = '%H:%M:%S.%L' | ||
formatter | ||
else | ||
Ougai::Formatters::Bunyan.new | ||
end | ||
end | ||
|
||
def elapsed(msg = '', args = {}, &block) | ||
measure(:info, msg, args, &block) | ||
end | ||
|
||
def debug_elapsed(msg = '', args = {}, &block) | ||
measure(:debug, msg, args, &block) | ||
end | ||
|
||
private | ||
|
||
def measure(level, msg, args, &block) | ||
elapsed = Benchmark.measure(&block) | ||
if msg.is_a? Hash | ||
public_send(level, msg.merge(elapsed: elapsed.real)) | ||
else | ||
public_send(level, msg, args.merge(elapsed: elapsed.real)) | ||
end | ||
end | ||
end |