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

Put some space for non-assets requests in development mode #23443

Merged

Conversation

prathamesh-sonpatki
Copy link
Member

r? @dhh

Here is the sample output on an app created from rails master with this change - https://gist.github.com/prathamesh-sonpatki/ca9dbc32bcbae9066562

EDIT: Updated gist with Kasper's suggestion of printing a line before starting assets request - https://gist.github.com/prathamesh-sonpatki/c9075f78ac6f1f372c7c

@kaspth
Copy link
Contributor

kaspth commented Feb 3, 2016

Shouldn't one space be enough? Having two lines between requests feels airy to me 😄

Can we make it so that there's a line just above the first asset request? Basically add a newline after: https://gist.github.com/prathamesh-sonpatki/ca9dbc32bcbae9066562#file-gistfile1-txt-L31

@prathamesh-sonpatki
Copy link
Member Author

@kaspth
Copy link
Contributor

kaspth commented Feb 3, 2016

Almost! These should just be one line, IMO: https://gist.github.com/prathamesh-sonpatki/c9075f78ac6f1f372c7c#file-gistfile1-txt-L16-L17 😁

# Put some space between for non-assets requests in development logs.
if development? && request.path !~ /^\/assets/
logger.debug ''
logger.debug ''

Choose a reason for hiding this comment

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

why? logger.debug ''

Copy link
Contributor

Choose a reason for hiding this comment

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

# Put some space between for non-assets requests in development logs. 😁

@prathamesh-sonpatki
Copy link
Member Author

@kaspth For that we will need to know previous request path and based on that make a decision whether to show the line or not. I guess it will be more complicated.

@kaspth
Copy link
Contributor

kaspth commented Feb 3, 2016

@prathamesh-sonpatki do we? Isn't outputting a space after every non asset request enough to get the result?

@prathamesh-sonpatki
Copy link
Member Author

@kaspth That will work for non-asset request and asset request sequence but will not work for asset-request and non-asset request sequence.

For eg.

Started GET "/assets/application.self-b89234cf2659d7fedea75bca0b8d231ad7dfc2f3f57fcbaf5f44ed9dc384137b.js?body=1" for 127.0.0.1 at 2016-02-03 14:00:33 +0530
Started GET "/posts/new" for 127.0.0.1 at 2016-02-03 14:00:41 +0530
Processing by PostsController#new as HTML
  Rendered posts/_form.html.erb (11.2ms)
  Rendered posts/new.html.erb within layouts/application (13.5ms)
Completed 200 OK in 50ms (Views: 42.4ms | ActiveRecord: 3.2ms) (Views: 42.4ms | ActiveRecord: 3.2ms)

@prathamesh-sonpatki
Copy link
Member Author

I think definitely we should keep Puma to multi threads but let's only send the line clears together with the line for completing a Rails request (the line reporting status code and timing). Don't want to send it together with assets etc.

I also tried this suggestion from DHH in #23428. With this approach we will get same result as in https://gist.github.com/prathamesh-sonpatki/ca9dbc32bcbae9066562. There will be no extra line before assets request as present here - https://gist.github.com/prathamesh-sonpatki/c9075f78ac6f1f372c7c

@@ -79,6 +82,12 @@ def development?
def logger
Rails.logger
end

def show_extra_line_in_development_for_non_assets_requests(path)
if development? && path !~ /^\/assets/
Copy link
Member

Choose a reason for hiding this comment

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

Does this work safely to handle public assets, assets from engines, vendored assets, etc?

btw, this won't work with http://guides.rubyonrails.org/asset_pipeline.html#changing-the-assets-path

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! It works with vendored assets but won't work with changing assets path.

@prathamesh-sonpatki
Copy link
Member Author

I used DHH's original suggestion, it does not print a new line after all assets requests end but covers all other cases.

@@ -26,6 +26,9 @@ def process_action(event)
end
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms"
message << " (#{additions.join(" | ".freeze)})" unless additions.blank?
message << " (#{additions.join(" | ".freeze)})" unless additions.blank?
Copy link
Member

Choose a reason for hiding this comment

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

Don't think we need this 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed 😄

@kaspth
Copy link
Contributor

kaspth commented Feb 3, 2016

:shipit:

1 similar comment
@schneems
Copy link
Member

schneems commented Feb 3, 2016

:shipit:

matthewd added a commit that referenced this pull request Feb 3, 2016
…elopment

Put some space for non-assets requests in development mode
@matthewd matthewd merged commit 8a84f1c into rails:master Feb 3, 2016
@prathamesh-sonpatki prathamesh-sonpatki deleted the fix-logging-in-development branch February 3, 2016 15:55
@@ -26,6 +26,8 @@ def process_action(event)
end
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms"
message << " (#{additions.join(" | ".freeze)})" unless additions.blank?
message << "\n\n" if Rails.env.development?
Copy link
Member

Choose a reason for hiding this comment

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

This is coupling Action Pack with Railties we should check if Rails.env is defined before calling it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants