Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4 log messages appear 2x #1

Closed
gkop opened this issue Jun 17, 2013 · 17 comments
Closed

Rails 4 log messages appear 2x #1

gkop opened this issue Jun 17, 2013 · 17 comments

Comments

@gkop
Copy link

gkop commented Jun 17, 2013

This is a brand new rails 4 rc2 app with the tweaks needed to run on heroku - https://github.com/gkop/heroku-rails-4-duplicate-logs .

Deploy to heroku, tail the logs, hit the / path, and you will see 2 log messages (404) -- http://pastie.org/8053185 .

Heroku staff - I have deployed the app for you - http://heroku-rails-4-duplicate-logs.herokuapp.com/

@hone
Copy link
Member

hone commented Jun 17, 2013

Thanks for filing this. This is because rails server sends logs to STDOUT as well as to the Rails.logger which is why you're seeing this twice. If you just use rackup on that sample app, you get the logs only once.

@gkop
Copy link
Author

gkop commented Jun 17, 2013

You're correct.

Procfile

web: rackup -p $PORT

Did the trick.

Thanks!

Note - I did reference https://devcenter.heroku.com/articles/rails4 but glossed over the bit on unicorn configuration, since I wasn't intending on using unicorn just yet. Perhaps add a note that regardless of server, you should either execute rackup or the server binary but not rails s or script rails/server or have a missing Procfile or a Procfile missing an explicit web process.

@heartpunk
Copy link

This drove me crazy for a few hours. Glad to finally find a solution.

@heartpunk
Copy link

Maybe the docs here/at rails_12factor should reflect this?

@heartpunk
Copy link

I'll happily update them and submit a PR if that's a desirable thing.

@schneems
Copy link
Contributor

Brainstorming here what could we do to fix this problem?

  • Make rails s only log to one source instead of two (this behavior is a bit confusing)
    • Not a bad option but need a stronger argument than just this issue for that change.
  • Detect what the top level command we're running in from this gem and don't run if it is rails server or rails s
    • this sounds very brittle and not very fun
  • Check the sinks that the logger is logging to and if one of them is already STDOUT, don't execute our code
    • Wouldn't mind doing this, but I don't think it's possible given the current implementation of Logger

@hone
Copy link
Member

hone commented Oct 8, 2013

@schneems didn't you fix this in Rails 4.1?

@schneems
Copy link
Contributor

schneems commented Oct 8, 2013

rails/rails#11060 was merged in and fixes this issue. There is nothing we can do for 4.0 closing this issue seems good.

@schneems schneems closed this as completed Oct 8, 2013
@davidpelaez
Copy link

I still have this issue, and this is the most relevant result in Google. So for anyone having the problem, this is something I used in application.rb

        if Rails.env.development?
            # Don't log to STDOUT, by default rails s will handle it
            config.logger = Logger.new('/dev/null')
        else
            # Don't log to file, sending everything to unicorn file.
            config.logger = Logger.new(STDOUT)
        end

It'll probably help someone out there.

@schneems
Copy link
Contributor

You can use Rails.env.development? instead of the double equals. Also make sure you remove that code when you rev to 4.1 otherwise you'll stop seeing logs in development.

@davidpelaez
Copy link

I updated the comment. Thanks for the note on 4.1 since having it posted here will sure avoid lots of future headaches. So this is all fixed in 4.1 -currently in beta-, right?

@schneems
Copy link
Contributor

it should be, if it's not open an issue on rails/rails and ping me via
@schneems

On Mon, Dec 30, 2013 at 1:23 PM, David Pelaez notifications@github.comwrote:

I updated the comment. Thanks for the note on 4.1 since having it posted
here will sure avoid lots of future headaches. So this is all fixed in 4.1
-currently in beta-, right?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-31359784
.

@styledev
Copy link

styledev commented Oct 4, 2014

Moving the rails_12factor gem to the production group fixed the double entries for me.
http://stackoverflow.com/questions/19900093/rails-logger-appears-to-be-duplicating-log-lines

@seanahrens
Copy link

For anyone who stumbles upon this issue from google, make sure that what's actually happening to you is not that your app is actually making duplicate REQUESTS as mine was. See http://stackoverflow.com/questions/3266020/rails-app-logging-duplicate-requests/28299100#28299100

@joallard
Copy link

Got this on 4.2, adding group: :production

@raldred
Copy link

raldred commented Aug 30, 2015

Same, looks like this issue is back in 4.2.
Brand new 4.2.4 app today and I have double logging.

@schneems
Copy link
Contributor

Open a new issue and give me an example app that reproduces the problem please

@heroku heroku locked and limited conversation to collaborators Aug 30, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants