-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add options to monolog console handler and formatter #23929
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
Add options to monolog console handler and formatter #23929
Conversation
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.
Welcome! Could you please explain your use case for this feature?
@@ -78,6 +78,7 @@ public function __construct($options = array()) | |||
'date_format' => self::SIMPLE_DATE, | |||
'colors' => true, | |||
'multiline' => false, | |||
'ignoreEmptyContextAndExtra' => false, |
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.
using camel case seems inconsistent
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.
wow I didn't even notice :) I will fix that
@chalasr hey! I tried to log some stuff in the console commands with PSR compatible logger, something like this:
and I expected to see this in console:
but I got output like that one:
which doesn't seem nice or usefull to me at all. I didn't find any other way to fix this than by writing my custom Handler and Formatter. EDIT: forgot to mention that I plan to submit another patch to allow unsetting context values that are used as placeholders. This PR actually solves half of the problem where this:
becomes this:
That is something that I still don't like and think is not useful :) Or at least that it deserves an option to be turned off :) EDIT 2: I added the "missing" patch which enables what I described above. I hope that now you understand what I wanted to achieve :) |
I added another commit which enables you to optionally remove context fields that are used as placeholders. All these changes combined make the log messages look much cleaner and without unnecessary variable dumps. If you want to split changes somehow or change something, please let me know. Thanks! |
@nicolas-grekas I'm sorry, but I fail to see the relevance here. It appears to me that the #24300 only adds a minimal PSR-3 logger implementation if there is none present. This PR addresses missing configuration options when using Monolog, which is a PSR-3 logger, ergo #24300 doesn't apply. Am I missing something? |
The relevance is that adding options increases the complexity for users, so if we can find a way that is not configurable but works great for everyone, that's better IMHO. #24300 uses a very simple format, that contains no json context, so maybe that was enough for you. If yes, then better not plan for what others could maybe (not) need :) |
Yeah, of course, I understand that adding unnecessary complexity is a bad thing to do :) I went through both PRs 3 times now, and I understand your motivation not to increase complexity, but I still not see how is #24300 relevant to this PR. I don't think that it can solve my use case. I want to use Monolog and the context variables; I just don't want them to clutter the output. #24300 is irrelevant for anyone using Monolog (or at least it looks like that to me - please correct me if I'm wrong, I'm not a Symfony nor Monolog expert by a longshot). |
Moving to 4.1. Rebase on master might be needed, where PHP 7.1 features can be used btw. |
$record = $this->replacePlaceHolder($record); | ||
|
||
$levelColor = self::$levelColorMap[$record['level']]; | ||
$context = $extra = ''; | ||
if (!empty($record['context']) || !$this->options['ignore_empty_context_and_extra']) { |
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.
we should not ignore an empty context if extras are not empty. Otherwise, you won't be able to know it is the extras (it will look like as if it is the context being dumped)
Hello, I think this issue is solved thanks to #30345 and symfony/monolog-bundle#297 @grongor Could you confirm it's OK? |
@lyrixx Hi, only partially ... possibility to configure formatter options is great and appreciated but I still miss the options which I wanted to introduce in this PR. But if you don't want them in the upstream then that's ok, I'm using my "clone" anyway... |
I think using a custom formatter for this case makes more sense. This PR has been stalled for a long time. I suggest to close it. |
TODO:
PS: this is my first contribution here, please be gentle :)