Skip to content

Commit bdfbc93

Browse files
authored
Merge pull request #196 from lyrixx/server-log
Added support for ServerLog command
2 parents 1afc6ac + 7d4da2c commit bdfbc93

File tree

7 files changed

+61
-1
lines changed

7 files changed

+61
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.1.0 (xxxx-xx-xx)
2+
3+
* Added support for server_log handler
4+
15
## 3.0.3 (2017-01-10)
26

37
* Fixed deprecation notices when using Symfony 3.3+ and PHP7+

DependencyInjection/Configuration.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@
281281
* - [level]: level name or int value, defaults to DEBUG
282282
* - [bubble]: bool, defaults to true
283283
*
284+
* - server_log:
285+
* - host: server log host. ex: 127.0.0.1:9911
286+
* - [level]: level name or int value, defaults to DEBUG
287+
* - [bubble]: bool, defaults to true
288+
*
284289
* @author Jordi Boggiano <j.boggiano@seld.be>
285290
* @author Christophe Coevoet <stof@notk.org>
286291
*/
@@ -768,6 +773,10 @@ public function getConfigTreeBuilder()
768773
->ifTrue(function ($v) { return 'flowdock' === $v['type'] && empty($v['source']); })
769774
->thenInvalid('The source has to be specified to use a FlowdockHandler')
770775
->end()
776+
->validate()
777+
->ifTrue(function ($v) { return 'server_log' === $v['type'] && empty($v['host']); })
778+
->thenInvalid('The host has to be specified to use a ServerLogHandler')
779+
->end()
771780
->end()
772781
->validate()
773782
->ifTrue(function ($v) { return isset($v['debug']); })

DependencyInjection/MonologExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,17 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
677677
$handler['app_name'],
678678
));
679679
break;
680+
case 'server_log':
681+
if (!class_exists('Symfony\Bridge\Monolog\Handler\ServerLogHandler')) {
682+
throw new \RuntimeException('The ServerLogHandler is not available. Please update "symfony/monolog-bridge" to 3.3.');
683+
}
684+
685+
$definition->setArguments(array(
686+
$handler['host'],
687+
$handler['level'],
688+
$handler['bubble'],
689+
));
690+
break;
680691

681692
// Handlers using the constructor of AbstractHandler without adding their own arguments
682693
case 'browser_console':
@@ -759,6 +770,7 @@ private function getHandlerClassByType($handlerType)
759770
'filter' => 'Monolog\Handler\FilterHandler',
760771
'mongo' => 'Monolog\Handler\MongoDBHandler',
761772
'elasticsearch' => 'Monolog\Handler\ElasticSearchHandler',
773+
'server_log' => 'Symfony\Bridge\Monolog\Handler\ServerLogHandler',
762774
);
763775

764776
if (!isset($typeToClassMapping[$handlerType])) {

Resources/doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ following command to download the latest stable version of this bundle:
99

1010
.. code-block:: bash
1111
12-
$ composer require symfony/monolog-bundle "~2.7"
12+
$ composer require symfony/monolog-bundle
1313
1414
This command requires you to have Composer installed globally, as explained
1515
in the `installation chapter`_ of the Composer documentation.

Tests/DependencyInjection/FixtureMonologExtensionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection;
1313

1414
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
15+
use Symfony\Bridge\Monolog\Handler\ServerLogHandler;
1516
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
@@ -154,6 +155,21 @@ public function testSingleEmailRecipient()
154155
), $container->getDefinition('monolog.handler.swift.mail_message_factory')->getArguments());
155156
}
156157

158+
public function testServerLog()
159+
{
160+
if (!class_exists('Symfony\Bridge\Monolog\Handler\ServerLogHandler')) {
161+
$this->markTestSkipped('The ServerLogHandler is not available.');
162+
}
163+
164+
$container = $this->getContainer('server_log');
165+
166+
$this->assertEquals(array(
167+
'0:9911',
168+
100,
169+
true,
170+
), $container->getDefinition('monolog.handler.server_log')->getArguments());
171+
}
172+
157173
public function testMultipleEmailRecipients()
158174
{
159175
$container = $this->getContainer('multiple_email_recipients');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
7+
8+
<monolog:config>
9+
<monolog:handler
10+
name="server_log"
11+
type="server_log"
12+
host="0:9911" />
13+
</monolog:config>
14+
</container>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
monolog:
2+
handlers:
3+
server_log:
4+
type: server_log
5+
host: 0:9911

0 commit comments

Comments
 (0)