[Suggestion] Prevent Rails from writing development/test log files by default

Hi there.

I know this, although easy, would be a big step. So I’d love to hear your thoughts.

I can’t remember the last time I needed to open/read log/development.log or log/test.log. This is just consuming disk space unnecessarily (my test.loge easily reaches more than 1 GB!).

After talking to some other developers, all of them agreed they don’t use it as well.

What if we change this behaviour to be optional? It’d still display the logs through the STDOUT, though.

I’ve been doing it in my projects and couldn’t find a reason not to do it.

The way I currently do it is similar to what Heroku’s rails_12factor gem used to do (and now is the default in Rails for production environment):

config/environments/development.rb

Prevents from writing logs on log/development.log

logger = ActiveSupport::Logger.new(STDOUT)

logger.formatter = config.log_formatter

config.logger = ActiveSupport::TaggedLogging.new(logger)

config/environments/test.rb

Prevents from writing logs on log/test.log

config.log_level = :warn

logger = ActiveSupport::Logger.new(STDOUT)

logger.formatter = config.log_formatter

config.logger = ActiveSupport::TaggedLogging.new(logger)

Thank you,

Lucas.

I personally use test.log a lot to check the sql queries that are being made in my test run.

Also setups using pow or any long running web server only uses the development.log so changing this will break that setup. I can see we disabling the boardcast, but I’d not do that by default.

I use them too, but at work we only write to the log if the file already exists. So if you rm `log/test.log` it won't be written to, but if you touch it, then you'll get logs.

an alternative to this change would be to symlink log/yourlog.log to /dev/null

$ ln -s log/production.log /dev/null

I do this, and it works well for me in dev mode without impact to others sharing the repo or other environments.

Thanks everyone for the replies.

Thanks Ed, I’m glad to hear that there are more people doing it.

Thanks everyone for the replies.

Thanks Ed, I’m glad to hear that there are more people doing it, which means my suggestion wasn’t that bad after all :slight_smile: