Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Logger appears to be duplicating log lines

I am experiencing something curious with the rails logger.

When I insert a Rails.logger.info("Some text") in the code, usually to trace flow, I am getting two lines of "Some text" output in the console.

This ordinarily isn't much of a problem, but when I dump the contents of larger objects, the output can get cumbersome to wade through.

This never seemed to happen before I upgraded to Rails 4, or at least, I don't recall it happening.

Does anyone know what is happening here, and if there is a way to stop duplicating log output?

like image 698
John Judd Avatar asked Nov 11 '13 06:11

John Judd


2 Answers

Try moving the rails_12factor gem (if you've got it installed) to the production group.

group :production do
  gem 'rails_12factor'
end
like image 110
Samuel Avatar answered Nov 09 '22 07:11

Samuel


This small workaround solved my issue. Follow these steps:

Under Rails External Libraries, Search for railties module. Go to this path: /lib/commands/server.rb

In this file comment this line, Rails.logger.extend(ActiveSupport::Logger.broadcast(console))

This command will switch off broadcasting, and just restart your rails server. You will not see any repeated logs anymore. Happy coding.

For more info checkout this issue page of rails: https://github.com/heroku/rails_stdout_logging/issues/1

like image 38
mdev Avatar answered Nov 09 '22 08:11

mdev