Skip to content

Commit

Permalink
Add include_stacktraces configuration option to handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 14, 2016
1 parent 08ac861 commit 8cdd4a1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public function getConfigTreeBuilder()
->scalarNode('priority')->defaultValue(0)->end()
->scalarNode('level')->defaultValue('DEBUG')->end()
->booleanNode('bubble')->defaultTrue()->end()
->booleanNode('include_stacktraces')->defaultFalse()->end()
->scalarNode('path')->defaultValue('%kernel.logs_dir%/%kernel.environment%.log')->end() // stream and rotating
->scalarNode('file_permission') // stream and rotating
->defaultNull()
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
$definition = new Definition(sprintf('%%monolog.handler.%s.class%%', $handler['type']));
$handler['level'] = $this->levelToMonologConst($handler['level']);

if ($handler['include_stacktraces']) {
$definition->setConfigurator(array('Symfony\\Bundle\\MonologBundle\\MonologBundle', 'includeStacktraces'));
}

switch ($handler['type']) {
case 'service':
$container->setAlias($handlerId, $handler['id']);
Expand Down
13 changes: 13 additions & 0 deletions MonologBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Bundle\MonologBundle;

use Monolog\Formatter\LineFormatter;
use Monolog\Handler\HandlerInterface;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddSwiftMailerTransportPass;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -34,4 +36,15 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new AddProcessorsPass());
$container->addCompilerPass(new AddSwiftMailerTransportPass());
}

/**
* @internal
*/
public static function includeStacktraces(HandlerInterface $handler)
{
$formatter = $handler->getFormatter();
if ($formatter instanceof LineFormatter) {
$formatter->includeStacktraces();
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"symfony/dependency-injection": "~2.3|~3.0",
"symfony/config": "~2.3|~3.0",
"symfony/http-kernel": "~2.3|~3.0",
"monolog/monolog": "~1.8"
"monolog/monolog": "~1.12"
},
"require-dev": {
"symfony/yaml": "~2.3|~3.0",
Expand Down

0 comments on commit 8cdd4a1

Please sign in to comment.