Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ public function getConfigTreeBuilder()
->scalarNode('level')->defaultValue('DEBUG')->end()
->booleanNode('bubble')->defaultTrue()->end()
->scalarNode('path')->defaultValue('%kernel.logs_dir%/%kernel.environment%.log')->end() // stream and rotating
->scalarNode('file_permission') // stream and rotating
->defaultNull()
->beforeNormalization()
->ifString()
->then(function ($v) {
if (substr($v, 0, 1) === '0') {
return octdec($v);
}

return (int) $v;
})
->end()
->end()
->scalarNode('ident')->defaultFalse()->end() // syslog
->scalarNode('logopts')->defaultValue(LOG_PID)->end() // syslog
->scalarNode('facility')->defaultValue('user')->end() // syslog
Expand Down
2 changes: 2 additions & 0 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
$handler['path'],
$handler['level'],
$handler['bubble'],
$handler['file_permission'],
));
break;

Expand Down Expand Up @@ -242,6 +243,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
$handler['max_files'],
$handler['level'],
$handler['bubble'],
$handler['file_permission'],
));
break;

Expand Down
1 change: 1 addition & 0 deletions Resources/config/schema/monolog-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<xsd:attribute name="bot-name" type="xsd:string" />
<xsd:attribute name="use-attachment" type="xsd:boolean" />
<xsd:attribute name="icon-emoji" type="xsd:string" />
<xsd:attribute name="file-permission" type="xsd:string" />
</xsd:complexType>

<xsd:simpleType name="level">
Expand Down
25 changes: 25 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,31 @@ public function testWithType()
$this->assertEquals('B', $config['handlers']['foo']['channels']['elements'][1]);
}

public function testWithFilePermission()
{
$configs = array(
array(
'handlers' => array(
'foo' => array(
'type' => 'stream',
'path' => '/foo',
'file_permission' => '0666',
),
'bar' => array(
'type' => 'stream',
'path' => '/bar',
'file_permission' => 0777
)
)
)
);

$config = $this->process($configs);

$this->assertSame(0666, $config['handlers']['foo']['file_permission']);
$this->assertSame(0777, $config['handlers']['bar']['file_permission']);
}

/**
* Processes an array of configurations and returns a compiled version.
*
Expand Down
10 changes: 5 additions & 5 deletions Tests/DependencyInjection/FixtureMonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testLoadWithSeveralHandlers()

$handler = $container->getDefinition('monolog.handler.custom');
$this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false));
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666));

$handler = $container->getDefinition('monolog.handler.main');
$this->assertDICDefinitionClass($handler, '%monolog.handler.fingers_crossed.class%');
Expand All @@ -62,7 +62,7 @@ public function testLoadWithOverwriting()

$handler = $container->getDefinition('monolog.handler.custom');
$this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::WARNING, true));
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::WARNING, true, null));

$handler = $container->getDefinition('monolog.handler.main');
$this->assertDICDefinitionClass($handler, '%monolog.handler.fingers_crossed.class%');
Expand All @@ -87,7 +87,7 @@ public function testLoadWithNewAtEnd()

$handler = $container->getDefinition('monolog.handler.new');
$this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
$this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', \Monolog\Logger::ERROR, true));
$this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', \Monolog\Logger::ERROR, true, null));
}

public function testLoadWithNewAndPriority()
Expand All @@ -114,11 +114,11 @@ public function testLoadWithNewAndPriority()

$handler = $container->getDefinition('monolog.handler.first');
$this->assertDICDefinitionClass($handler, '%monolog.handler.rotating_file.class%');
$this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', 0, \Monolog\Logger::ERROR, true));
$this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', 0, \Monolog\Logger::ERROR, true, null));

$handler = $container->getDefinition('monolog.handler.last');
$this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
$this->assertDICConstructorArguments($handler, array('/tmp/last.log', \Monolog\Logger::ERROR, true));
$this->assertDICConstructorArguments($handler, array('/tmp/last.log', \Monolog\Logger::ERROR, true, null));
}

public function testHandlersWithChannels()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">

<config>
<handler name="custom" type="stream" path="/tmp/symfony.log" bubble="false" level="ERROR" />
<handler name="custom" type="stream" path="/tmp/symfony.log" bubble="false" level="ERROR" file-permission="0666" />
<handler name="main" type="fingers_crossed" action-level="ERROR" passthru-level="NOTICE" handler="nested" />
<handler name="nested" type="stream" />
<handler name="filtered" type="filter" handler="nested2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ monolog:
path: /tmp/symfony.log
bubble: false
level: ERROR
file_permission: 0666
main:
type: fingers_crossed
action_level: ERROR
Expand Down
8 changes: 5 additions & 3 deletions Tests/DependencyInjection/MonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public function testLoadWithDefault()

$handler = $container->getDefinition('monolog.handler.main');
$this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
$this->assertDICConstructorArguments($handler, array('%kernel.logs_dir%/%kernel.environment%.log', \Monolog\Logger::DEBUG, true));
$this->assertDICConstructorArguments($handler, array('%kernel.logs_dir%/%kernel.environment%.log', \Monolog\Logger::DEBUG, true, null));
}

public function testLoadWithCustomValues()
{
$container = $this->getContainer(array(array('handlers' => array('custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR')))));
$container = $this->getContainer(array(array('handlers' => array(
'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666')
))));
$this->assertTrue($container->hasDefinition('monolog.logger'));
$this->assertTrue($container->hasDefinition('monolog.handler.custom'));

Expand All @@ -45,7 +47,7 @@ public function testLoadWithCustomValues()

$handler = $container->getDefinition('monolog.handler.custom');
$this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false));
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666));
}

/**
Expand Down