Skip to content

Commit 00ed2f3

Browse files
committed
Add stream handler lock option
1 parent 2b41b8b commit 00ed2f3

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

DependencyInjection/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
* - path: string
3232
* - [level]: level name or int value, defaults to DEBUG
3333
* - [bubble]: bool, defaults to true
34+
* - [file_permission]: int|null, defaults to null (0644)
35+
* - [use_locking]: bool, defaults to false
3436
*
3537
* - console:
3638
* - [verbosity_levels]: level => verbosity configuration
@@ -349,6 +351,7 @@ public function getConfigTreeBuilder()
349351
})
350352
->end()
351353
->end()
354+
->booleanNode('use_locking')->defaultFalse()->end() // stream
352355
->scalarNode('filename_format')->defaultValue('{filename}-{date}')->end() //rotating
353356
->scalarNode('date_format')->defaultValue('Y-m-d')->end() //rotating
354357
->scalarNode('ident')->defaultFalse()->end() // syslog

DependencyInjection/MonologExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
162162
$handler['level'],
163163
$handler['bubble'],
164164
$handler['file_permission'],
165+
$handler['use_locking'],
165166
));
166167
break;
167168

Resources/config/schema/monolog-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<xsd:attribute name="level" type="level" />
3434
<xsd:attribute name="bubble" type="xsd:boolean" />
3535
<xsd:attribute name="process-psr-3-messages" type="xsd:boolean" />
36+
<xsd:attribute name="use_locking" type="xsd:boolean" />
3637
<xsd:attribute name="app-name" type="xsd:string" />
3738
<xsd:attribute name="path" type="xsd:string" />
3839
<xsd:attribute name="id" type="xsd:string" />

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,31 @@ public function testWithFilePermission()
323323
$this->assertSame(0777, $config['handlers']['bar']['file_permission']);
324324
}
325325

326+
public function testWithUseLocking()
327+
{
328+
$configs = array(
329+
array(
330+
'handlers' => array(
331+
'foo' => array(
332+
'type' => 'stream',
333+
'path' => '/foo',
334+
'use_locking' => false,
335+
),
336+
'bar' => array(
337+
'type' => 'stream',
338+
'path' => '/bar',
339+
'use_locking' => true,
340+
)
341+
)
342+
)
343+
);
344+
345+
$config = $this->process($configs);
346+
347+
$this->assertFalse($config['handlers']['foo']['use_locking']);
348+
$this->assertTrue($config['handlers']['bar']['use_locking']);
349+
}
350+
326351
public function testWithNestedHandler()
327352
{
328353
$configs = array(

Tests/DependencyInjection/FixtureMonologExtensionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testLoadWithSeveralHandlers()
3838

3939
$handler = $container->getDefinition('monolog.handler.custom');
4040
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\StreamHandler');
41-
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666));
41+
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666, false));
4242

4343
$handler = $container->getDefinition('monolog.handler.main');
4444
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\FingersCrossedHandler');
@@ -66,7 +66,7 @@ public function testLoadWithOverwriting()
6666

6767
$handler = $container->getDefinition('monolog.handler.custom');
6868
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\StreamHandler');
69-
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::WARNING, true, null));
69+
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::WARNING, true, null, false));
7070

7171
$handler = $container->getDefinition('monolog.handler.main');
7272
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\FingersCrossedHandler');
@@ -92,7 +92,7 @@ public function testLoadWithNewAtEnd()
9292

9393
$handler = $container->getDefinition('monolog.handler.new');
9494
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\StreamHandler');
95-
$this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', \Monolog\Logger::ERROR, true, null));
95+
$this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', \Monolog\Logger::ERROR, true, null, false));
9696
}
9797

9898
public function testLoadWithNewAndPriority()
@@ -124,7 +124,7 @@ public function testLoadWithNewAndPriority()
124124

125125
$handler = $container->getDefinition('monolog.handler.last');
126126
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\StreamHandler');
127-
$this->assertDICConstructorArguments($handler, array('/tmp/last.log', \Monolog\Logger::ERROR, true, null));
127+
$this->assertDICConstructorArguments($handler, array('/tmp/last.log', \Monolog\Logger::ERROR, true, null, false));
128128
}
129129

130130
public function testHandlersWithChannels()

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public function testLoadWithDefault()
3333

3434
$handler = $container->getDefinition('monolog.handler.main');
3535
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\StreamHandler');
36-
$this->assertDICConstructorArguments($handler, array('%kernel.logs_dir%/%kernel.environment%.log', \Monolog\Logger::DEBUG, true, null));
36+
$this->assertDICConstructorArguments($handler, array('%kernel.logs_dir%/%kernel.environment%.log', \Monolog\Logger::DEBUG, true, null, false));
3737
$this->assertDICDefinitionMethodCallAt(0, $handler, 'pushProcessor', array(new Reference('monolog.processor.psr_log_message')));
3838
}
3939

4040
public function testLoadWithCustomValues()
4141
{
4242
$container = $this->getContainer(array(array('handlers' => array(
43-
'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666')
43+
'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666', 'use_locking' => true)
4444
))));
4545
$this->assertTrue($container->hasDefinition('monolog.logger'));
4646
$this->assertTrue($container->hasDefinition('monolog.handler.custom'));
@@ -51,7 +51,7 @@ public function testLoadWithCustomValues()
5151

5252
$handler = $container->getDefinition('monolog.handler.custom');
5353
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\StreamHandler');
54-
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666));
54+
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666, true));
5555
}
5656

5757
public function testLoadWithNestedHandler()
@@ -71,7 +71,7 @@ public function testLoadWithNestedHandler()
7171

7272
$handler = $container->getDefinition('monolog.handler.custom');
7373
$this->assertDICDefinitionClass($handler, 'Monolog\Handler\StreamHandler');
74-
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666));
74+
$this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666, false));
7575
}
7676

7777
public function testLoadWithServiceHandler()

0 commit comments

Comments
 (0)