[9.x] Add verbosity level checking to console alerts #44614
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First of all, let me point out some inconsistencies.
Many logging systems and PSR-3 introduces severity level (Syslog, Monolog PSR-3). In most cases they are: emergency, alert, critical, error, warning, notice, info, debug. And all of them are the same in terms, that alert is more important than error.
In Laravel console commands we can control the amount of generated output information by specifying -vvv, -v and -q options. It is provided by the underlying Symfony's Verbosity Levels.
Also Laravel provides several helper functions to colorize the console output: error, warn, info, comment, question. They are utilizing Symfony's Color Styles.
Next we have few useful blocks: alert, table. They can be used to decorate the output.
As you can see several names partially matches severity names: alert, error, warn, info. And the main problem is in alert which is intended to "write a string in an alert box". It gives us a highly visible box, but it lacks the ability to be used as extra important text.
Lets assume this snippet:
Would we run this command with
-q
(we want to see only important messages) we will see only error:And won't see alert at all. Our alert is not an alert, and we can't change this behavior.
The most correct solution would be to rename method alert to box, panel, header or something else. But it would be a breaking change and should be discussed at first place.
Now, about this PR.
Now users can specify verbosity level (importance) for alert boxes (decorated output blocks).
Boxes are printed based on the current level of output detail. It won't generate dangling blank lines unless the box is printed.
It's not a BC. Currently alert doesn't accept second argument. The parameter has a default value that retains the old behavior. Extra parameter passed to older frameworks will be ignored.
There is no tests. It's still a questionable should we rename this method or not. And, as far as none of this methods were covered with tests, and current fix is trivial, I decide to not write a test that would be removed in the future. But if it is really required, I can provide one. Just let me know.