Skip to content

Commit

Permalink
Reduce log size in development/test environments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
javierm committed Jun 28, 2023
1 parent ab698a7 commit 7bbb3c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@

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
Bullet.enable = true
Bullet.bullet_logger = true
Expand Down
6 changes: 6 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
# Raises error for missing translations.
# 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
Bullet.enable = true
Bullet.bullet_logger = true
Expand Down

0 comments on commit 7bbb3c0

Please sign in to comment.