Reduce log size in development/test environments

Code based on the logger Rails uses by default; as mentioned in the
Rails configuration guide:

> [the logger] defaults to an instance of ActiveSupport::TaggedLogging
> that wraps an instance of ActiveSupport::Logger which outputs a log to
> the log/ directory. You can supply a custom logger, to get full
> compatibility you must follow these guidelines:
>
> * To support a formatter, you must manually assign a formatter from
>   the config.log_formatter value to the logger.
> * To support tagged logs, the log instance must be wrapped with
>   ActiveSupport::TaggedLogging.
> * To support silencing, the logger must include
>   ActiveSupport::LoggerSilence module. The ActiveSupport::Logger class
>   already includes these modules.

Just like the documentation mentions, we're enabling log rotation using
"1" as the number of old files to keep and then the maximum size of the
log file.
This commit is contained in:
Javi Martín
2022-05-23 16:20:27 +02:00
parent db4db07853
commit e0a94f6a6e
2 changed files with 12 additions and 0 deletions

View File

@@ -64,6 +64,12 @@ Rails.application.configure do
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
# Limit size of local logs
# TODO: replace with config.log_file_size after upgrading to Rails 7.1
logger = ActiveSupport::Logger.new(config.default_log_file, 1, 100.megabytes)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.after_initialize do config.after_initialize do
Bullet.enable = true Bullet.enable = true
Bullet.bullet_logger = true Bullet.bullet_logger = true

View File

@@ -54,6 +54,12 @@ Rails.application.configure do
# Raises error for missing translations. # Raises error for missing translations.
# config.action_view.raise_on_missing_translations = true # config.action_view.raise_on_missing_translations = true
# Limit size of local logs
# TODO: replace with config.log_file_size after upgrading to Rails 7.1
logger = ActiveSupport::Logger.new(config.default_log_file, 1, 100.megabytes)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.after_initialize do config.after_initialize do
Bullet.enable = true Bullet.enable = true
Bullet.bullet_logger = true Bullet.bullet_logger = true