-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console][FrameworkBundle] Log console exceptions #21003
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
[Console][FrameworkBundle] Log console exceptions #21003
Conversation
6824d97
to
07a2966
Compare
f0f0717
to
9153eb1
Compare
9153eb1
to
3e55c69
Compare
<service id="console.exception_listener" class="Symfony\Component\Console\EventListener\ExceptionListener"> | ||
<tag name="kernel.event_subscriber" /> | ||
<argument type="service" id="logger" on-invalid="null" /> | ||
</service> |
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.
I think it could be useful to add a channel. for example console
.
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.
It makes sense, console
channel added
3e55c69
to
95dd011
Compare
👍 |
@@ -27,7 +27,7 @@ | |||
"psr/log": "~1.0" | |||
}, | |||
"suggest": { | |||
"symfony/event-dispatcher": "", | |||
"symfony/event-dispatcher": "For using the console events and exception listener", |
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.
I would not change this.
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.
Reverted
518a4d3
to
b175619
Compare
What about adding an entry to the changelog? |
|
||
<services> | ||
|
||
<service id="console.exception_listener" class="Symfony\Component\Console\EventListener\ExceptionListener"> |
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.
could be private
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.
Since it is an event listener, it needs #21312 to be merged first (see https://travis-ci.org/symfony/symfony/jobs/192665057#L2971)
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Console exception listener. |
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 description doesn't add much value IMO
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.
I agree, removed
9ea7465
to
735f100
Compare
Changelog updated |
735f100
to
3399e7f
Compare
@xabbuh The listener is private now |
The event-dispatcher does not allow private listeners before 3.3... Can we let it public, or shall I update the framework's event-dispatcher requirement to |
3981130
to
6217caa
Compare
@chalasr I think most people upgrade all Symfony components from one version to the next, especially as many just use symfony/symfony, which does not provide any flexibility. Having broader constraints help with compatibility with other libs using Symfony though. |
Makes sense, thank you for the hint @fabpot |
👍 Status: Reviewed |
ping @fabpot |
@@ -81,6 +81,7 @@ public function load(array $configs, ContainerBuilder $container) | |||
} | |||
|
|||
$loader->load('fragment_renderer.xml'); | |||
$loader->load('console.xml'); |
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.
I would only registered this when the Console component is actually available.
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.
Fixed
9ff4b70
to
c5e671f
Compare
@@ -82,6 +83,10 @@ public function load(array $configs, ContainerBuilder $container) | |||
|
|||
$loader->load('fragment_renderer.xml'); | |||
|
|||
if (class_exists(Application::class)) { |
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 should add a FileExistenceResource
resource so that if the console component is installed, the cache is automatically rebuilt.
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.
Sorry but I don't understand. We are checking a class existence here, FileExistenceResource
is about the filesystem, 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.
Got it! You mean ClassExistenceResource
:) done
Build failure is unrelated. |
c5e671f
to
156e264
Compare
Handle non string-castable inputs Cleanup input for display Naming changes InputInterface doesnt have a toString() Logger must be private Remove useless doc blocks Tweak tests
156e264
to
919041c
Compare
Thank you @chalasr. |
…eshalsall, chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [Console][FrameworkBundle] Log console exceptions | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10895 | License | MIT | Doc PR | symfony/symfony-docs#7373 Continues #19382, fixing some issues including: - ability to display the input string for any `InputInterface` implementation (cast to string if possible, use the command name otherwise) - if the input can be casted as string, cleanup the result (from `command "'command:name' --foo=bar" ` to `command "command:name --foo=bar"`) - made `ExceptionLister::$logger` private instead of protected - changed methods name from `onKernel*` to `onConsole*` (e.g. `onConsoleException`) and removed unnecessary doc blocks - Added more tests Log for an exception: > [2016-12-22 00:34:42] app.ERROR: Exception thrown while running command: "cache:clear -vvv". Message: "An error occured!" {"exception":"[object] (RuntimeException(code: 0): An error occured! at /Volumes/HD/Sites/tests/sf-demo-3.2/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:61)","command":"cache:clear -vvv","message":"An error occured!"} [] Commits ------- 919041c Add Console ExceptionListener 9896547 Add basic support for automatic console exception logging
This PR was merged into the 3.3-dev branch. Discussion ---------- Don't log console errors in console output Since symfony/symfony#21003, console errors are logged, and since the `console` channel is not ignored by the monolog console handler, the log is written to stderr. IMHO it's useless since the ran command already write the message into, it's just having two traces for the same error, which doesn't make sense to me. I propose to fix that. __Before__  __After__  If one wants the trace, then one can run the command in verbose mode or look at its log file. Commits ------- 2bf1249 Don't log console errors in console output
…(chalasr) This PR was merged into the master branch. Discussion ---------- [Console] Update the doc for automatic console logging In symfony/symfony#21003 we are going to provide automatic error/exception logging for the console, similar to what is done in an HTTP context. In the docs, there is a whole chapter dedicated to this topic. Right now I just removed it, maybe it should be done differently or mentioned somewhere that error/exceptions are automatically logged on the `console` channel? Thanks Commits ------- 76d2c91 Update the doc for automatic console logging
…rs (haroldiedema) This PR was merged into the 3.3 branch. Discussion ---------- [Console] Log exit codes as debug messages instead of errors | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Fixes PR #21003 This patch stops logging `exit_codes != 0` to _error_ and logs it to _debug_ instead, since it's not an error. The console application exited without uncaught exceptions, and the console application deliberately returned a specific exit code, therefore it shouldn't be logged as an error. A valid use case would be to let a caller script in bash (the script spawning the console command) know what action to take based on the exit code. More specifically, exit codes other than 1, 2, 127+n isn't necessarily considered an error. Monolog is hooked to our mailbox, so we can see what is happening in our production environment. However, it's currently being spammed for no reason because of #21003. tl;dr: user-programmed exit codes (return <int> in `execute()`) should NOT log an error message to monolog. I find it a bit iffy to leave the `console.terminiate` event listener in since it now logs to `debug` instead. I'm unsure if people want/need this, so I might as well remove the terminate listener entirely. Commits ------- cadbed3 [Console] Log exit codes as debug messages instead of errors
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Display file and line on Exception | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes/no | Fixed tickets | - | License | MIT | Doc PR | - When an exception occured: If you have not set a verbose mode when running the command, you don't have information about the file and the line on which the exception occured. So you must run a second time the command but the exception may not occured this time (if based on some databases datas which have changed) and it's a waste of time if you process is very long and the exception occured at the end. The feature #21003 solve the problem if you are in a standard Symfony edition, if you leave the default settings and if you are in dev mode Commits ------- 484d278 [Console] Display file and line on Exception
Continues #19382, fixing some issues including:
InputInterface
implementation (cast to string if possible, use the command name otherwise)command "'command:name' --foo=bar"
tocommand "command:name --foo=bar"
)ExceptionLister::$logger
private instead of protectedonKernel*
toonConsole*
(e.g.onConsoleException
) and removed unnecessary doc blocksLog for an exception: