Skip to content

Commit 9b84732

Browse files
committed
feature #21003 [Console][FrameworkBundle] Log console exceptions (jameshalsall, 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 ------- 919041c1ad Add Console ExceptionListener 9896547a4d Add basic support for automatic console exception logging
2 parents f15405a + 2aa9c9f commit 9b84732

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\Finder\Finder;
2929
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
3030
use Symfony\Component\Config\FileLocator;
31+
use Symfony\Component\Config\Resource\ClassExistenceResource;
3132
use Symfony\Component\PropertyAccess\PropertyAccessor;
3233
use Symfony\Component\Serializer\Encoder\YamlEncoder;
3334
use Symfony\Component\Serializer\Encoder\CsvEncoder;
@@ -38,6 +39,7 @@
3839
use Symfony\Component\Workflow;
3940
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
4041
use Symfony\Component\Yaml\Yaml;
42+
use Symfony\Component\Console\Application;
4143

4244
/**
4345
* FrameworkExtension.
@@ -83,6 +85,11 @@ public function load(array $configs, ContainerBuilder $container)
8385

8486
$loader->load('fragment_renderer.xml');
8587

88+
$container->addResource(new ClassExistenceResource(Application::class));
89+
if (class_exists(Application::class)) {
90+
$loader->load('console.xml');
91+
}
92+
8693
// Property access is used by both the Form and the Validator component
8794
$loader->load('property_access.xml');
8895

Resources/config/console.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
9+
<service id="console.exception_listener" class="Symfony\Component\Console\EventListener\ExceptionListener" public="false">
10+
<argument type="service" id="logger" on-invalid="null" />
11+
<tag name="kernel.event_subscriber" />
12+
<tag name="monolog.logger" channel="console" />
13+
</service>
14+
15+
</services>
16+
</container>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"symfony/class-loader": "~3.2",
2222
"symfony/dependency-injection": "~3.3",
2323
"symfony/config": "~3.3",
24-
"symfony/event-dispatcher": "~2.8|~3.0",
24+
"symfony/event-dispatcher": "~3.3",
2525
"symfony/http-foundation": "~3.1",
2626
"symfony/http-kernel": "~3.3",
2727
"symfony/polyfill-mbstring": "~1.0",

0 commit comments

Comments
 (0)