mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 06:26:41 +08:00
cbbe3a808b
Why this change? This ensures that malicious requests cannot end up causing the logs to quickly fill up. The default chosen is sufficient for most legitimate requests to the Discourse application. When truncation happens, parsing of logs in supported format like lograge may break down.
32 lines
900 B
Ruby
32 lines
900 B
Ruby
# 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
|
|
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
|
|
end
|
|
end
|