Suddenly my Rails 4.2 app is writing nothing to development.log.
Absolutely nothing!
I have tried checking the correct environment is being used, restarting the server, checking for gems that might interact with logger, checking permissions, logger.flush
, and rake log:clean
.
The log file is now completely empty, and nothing is being written.
Running rails s
gives:
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-03-14 18:49:57] INFO WEBrick 1.3.1
[2015-03-14 18:49:57] INFO ruby 2.1.5 (2014-11-13) [x86_64-darwin14.0]
[2015-03-14 18:49:57] INFO WEBrick::HTTPServer#start: pid=3963 port=3000
There are quite a few similar questions on Stackoverflow, but none provide an answer that has worked in my case.
I have no idea what would cause this or how to systematically debug.
What steps should I take?
In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.
If you want to change all the default logging for that specific model, you can simply use User. logger = Logger. new(STDOUT) or wherever you want to log to. In the same way, ActiveRecord::Base.
If you want to know the current log level, you can call the Rails. logger. level method. This is useful when you want to log under development or staging without flooding your production log with unnecessary information.
This can be done in one of two ways—first, with configuration. As shown below, we're setting the format specification to show the log message's datetime and message and the program's name. Alternatively, we can also change the format by overriding the logger's format method.
OK, after much going round in circles, I finally found the culprit.
The rails_12factor
is apparently overwriting config.logger.
See: https://github.com/heroku/rails_stdout_logging/blob/master/lib/rails_stdout_logging/rails3.rb#L7
I removed this gem from the development environment (I really only need it in the deployed environment) and everything is now working.
To put a gem in production only, it needs to be in a gem environment group like this:
# This is override development.log output and should only go in production.
group :production do
gem 'rails_12factor'
end
Thanks @maxd for helping to get me thinking in the right direction.
Add the following line to config/environments/development.rb
config.log_level = :debug
restart server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With