Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add formatter for the logstash-logger gem
Allows for the added payload fields in lograge to surface in logs outside of just controller logs.
- Loading branch information
Showing
5 changed files
with
54 additions
and
1 deletion.
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
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
23 changes: 23 additions & 0 deletions
23
lib/lograge/logstash_logger_formatters/merged_with_lograge_payload.rb
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,23 @@ | ||
begin | ||
require 'logstash-logger' | ||
require 'logstash-event' | ||
rescue LoadError | ||
puts 'You need to install the logstash-event and logstash-logger gems ' \ | ||
'to use Lograge::LogStashLoggerFormatters::MergedWithLogragePayload.' | ||
raise | ||
end | ||
|
||
module Lograge | ||
module LogStashLoggerFormatters | ||
class MergedWithLogragePayload < LogStashLogger::Formatter::Base | ||
private | ||
|
||
def format_event(event) | ||
lograge_event_payload = RequestStore.store[:lograge_event_payload] || {} | ||
lograge_event_payload.merge!(RequestStore.store[:lograge_custom_payload] || {}) | ||
event.overwrite(event.fields.merge(lograge_event_payload)) | ||
"#{event.to_json}\n" | ||
end | ||
end | ||
end | ||
end |
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