2023-10-01 22:41:34 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
if Rails.env.production? || ENV["ENABLE_LOGS_TRUNCATION"] == "1"
|
|
|
|
def set_or_extend_truncate_logs_formatter(logger)
|
|
|
|
if logger.formatter
|
|
|
|
logger.formatter.extend(
|
|
|
|
Module.new do
|
|
|
|
def call(*args)
|
|
|
|
truncate_logs_formatter.call(super(*args))
|
|
|
|
end
|
|
|
|
|
|
|
|
def truncate_logs_formatter
|
|
|
|
@formatter ||=
|
|
|
|
TruncateLogsFormatter.new(log_line_max_chars: GlobalSetting.log_line_max_chars)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
)
|
|
|
|
else
|
|
|
|
logger.formatter =
|
|
|
|
TruncateLogsFormatter.new(log_line_max_chars: GlobalSetting.log_line_max_chars)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Rails.application.config.to_prepare do
|
2024-06-26 11:55:05 -05:00
|
|
|
set_or_extend_truncate_logs_formatter(Rails.logger)
|
|
|
|
|
|
|
|
if Rails.logger.respond_to? :chained
|
|
|
|
Rails.logger.chained.each { |logger| set_or_extend_truncate_logs_formatter(logger) }
|
|
|
|
end
|
2023-10-01 22:41:34 -05:00
|
|
|
end
|
|
|
|
end
|