Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] LogTailer ignores config.log_path

#2350

In railties/lib/rails/rack/log_tailer.rb:4:

EnvironmentLog = "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log"

This fails when you customize the log path using the initializer, since this file will not exist.

(Will submit a patch.)

Reported by Phil Hagelberg · March 26th, 2009 @ 06:06 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Phil Hagelberg
    Phil Hagelberg

    Unfortunately I couldn't manually test the full-stack since the rake gem task fails on my machine, but the attached patch should do the trick.

    This will make it easier to distribute Rails apps as gems.

    March 26th, 2009 @ 07:03 PM

  2. Phil Hagelberg
    Phil Hagelberg
    • Title changed from LogTailer ignores config.log_path to [PATCH] LogTailer ignores config.log_path

    March 26th, 2009 @ 08:24 PM

  3. Jeff Hodges
    Jeff Hodges

    Tossed this around and I can't find a problem with it. The github repo is flipping out on a credits.erb file when generating the guides, but I disabled that and created a sample rails app, etc. Looks good to me.

    March 28th, 2009 @ 03:58 PM

  4. Jeff Hodges
  5. Phil Hagelberg
    Phil Hagelberg
    • Tag changed from initializer, logging, rack to initializer, logging, patch, rack

    March 31st, 2009 @ 02:22 AM

  6. felipekaufmann
    felipekaufmann

    Also breaks when using SyslogLogger and no log file is found in RAILSROOT/log. (Of course, rails creates the empty logfiles when the app is generated, but I didn't want them in my repository...)

    April 8th, 2009 @ 09:08 AM

  7. Phil Hagelberg
    Phil Hagelberg

    Felipe: can you elaborate? Does rails break with SyslogLogger in its current state, or after this patch is applied?

    April 22nd, 2009 @ 05:01 AM

  8. felipekaufmann
    felipekaufmann

    Phil: Sorry for the long silence. As it turns out, my issue persists with or without patch. However, I don't know if the error lies in rails or SyslogLogger:

    • rails 2.1.0 application, configured with SyslogLogger as RAILS_DEFAULT_LOGGER, starts up fine even if .log does not exist.

    • rails 2.3.2 application, configured with SyslogLogger as RAILS_DEFAULT_LOGGER does not start up if .log is mssing, fails with:

    rails-2.3.2/lib/rails/rack/log_tailer.rb:10:in size': No such file or directory - <path_to_approot>/log/production.log (Errno::ENOENT)

    Oddly enough, if I remove the SyslogLogger configuration from the production.rb environment config, the missing logfile is created during the boot up. With SyslogLogger, the file is not created and log_tailer complains about its absence. Not critical though, since just touching the missing file will work fine. Just not pretty ;-)

    Maybe I should file this somewhere else?

    May 1st, 2009 @ 10:39 AM

  9. Roland Moriz
    Roland Moriz

    I think this issue is bogus.
    It looks to me that rspec-rails, when required, automatically sets the RAILS_ENV to 'test' which also changes the logfile name in the LogTailer.

    Fix:

    do NOT load your test-framework gems in 'development' and 'production' environments.

    April 7th, 2010 @ 09:06 PM

  10. Roland Moriz
    Roland Moriz

    whoops. desregard my last posting. i was certifiably insane then...

    April 7th, 2010 @ 09:11 PM

  11. PizzaMan
    PizzaMan

    I found this because I'm having the same problem. FYI, the patch doesn't fix the problem when using any logger other than the default logger and either 1) you use a non-standard file name and you don't set config.log_file or 2) there is no file (remote logging). Normally when using an external logger you often don't set config.log_path so the patch doesn't get the new filename or if you are using a remote logger there is no filename for LogTailer to open.

    This goes away if you run the server detached as LogTailer is bypassed then. However, I prefer to run it normally (not detached) and redirect stdout/stderr to a log file (you sometimes get useful debugging info from it).

    It would be nice if there was another way to turn off the LogTailer but I haven't found one I like yet (I generally don't like patching due to work required to maintain the patch when you upgrade versions). Maybe it would be better if LogTailer looked for the file and if the file wasn't found then LogTailer does nothing (let the server continue without it)? Maybe output a message to let the user know. Or maybe disable if there is an external logger defined (and config.log_path isn't set?).

    April 14th, 2010 @ 06:40 AM

  12. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  13. Luke Chadwick
    Luke Chadwick
    • Tag changed from initializer, logging, patch, rack to initializer, logging, rack
    • Assigned user set to Ryan Bigg

    I'm interested in patching this, but I'd like someone to double check my suggested solution. I've come up with some cases to discuss:

    Case 1:
       config.log_path = "../../var/log/audit.log"
       config.logger = Logger.new(config.log_path, 10, 1048576)
    

    This would actually be handled by the patch above (as far as I can tell)

    Case 2:
       config.logger = Logger.new("../../var/log/audit.log", 10, 1048576)
    

    This would NOT be handled by the patch above (since config.log_path is never set)

    Case 3:
       config.logger = SyslogLogger.new('target')
    

    Also not handled.


    Suggested Solution

    • Make Logger default to having an instance method 'log_path'
    • Make LogTailer look at Rails.logger.log_path, added above, to get the path if it exists
    • Make LogTailer fail gracefully if it doesn't exist/returns nil.

    Can we pass this ticket to someone to make a decision on whether this is an acceptable solution?

    As soon as I get a nod I'll sit down and write a patch.

    June 2nd, 2010 @ 02:02 AM

  14. Luke Chadwick
    Luke Chadwick
    • Assigned user cleared.
    • Importance changed from to

    October 12th, 2010 @ 10:10 AM

  15. Aaron Patterson
    Aaron Patterson

    You could set a custom formatter on the log object. This may not work for SyslogLogger because I don't think it conforms with the built in Logger interface.

    Here is an example:

    require 'logger'
    
    class FormatterProxy < Struct.new(:formatter)
      def call *args
        msg = formatter.call(*args)
        puts "HI!!! #{msg}"
        msg
      end
    end
    
    logger = Logger.new $stdout
    logger.add(Logger::DEBUG, "before override\n")
    logger.formatter = FormatterProxy.new(
      logger.formatter || Logger::Formatter.new
    )
    logger.add(Logger::DEBUG, "after override\n")
    

    October 15th, 2010 @ 11:12 PM

  16. Ryan Bigg
    Ryan Bigg
    • Tag changed from sheepskin boots, initializer, logging, rack to initializer logging rack

    Automatic cleanup of spam.

    October 16th, 2010 @ 02:22 AM

  17. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:35 AM

  18. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:47 PM

  19. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:47 PM

  20. Peter Abrahamsen
    Peter Abrahamsen

    Umm, bump. This is a really obvious and fatal bug. I'm monkey-patching to get by for now.

    April 12th, 2011 @ 11:06 PM