-
Notifications
You must be signed in to change notification settings - Fork 631
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
Allow easier Monolog config #14974
base: 4.x
Are you sure you want to change the base?
Allow easier Monolog config #14974
Conversation
src/log/MonologTarget.php
Outdated
} | ||
$handlers = $this->handlers instanceof Closure | ||
? ($this->handlers)($this) | ||
: $this->handlers; |
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.
If $this->handlers
is an array, we take it as-is.
This makes the most intuitive sense to me, however, it isn't how \craft\log\Dispatcher::$targets
works, where they are appended to the defaults. Happy to change it either way.
418b7f2
to
87b6e5f
Compare
src/log/MonologTarget.php
Outdated
|
||
return $handlers; | ||
} | ||
|
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.
getDefaultHandlers
is not static because it needs access to $this->formatter
and $this->name
.
Its intended use is to be referenced in handlers
when a Closure is used (when you want to append a handler to the defaults).
{ | ||
return $this->name; | ||
} | ||
|
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.
Adds getters for all these so they can be used in the Logger closure
Description
The most common scenario is to want to add a Monolog handler for a third party service. This is an attempt to make that a bit easier.
As it is,
MonologTarget
is very much geared toward Craft's use of it and is a bit difficult to extend. One could always just add a target usingsamdark\log\PsrTarget
, (whichMonologTarget
extends), but you miss out on the default formatting and processors that Craft applies.This PR allows
MonologTarget
to be constructed with a Closure for thelogger
property, allowing you to override anything.Example: Add a custom log target with your own Monolog handlers and Craft's default formatting
Before:
After:
…or, push a handler onto Craft's default log targets: