Jwan622
Jwan622

Reputation: 11647

Duplicate output in logs for Rails app

Here is my output:

Cache read: views/c4f74176be2db099863b59e962270679
Cache read: views/c4f74176be2db099863b59e962270679
Read fragment views/c4f74176be2db099863b59e962270679 (0.3ms)
Read fragment views/c4f74176be2db099863b59e962270679 (0.3ms)
  Rendered planners/new.html.erb within layouts/application (12.0ms)
  Rendered planners/new.html.erb within layouts/application (12.0ms)
  Rendered layouts/_nav_bar.html.erb (1.3ms)
  Rendered layouts/_nav_bar.html.erb (1.3ms)
  Rendered layouts/_footer_bar.html.erb (0.1ms)
  Rendered layouts/_footer_bar.html.erb (0.1ms)
Completed 200 OK in 861ms (Views: 859.2ms | ActiveRecord: 0.7ms)
Completed 200 OK in 861ms (Views: 859.2ms | ActiveRecord: 0.7ms)

Here is my gemfile:

source 'https://rubygems.org'
ruby '2.1.3'

gem 'rails',                    '4.2.0'
gem 'pg',                       '~> 0.18.1'
gem 'sass-rails',               '~> 5.0'
gem 'uglifier',                 '>= 1.3.0'
gem 'coffee-rails',             '~> 4.1.0'

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder',                 '~> 2.0'
gem 'sdoc',                     '~> 0.4.0', group: :doc
gem 'paperclip',                '~> 4.2.1'
gem 'faker',                    '~> 1.4.2'
gem "twitter-bootstrap-rails",  '~> 3.2.0'
gem 'bootstrap_form',           '~> 2.2.0'
gem 'bcrypt',                   '~> 3.1.7'
gem 'unicorn',                  '~> 4.8.3'
gem "therubyracer",             '~> 0.12.1'
gem "less-rails",               '~> 2.6.0'
gem "rails_12factor",           '~> 0.0.3'
gem 'aws-sdk',                  '~> 1.5.7'
gem 'omniauth-twitter',         '~> 1.1.0'
gem 'figaro',                   '~> 1.1.0'
gem 'responders',               '~> 2.1.0'
gem 'faraday',                  '< 0.9.0'
gem 'rest-client',              '~> 1.7.3'
gem 'bootstrap-datepicker-rails'
gem "dalli"


group :development, :test do
  gem 'simplecov',              '~> 0.9.1'
  gem 'pry',                    '~> 0.10.1'
  gem 'pry-byebug'
  gem "factory_girl_rails",     '~> 4.0'
  gem 'web-console',            '~> 2.0'
  gem 'spring',                 '~> 1.2.0'
  gem 'capybara',               '~> 2.4.4'
  gem 'mocha',                  '~> 1.1.0'
  gem 'launchy',                '~> 2.4.3'
  gem 'capybara_minitest_spec'
  gem 'database_cleaner',       '~> 1.4.0'
  gem 'quiet_assets'
  gem 'awesome_print',          require: "ap"
  gem 'vcr'
end

My output for some reason is doubling but it looks like it's just output doubling and not running twice. My View time loading is the same and so it appears that it's just a STDOUT double. What is going on?

Upvotes: 3

Views: 1413

Answers (1)

pablobm
pablobm

Reputation: 2066

Short answer

Restrict rails_12factor to production only:

gem "rails_12factor",           '~> 0.0.3', group: :production

Long answer

The command rails server sends your logs to stdout in addition to sending them to your logger. Therefore, if your logger writes to stdout, each entry will appear twice on the terminal.

The gem rails_12factor sends your logs to stdout. If you use it on development, and you use rails server to start your environment, then you get duplicate logs. See this comment (and its thread) for more info:

There's one final hitch though: I can still see duplicate SQL output when using the Rails console on production (not on the server logs though). This issue is still being discussed on the Rails issue tracker, and there seems to be no solution yet. See:

Upvotes: 7

Related Questions