Skip to content

Commit cff4dc5

Browse files
committed
Merge pull request #103 from unkind/feature-file-permission-option
Added "file_permission" option ("stream", "rotating_file")
2 parents e33d138 + 0b0afbe commit cff4dc5

File tree

8 files changed

+53
-9
lines changed

8 files changed

+53
-9
lines changed

DependencyInjection/Configuration.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ public function getConfigTreeBuilder()
270270
->scalarNode('level')->defaultValue('DEBUG')->end()
271271
->booleanNode('bubble')->defaultTrue()->end()
272272
->scalarNode('path')->defaultValue('%kernel.logs_dir%/%kernel.environment%.log')->end() // stream and rotating
273+
->scalarNode('file_permission') // stream and rotating
274+
->defaultNull()
275+
->beforeNormalization()
276+
->ifString()
277+
->then(function ($v) {
278+
if (substr($v, 0, 1) === '0') {
279+
return octdec($v);
280+
}
281+
282+
return (int) $v;
283+
})
284+
->end()
285+
->end()
273286
->scalarNode('ident')->defaultFalse()->end() // syslog
274287
->scalarNode('logopts')->defaultValue(LOG_PID)->end() // syslog
275288
->scalarNode('facility')->defaultValue('user')->end() // syslog

DependencyInjection/MonologExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
135135
$handler['path'],
136136
$handler['level'],
137137
$handler['bubble'],
138+
$handler['file_permission'],
138139
));
139140
break;
140141

@@ -242,6 +243,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
242243
$handler['max_files'],
243244
$handler['level'],
244245
$handler['bubble'],
246+
$handler['file_permission'],
245247
));
246248
break;
247249

Resources/config/schema/monolog-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<xsd:attribute name="bot-name" type="xsd:string" />
6262
<xsd:attribute name="use-attachment" type="xsd:boolean" />
6363
<xsd:attribute name="icon-emoji" type="xsd:string" />
64+
<xsd:attribute name="file-permission" type="xsd:string" />
6465
</xsd:complexType>
6566

6667
<xsd:simpleType name="level">

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,31 @@ public function testWithType()
271271
$this->assertEquals('B', $config['handlers']['foo']['channels']['elements'][1]);
272272
}
273273

274+
public function testWithFilePermission()
275+
{
276+
$configs = array(
277+
array(
278+
'handlers' => array(
279+
'foo' => array(
280+
'type' => 'stream',
281+
'path' => '/foo',
282+
'file_permission' => '0666',
283+
),
284+
'bar' => array(
285+
'type' => 'stream',
286+
'path' => '/bar',
287+
'file_permission' => 0777
288+
)
289+
)
290+
)
291+
);
292+
293+
$config = $this->process($configs);
294+
295+
$this->assertSame(0666, $config['handlers']['foo']['file_permission']);
296+
$this->assertSame(0777, $config['handlers']['bar']['file_permission']);
297+
}
298+
274299
/**
275300
* Processes an array of configurations and returns a compiled version.
276301
*

Tests/DependencyInjection/FixtureMonologExtensionTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testLoadWithSeveralHandlers()
3535

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

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

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

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

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

9393
public function testLoadWithNewAndPriority()
@@ -114,11 +114,11 @@ public function testLoadWithNewAndPriority()
114114

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

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

124124
public function testHandlersWithChannels()

Tests/DependencyInjection/Fixtures/xml/multiple_handlers.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
88

99
<config>
10-
<handler name="custom" type="stream" path="/tmp/symfony.log" bubble="false" level="ERROR" />
10+
<handler name="custom" type="stream" path="/tmp/symfony.log" bubble="false" level="ERROR" file-permission="0666" />
1111
<handler name="main" type="fingers_crossed" action-level="ERROR" passthru-level="NOTICE" handler="nested" />
1212
<handler name="nested" type="stream" />
1313
<handler name="filtered" type="filter" handler="nested2">

Tests/DependencyInjection/Fixtures/yml/multiple_handlers.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ monolog:
55
path: /tmp/symfony.log
66
bubble: false
77
level: ERROR
8+
file_permission: 0666
89
main:
910
type: fingers_crossed
1011
action_level: ERROR

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public function testLoadWithDefault()
3131

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

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

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

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

5153
/**

0 commit comments

Comments
 (0)