Add Logging engine Log::Any and add support for context logging#1761
Add Logging engine Log::Any and add support for context logging#1761mikkoi wants to merge 1 commit intoPerlDancer:mainfrom
Conversation
|
Is there a particular benefit to putting this in core instead of a plugin on CPAN? |
No. I actually considered that: building the whole thing as a plugin. That would mean creating a new set of keywords and a lot of duplicate code. I am okay with that. However, I also wanted to raise the point that Dancer2's logging has shortcomings. It is not possible as it is to do what I need. I think we should consider Log::Any's example. A true overhaul is not possible, though, because that would mean incompatible changes to the API. |
Good to raise this point. Is there anything you would suggest to improve specifically? Maybe this could lead to a core improvement, regardless of this being merged into core or not. ("Doing this in core is very difficult because of how core is" is a fair reason to suggest doing this in core, but it also raises the question of what we can do better in it.) |
|
You can accomplish this already with Log::Any. In your app config: And then in your Dancer2 app: Am I missing something? Recommend we close this. I could do a PR to add this to the cookbook. What do y'all think? |
|
Yes, makes sense to me. |
This doesn't work for me. It does not support structured logging. info 'Create user', { user => 'Mikko', request_id => 123, trx_active => 1, };And then the output would be: {"level":"info","category":"MyApp:Web","message":"Create user","user":"Mikko","request_id":123,"trx_active":1,"file":"/[..]/lib/MyApp/Web.pm","line":234}Additionally, to emulate Log::Any we could have command "log_context" to create "base" context for all logging done within the scope: {
logging_context { request_id => 123, };
info 'Create user', { user => 'Mikko', trx_active => 1, };
} |
It does; if you build a new skeleton app, make sure to disable the console logger in That being said, I find |
It does close but not quite. I get this: When I want: The problem is the {'baz' => 'bah','foo' => 'bar'} which would need to be processed separately. It also doesn't handle a message and structure:
We can add all sorts of additional info there which a logviewer can index. |
|
I see two different things happening in this PR:
Would you please submit this as two separate PRs? The core logging improvements I would 👍 in a hot minute. The other requires some discussion:
If we merge this, I'd need to see some more docs on how to configure this adapter with multiple Log::Any adapters. I am always happy to see PRs from you @mikkoi :) Look forward to working through this with you. |
|
Some thoughts: I am in favor of adding support for structured logging to the core. However, I think it's not needed to duplicate my plugin. And, I would want the support to provide more options than simple Log::Any structured logging, i.e. arbitrary data structures -- not just a hashref -- as supported e.g. by Log::Any::JSON (which also provides millisecond timestamp resolution). This would require making _serialize more complex., though. |
|
Thanks, @cromedome This is quite radical proposal, but how about if we changed Dancer2's own logging system to Log::Any? |
I don't have an immediate answer, and need to dwell on that for a bit. There's a lot to think over there, and I am not sure the gains are worth the effort. I think Log::Any is overkill for a lot of our users. Other core team members might have another view they'd like to share. |
|
@mikkoi in the interim, I'd love a new/updated PR with the non-Log::Any part of this. |
I use Log::Any extensively for $work projects; yet I'm not keen on using it for the default logger. For our apps, we want consitent logging calls everywhere, which is why we chose Log::Any. That implies using |
|
SLIGHTLY OT ...
Hi @veryrusty |
I think I said we wanted consistency. Sure, the keywords work. But consistently using |
Log::Any has a new feature: Logging structed data. Essentially it means that you can add a hash after or in place of the logging message.
This can be really convenient if you simultaneously write the information into logs as JSON and pump the JSON into a logviewer where you can search or categorise by any JSON element.
This PR adds a logger engine for Log::Any and changes Dancer2::Core::Role::Logger to support the action.