Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No log messages in production.log

I wrote a demo HelloWorld Rails app and tested it with WEBrick (it doesn't even use a DB, it's just a controller which prints "hello world"). Then I tried to deploy it to a local Apache powered with Passenger. In fact this test is just to get Passenger working (it's my first deploy on Apache). Now I'm not even sure that Passenger works, but I don't get any error on the Apache side.

When I fire http://rails.test/ the browser shows the Rails 500 error page - so I assume that Passenger works. I want to investigate the logs, but it happens that production.log is empty! I don't think it's a permission problem, because if I delete the file, it is recreated when I reload the page. I tried to change the log level in conf/environments/production.rb, tried to manually write to log file with Rails console production and

 Rails.logger.error('asdf')

it returns true but nothing gets written to production.log. The path (obtained per Rails.logger.inspect) is correct, and I remark that the file is recreated if I manually remove it. How can I know what's going on?

(I already checked the Apache logs, plus I set the highest debug level for Passenger but it seems a Rails problem, so is not logged by the server)

like image 737
Raffaele Avatar asked Mar 09 '12 14:03

Raffaele


People also ask

Should debug logs be in production?

When a problem happens in production, you won't have the debug logs to help identify the root cause. Instead, you have to waste precious time deploying a new version of your code to enable debug logging. Not to mention that you shouldn't forget to disable debug logging when you deploy the fix.

What should be the log level in production?

The usual advice Logging levels are usually considered to be in order of importance: turn on "unimportant" levels in development ( trace , debug and the like), but enable only the "most important" levels ( warning , error , etc.) in production, where resources like CPU time and disk space are precious.

What is a log message?

In computing, a log file is a file that records either events that occur in an operating system or other software runs, or messages between different users of communication software. Logging is the act of keeping a log. In the simplest case, messages are written to a single log file.


1 Answers

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
like image 58
Brandan Avatar answered Sep 23 '22 07:09

Brandan