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

Fix for log tailer when the log file doesn't exist. #4528

Merged
merged 1 commit into from
Jan 20, 2012

Conversation

j-manu
Copy link
Contributor

@j-manu j-manu commented Jan 18, 2012

If the log file doesn't exist, log tailer errors out and takes down the server with it. Currently this does not happen because even if the log directory doesn't exist, https://github.com/rails/rails/blob/master/railties/lib/rails/application/bootstrap.rb#L27 creates it and the log file will be created.


@file = ::File.open(path, 'r')
if File.exists?(path)
@cursor = ::File.size(path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should initialize the variables regardless, probably setting it to nil.

@j-manu
Copy link
Contributor Author

j-manu commented Jan 18, 2012

Ok. Will issue a new PR with the changes

@j-manu
Copy link
Contributor Author

j-manu commented Jan 18, 2012

A question: Is :: needed here (for File) or is it just best practice to use it ? On line 7 there is no :: for
File.expand_path(Rails.root). If needed, I will change the commit

@j-manu
Copy link
Contributor Author

j-manu commented Jan 19, 2012

@tenderlove is this OK now?

tenderlove added a commit that referenced this pull request Jan 20, 2012
Fix for log tailer when the log file doesn't exist.
@tenderlove tenderlove merged commit de41f5a into rails:master Jan 20, 2012
if ::File.exists?(path)
@cursor = ::File.size(path)
@file = ::File.open(path, 'r')
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y U NO USE an else there to assign cursor and file to nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brevity :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who needs readability?

@file, @cursor = ::File.exists?(path) ? [::File.open(path, 'r'), ::File.size(path)] : nil

@swrobel
Copy link
Contributor

swrobel commented Apr 9, 2012

This needs to be merged into 3-2-stable

> rm log/development.log
> rails s
=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
/gems/railties-3.2.3/lib/rails/rack/log_tailer.rb:8:in `size': No such file or directory - log/development.log (Errno::ENOENT)

@swrobel
Copy link
Contributor

swrobel commented Apr 11, 2012

@tenderlove please merge into 3-2-stable

tenderlove added a commit that referenced this pull request Apr 27, 2012
Fix for log tailer when the log file doesn't exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants