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

86 views
Skip to first unread message

Lucas Caton

unread,
Oct 24, 2016, 9:20:10 PM10/24/16
to Ruby on Rails: Core

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.

Rafael Mendonça França

unread,
Oct 24, 2016, 10:16:16 PM10/24/16
to rubyonra...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Aaron Patterson

unread,
Oct 24, 2016, 10:17:54 PM10/24/16
to rubyonra...@googlegroups.com
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.

On Tue, Oct 25, 2016 at 02:15:51AM +0000, Rafael Mendonça França wrote:
> 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.
>
> On Mon, Oct 24, 2016 at 11:20 PM Lucas Caton <lucas...@gmail.com> wrote:
>
> > 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):
--
Aaron Patterson
http://tenderlovemaking.com/

Ed Kim

unread,
Nov 1, 2016, 7:37:50 PM11/1/16
to rubyonra...@googlegroups.com
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.




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.

Lucas Caton

unread,
Nov 1, 2016, 8:36:25 PM11/1/16
to Ruby on Rails: Core
Thanks everyone for the replies.

Thanks Ed, I'm glad to hear that there are more people doing it.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Lucas Caton

unread,
Nov 1, 2016, 8:37:42 PM11/1/16
to Ruby on Rails: Core
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 :-)


On Wednesday, 2 November 2016 09:37:50 UTC+10, ed wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages