Why is Rails not writing to development.log
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.
Rails.logger doesn't log the data into development.log
Did you make sure the user running the Rails server has write permissions to the log file?
I've seen this happen if the server is started as root
the first time
sudo rails s
which created the development.log file owned by root.
Then if a non-privileged user starts the server
rails s
the log file cannot be written to because it's owned by root.
No log messages in production.log
Assuming you're running Rails 3.2.1, this is a bug. It was patched in 3.2.2.
If you can't upgrade to 3.2.2 for any reason, this comment on GitHub has a workaround:
# config/initializers/patch_rails_production_logging.rb
Rails.logger.instance_variable_get(:@logger).instance_variable_get(:@log_dest).sync = true if Rails.logger
logger.debug vs puts in Rails debugging?
You're definitely headed the right direction in using logger.debug
instead of puts
as puts
is more for command line applications.
Rails.logger.debug
, or in short logger.debug
writes the parameter text to a log file. This log file is by default environment specific. If you are currently running rails in development
environment then the log file in use is log/development.log
.
If you open the file log/development.log
, you will find the debug text text
in there. To see the log output as they are written to the file, you can use the tail
command (if you are in unix system) as follows in a new terminal with present working directory as your rails application root:
$ tail -f log/development.log
Related Topics
Issues with Has_Many :Through, Cache, Touch and Counter_Cache
Set Compression Level When Generating a Zip File Using Rubyzip
Is Communication Between Two Ruby Processes Possible/Easy
Lion: Problem with Rvm Installing Rubies - Problem Related to Openssl
Sass: Dealing with The Ie 4095 Selectors Per Stylesheet Restriction
Rails Sitemap_Generator Uninitialized Constant
Terminal Not Executing Ruby Files
Anything Speaking Against the Bitnami.Org Ruby/Rails/Redmine Stack
Converting External CSS to Inline CSS for Mail in Rails
"Ruby.Exe Is Not Recognized as an Internal or External Command" in Windows 7
How to Programmatically Take Snapshot of Crawled Webpages (In Ruby)
Gem Install Dm-Postgres-Adapter Build Error
Using Each_With_Index with Map
Activeadmin: Adding Delete for a Nested Resource
Ruby Time.Parse Gives Me Out of Range Error
How to Import Using Fastercsv a Row with a Name Like "CiaráN"