Skip to content

Commit 036cd4b

Browse files
committed
feature #242 Add stream handler lock option (mRoca)
This PR was merged into the 3.x-dev branch. Discussion ---------- Add stream handler lock option This PR adds the $useLocking StreamHandler argument : https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/StreamHandler.php#L44 Commits ------- 00ed2f3 Add stream handler lock option
2 parents a6c3267 + 00ed2f3 commit 036cd4b

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
@@ -361,6 +363,7 @@ public function getConfigTreeBuilder()
361363
})
362364
->end()
363365
->end()
366+
->booleanNode('use_locking')->defaultFalse()->end() // stream
364367
->scalarNode('filename_format')->defaultValue('{filename}-{date}')->end() //rotating
365368
->scalarNode('date_format')->defaultValue('Y-m-d')->end() //rotating
366369
->scalarNode('ident')->defaultFalse()->end() // syslog and syslogudp

DependencyInjection/MonologExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
186186
$handler['level'],
187187
$handler['bubble'],
188188
$handler['file_permission'],
189+
$handler['use_locking'],
189190
));
190191
break;
191192

Resources/config/schema/monolog-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<xsd:attribute name="level" type="level" />
3535
<xsd:attribute name="bubble" type="xsd:boolean" />
3636
<xsd:attribute name="process-psr-3-messages" type="xsd:boolean" />
37+
<xsd:attribute name="use_locking" type="xsd:boolean" />
3738
<xsd:attribute name="app-name" type="xsd:string" />
3839
<xsd:attribute name="path" type="xsd:string" />
3940
<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
@@ -324,6 +324,31 @@ public function testWithFilePermission()
324324
$this->assertSame(0777, $config['handlers']['bar']['file_permission']);
325325
}
326326

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

Tests/DependencyInjection/FixtureMonologExtensionTest.php

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

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

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

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

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

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

9797
public function testLoadWithNewAndPriority()
@@ -123,7 +123,7 @@ public function testLoadWithNewAndPriority()
123123

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

129129
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)