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

adding an option to format log message to be one line #16

Merged
merged 2 commits into from
Mar 7, 2019

Conversation

mmclead
Copy link

@mmclead mmclead commented Apr 13, 2017

I'm using this to make searching logs easier. When filtering on a keyword the current multi-line log format makes it more difficult to get to all the information that is being logged.

This will add a configuration to the logger to format all the same information into one log line before processing the request and after processing the request.

@ridiculous
Copy link
Owner

This looks pretty sweet! I'm all for it! How about changing the option name though? What do you think about :condensed or :concise? Thanks

@mmclead
Copy link
Author

mmclead commented May 6, 2017

Sure. I like :condensed I'll get that up sometime soon.

@mmclead
Copy link
Author

mmclead commented Jun 2, 2017

@ridiculous I refactored how the logger is being called here. The idea was to isolate the logic that the :condensed option needs to one place.

Let me know if that works for you. My initial concern about it is the speed of doing the compact, delete_if, strip! and join on every log statement.

I could also do

logger.info(
        log_statements.inject([]) do |condensed_statement, log_statement|
          next condensed_statement if log_statement.nil? || log_statement.empty?
          condensed_statement << log_statement.strip
        end.join(" - ")
      )

so it only iterates 2 times instead of 4 times

@@ -64,8 +69,12 @@ def call!(env)
end

def after(status)
logger.info "Completed #{status} in #{((Time.now - start_time) * 1000).round(2)}ms"
logger.info ''
log_info(
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer to keep this as 2 statements, instead of creating a new array object for it

Copy link
Owner

Choose a reason for hiding this comment

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

Sry, I misread this, didn't see it was a new method log_info

Copy link
Owner

@ridiculous ridiculous left a comment

Choose a reason for hiding this comment

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

I like the direction this is going. If we really want to make this fast, efficient and organized, we may want to add this as an optional plugin or file that's loaded at boot time, instead of checking at runtime if it's "condensed." What do you think about that? I'm thinking we could mount a different class?

mount Grape::Middleware::CondensedLogger

@ridiculous
Copy link
Owner

Any thoughts on my proposal, @mmclead?

@mmclead
Copy link
Author

mmclead commented Jul 24, 2017

The proposal sounds great. I just haven't had the time to put in the work. Its on my radar though, and hopefully will get to it soon. (product launch at work is in the next couple weeks)

@skandragon
Copy link

I'd love to have this option. :)

@pbstriker38
Copy link

@mmclead @ridiculous
Any progress on this feature?

Copy link
Owner

@ridiculous ridiculous left a comment

Choose a reason for hiding this comment

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

Sorry for dropping the ball here. But this looks good! Let's do it! PS I should just give you commit access

@ridiculous ridiculous merged commit 3e64a80 into ridiculous:master Mar 7, 2019
@ridiculous
Copy link
Owner

released in v1.11.0

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.

4 participants