-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7891] - apply/pubilsh logging config
- Loading branch information
Showing
8 changed files
with
110 additions
and
71 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
class CustomLogFormatter < SemanticLogger::Formatters::Json | ||
def call(log, logger) | ||
super | ||
|
||
format_job_data | ||
format_exception | ||
format_json_message_context | ||
format_backtrace | ||
remove_post_params | ||
|
||
hash.to_json | ||
end | ||
|
||
private | ||
|
||
def format_job_data | ||
hash[:job_id] = RequestStore.store[:job_id] if RequestStore.store[:job_id].present? | ||
hash[:job_queue] = RequestStore.store[:job_queue] if RequestStore.store[:job_queue].present? | ||
end | ||
|
||
def format_exception | ||
exception_message = hash.dig(:exception, :message) | ||
return if exception_message.nil? | ||
|
||
hash[:message] = "Exception occurred: #{exception_message}" | ||
end | ||
|
||
def format_json_message_context | ||
if hash[:message].present? | ||
context = JSON.parse(hash[:message])["context"] | ||
hash[:sidekiq_job_context] = hash[:message] | ||
hash[:message] = context | ||
end | ||
rescue JSON::ParserError | ||
nil | ||
end | ||
|
||
def format_backtrace | ||
return unless hash[:message]&.start_with?("/") | ||
|
||
message_lines = hash[:message].split("\n") | ||
return unless message_lines.all? { |line| line.start_with?("/") } | ||
|
||
hash[:backtrace] = hash[:message] | ||
hash[:message] = "Exception occured: #{message_lines.first}" | ||
end | ||
|
||
def remove_post_params | ||
return unless method_is_post_or_put_or_patch? && hash.dig(:payload, :params).present? | ||
|
||
hash[:payload][:params].clear | ||
end | ||
|
||
def method_is_post_or_put_or_patch? | ||
hash.dig(:payload, :method).in?(%w[PUT POST PATCH]) | ||
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -10,6 +10,8 @@ feedback_link_url: "https://forms.office.com/e/Q6LVwtEKje" | |
support_email: [email protected] | ||
data_email: [email protected] | ||
|
||
log_level: info | ||
|
||
dttp: | ||
client_id: "application-registration-client-id-from-env" | ||
scope: "https://dttp-dev.crm4.dynamics.com/.default" | ||
|
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