-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Bridge/Monolog] Enhance the Console Handler #21705
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
3ae3f06
to
4103b61
Compare
} | ||
if (isset($args[1])) { | ||
$options['date_format'] = $args[1]; | ||
} |
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.
What about the two last arguments?
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.
They are not relevant anymore. So I don't need to "map" them.
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.
shouldn't $allowInlineLineBreaks
map to multiline
?
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.
Indeed. I will fix it in the next pr. Thanks.
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.
So you intentionally removed the option to suppress emtpy context and extra data?
Update: Just saw that this was mentioned in #21705 (comment) as well.
{ | ||
parent::__construct($format, $dateFormat, $allowInlineLineBreaks, $ignoreEmptyContextAndExtra); | ||
// BC Layer |
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.
You might want to document what the signature you're emulating here looks like
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.
Sure ;) And I have to add a trigger_error too. I just wait some feedback before.
'multiline' => false, | ||
), $options); | ||
|
||
$this->cloner = new VarCloner(); |
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.
No DI here or line 83?
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.
No indeed. IMHO it's useless and there are other part of the framework where the dumper / cloner is hard-coded like that.
About the line 83, I cannot anyway as I do need a CLIDumper and well configured.
4103b61
to
5fe4af5
Compare
5fe4af5
to
6823479
Compare
*/ | ||
public function __construct($options = array()) | ||
{ | ||
// BC Layer, old constructor: |
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.
What I meant by "documenting what it looks like" was more sth like :
// BC layer for this signature : __construct($format = null, $dateFormat = null)
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.
Actually, it's "documented" just bellow in the trigger error message.
For the record, I added what you asked for, then I added the deprecation, then I removed because it was a kind of duplicate. and now I notice I forgot to remove , old constructor:
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.
Alright!
{ | ||
// BC Layer, old constructor: | ||
if (!is_array($options)) { | ||
@trigger_error(sprintf('The constructor arguments $format, $dateFormat, $allowInlineLineBreaks, $ignoreEmptyContextAndExtra of %s are deprecated and will be removed in 4.0. Use $options insteand.', self::class), E_USER_DEPRECATED); |
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.
insteand => instead
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.
Thanks. Fixed.
6823479
to
2f01f9f
Compare
In your commit message : - Basically, The formatter now use the VarDumper & use more significant…
+ Basically, the formatter now uses the VarDumper & uses more significant… |
b516ef7
to
1ba3fcd
Compare
1ba3fcd
to
7a2de64
Compare
Looks like the This PR is now ready for the review ;) |
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.
👍
{ | ||
// BC Layer | ||
if (!is_array($options)) { | ||
@trigger_error(sprintf('The constructor arguments $format, $dateFormat, $allowInlineLineBreaks, $ignoreEmptyContextAndExtra of %s are deprecated and will be removed in 4.0. Use $options instead.', self::class), E_USER_DEPRECATED); |
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.
Missing quotes around %s
(should be "%s"
)
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.
are deprecated since 3.3
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.
Thanks; fixed.
), $options); | ||
|
||
if (!class_exists(VarCloner::class)) { | ||
throw new \RuntimeException('To use the ConsoleFormatter you must install the symfony/var-dumper component.'); |
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.
This could be moved to the top, right?
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.
Thanks. Fixed.
7a2de64
to
df24afc
Compare
Quick question: would it be possible to fallback to the old way when vardumper is not installed? |
It's not really easy (but not impossible) since the We can create two Another solution is to extends again the LineFormatter. What is the best option to you? |
const SIMPLE_DATE = 'H:i:s'; | ||
|
||
private static $levelColorMap = array( | ||
100 => 'fg=white', |
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.
what's about using monolog's (or PSR) constants?
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.
- because the map will not be aligned ;) just kidding !
- PSR contant with int level does not exist
I updated the PR to use Monolog\Logger::CONSTANT
df24afc
to
5fa5041
Compare
@lyrixx, I think we still need to support the case where |
5fa5041
to
4487f99
Compare
I pushed a new version: Now if the var-dumper component is not installed, the context and the extra are not dumped at all. I chose to do that in order to keep the code as simple as possible. I could also extends the NormalizeFormatter, but there is lot of code in the LineFormatter. So I don't think it worth it. |
private $dumper; | ||
|
||
/** | ||
* {@inheritdoc} |
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.
This should be removed as you don't extend anything anymore. Also, the phpdoc should document the available option keys.
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.
Thanks. I updated the PHP Doc.
a11d586
to
69ec738
Compare
Last thing, can you add a note in the CHANGELOG? |
Basically, the formatter now uses the VarDumper & uses more significant colors and has a more compact / readable format (IMHO).
69ec738
to
b663ab5
Compare
Done ;) |
Thank you @lyrixx. |
This PR was merged into the 3.3-dev branch. Discussion ---------- [Bridge/Monolog] Enhance the Console Handler | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | - | Fixed tickets | - | License | MIT | Doc PR | - --- I extracted and enhanced the formatting logic from #21080. Basically, The formatter now use the VarDumper & use more significant colors and has a more compact / readable format (IMHO). --- I used the following code to generate before/after screenshots. ```php protected function execute(InputInterface $input, OutputInterface $output) { $logger = $this->getContainer()->get('logger'); $filesystem = $this->getContainer()->get('filesystem'); $anObject = new \stdClass; $anObject->firstPpt = 'foo'; $anObject->secondePpt = 'bar'; $logger->log('notice', 'Hello {who}', [ 'who' => 'Wold', 'an_object' => $anObject, 'file_system' => $filesystem, ]); $r = new \ReflectionClass(LogLevel::class); foreach ($r->getConstants() as $level) { $logger = $logger->withName($level); $logger->log($level, 'log at level {level}', [ 'level' => $level, ]); } } ``` before:  After:  Commits ------- b663ab5 [Bridge/Monolog] Enhanced the Console Handler
Related to symfony/symfony#21705 Note: It's not an issue to let monolog doing it, but if monolog do it symfony can not do it. The best experience is when symfony do it. So let's disable it.
…symfony. (lyrixx) This PR was merged into the 3.3-dev branch. Discussion ---------- Do not process psr_3 log messages, as it's now done by symfony. Related to symfony/symfony#21705 Note: It's not an issue to let monolog doing it, but if monolog do it symfony can not do it. The best experience is when symfony do it. So let's disable it. Commits ------- ebe2bad Do not process psr_3 log messages, as it's now done by symfony.
This seems to be a memory hog. At least I was greeted with the php terminating script due to memory exhaustion (128M) instead of getting the stack dump. I have run the command with time to see the top memory consumption and it was around 150M-160M. Running same command with 3.2, the memory used is around 50M |
@mvrhov Thanks for reporting this, but could you open a new issue and ping me to keep a trace of this issue? |
Does this PR basically revert #11496? I don't see why. |
…xt and extra data (mpdude) This PR was squashed before being merged into the 3.4 branch (closes #28471). Discussion ---------- [MonologBridge] Re-add option option to ignore empty context and extra data | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | In #11496, an option was added to `ConsoleFormatter` to ignore empty context and extra data. This setting was even turned on by default. The `ConsoleHandler` was then overhauled in #21705. During this change, the option got lost. Commits ------- d1e7438 [MonologBridge] Re-add option option to ignore empty context and extra data
I extracted and enhanced the formatting logic from #21080.
Basically, The formatter now use the VarDumper & use more significant colors and has a more compact / readable format (IMHO).
I used the following code to generate before/after screenshots.
before:
After: