-
-
Notifications
You must be signed in to change notification settings - Fork 194
Embrace Crystal standard Log for logging. #705
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
Conversation
Kemal uses a LogHandler to log requests, this code predates the Crystal Log class so while the Kemal documentation says that logging is done using Log class, the http request log is done in a different way. This patch deprecates: - Kemal::Config#logger - Kemal::Config#logger=(Kemal::BaseLogHandler) - log(String) - Kemal::LogHandler.initialize(IO) - NullLogHandler and changes: - Add Kemal::Log (Log = ::Log.for(self)) - Kemal::LogHandler now uses Log. - No handler is created if logging is set to false. Old code using custom log handlers must work as before.
0c937cc
to
1b57c2f
Compare
1b57c2f
to
8a365e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks a lot @hugopl 👍
We've been using a custom class which Log.info do
JSON.build do |json|
json.object do
json.field "method", context.request.method
...
end
end
end Is there a recommended way to do something like this now that |
You can create a normal http handler and insert it on Kemal. Other day I was thinking about a way of ease this process by letting the user pass a proc to be used by the RequestLogHandler Log.info call. Maybe I will create a patch and request for comments. |
@hugopl Thanks -- I just made my custom logger a subclass of
Good enough. Works for me 👍 |
Description of the Change
Kemal uses a LogHandler to log requests, this code predates the Crystal Log class so while the Kemal documentation says that logging is done using Log class, the http request log is done in a different way.
This patch deprecates:
Kemal::LogHandler.initialize(IO)and changes:
Kemal::LogHandler now uses Log.Old code using custom log handlers must work as before.
Alternate Designs
Change nothing and follow with life.
Benefits
Unified log interface using the standard library Log facilities.
Possible Drawbacks
If there's some code usingLogHandler.new(io)
the log wont be written toio
, maybe I could keepLogHandler
untouched, just deprecated, and create a newRequestLogHandler
.