This project is archived and is in readonly mode.

#2350 ✓stale
Phil Hagelberg

[PATCH] LogTailer ignores config.log_path

Reported by Phil Hagelberg | March 26th, 2009 @ 06:06 PM | in 3.x

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.)

Comments and changes to this ticket

  • Phil Hagelberg

    Phil Hagelberg March 26th, 2009 @ 07:03 PM

    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.

  • Phil Hagelberg

    Phil Hagelberg March 26th, 2009 @ 08:24 PM

    • Title changed from “LogTailer ignores config.log_path” to “[PATCH] LogTailer ignores config.log_path”
  • Jeff Hodges

    Jeff Hodges March 28th, 2009 @ 03:58 PM

    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.

  • Jeff Hodges
  • Phil Hagelberg

    Phil Hagelberg March 31st, 2009 @ 02:22 AM

    • Tag changed from initializer, logging, rack to initializer, logging, patch, rack
  • felipekaufmann

    felipekaufmann April 8th, 2009 @ 09:08 AM

    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...)

  • Phil Hagelberg

    Phil Hagelberg April 22nd, 2009 @ 05:01 AM

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

  • felipekaufmann

    felipekaufmann May 1st, 2009 @ 10:39 AM

    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?

  • Roland Moriz

    Roland Moriz April 7th, 2010 @ 09:06 PM

    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.

  • Roland Moriz

    Roland Moriz April 7th, 2010 @ 09:11 PM

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

  • PizzaMan

    PizzaMan April 14th, 2010 @ 06:40 AM

    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?).

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Luke Chadwick

    Luke Chadwick June 2nd, 2010 @ 02:02 AM

    • 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.

  • Luke Chadwick

    Luke Chadwick October 12th, 2010 @ 10:10 AM

    • Assigned user cleared.
    • Importance changed from “” to “”
  • Aaron Patterson

    Aaron Patterson October 15th, 2010 @ 11:12 PM

    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")
    
  • Ryan Bigg

    Ryan Bigg October 16th, 2010 @ 02:22 AM

    • Tag changed from sheepskin boots, initializer, logging, rack to initializer logging rack

    Automatic cleanup of spam.

  • Ryan Bigg

    Ryan Bigg October 19th, 2010 @ 08:35 AM

    • Tag cleared.

    Automatic cleanup of spam.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:47 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:47 PM

    • State changed from “open” to “stale”
  • Peter Abrahamsen

    Peter Abrahamsen April 12th, 2011 @ 11:06 PM

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

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages