Skip to content

Commit b97e237

Browse files
committed
feature #267 Allow setting "ident" parameter for SyslogUdpHandler, affects #266 (dhirtzbruch)
This PR was merged into the 3.x-dev branch. Discussion ---------- Allow setting "ident" parameter for SyslogUdpHandler, affects #266 As outlined in ticket #266: The SyslogUdpHandler constructor has a sixth parameter "ident", defaulting to "php". However, the current Monolog Bundle implementation allows setting only the first five. Which defaults to the "ident" being set to "php". In our case, we are using papertrail as a log backend, and use the same webserver for multiple small projects. In papertrail, that results in the following output: ``` May 05 02:16:30 vagrant php: app.ERROR: fooo {"exception":"[object] (Exception(code: 0): fooo at /var/customers/webs/fastbolt/https/env1.fastbolt.com/src/Pricecalc/UserBundle/Controller/SecurityController.php:36)","username":"anon.","uri":"http://env1.dev.local/login","level":"critical"} [] May 05 02:18:32 vagrant php: app.ERROR: fooo {"exception":"[object] (Exception(code: 0): fooo at /var/customers/webs/fastbolt/https/env2.fastbolt.com/src/Pricecalc/UserBundle/Controller/SecurityController.php:36)","username":"anon.","uri":"http://env2.dev.local/login","level":"critical"} [] ``` The "php" after "vagrant" is the ident configuration. As you can see, we are not able to determine the source environment, other than guessing from filepath or uri. However, for filtering using the API, we`d like to be able to change the ident per configuration. ``` monolog: handlers: syslog: type: syslogudp host: example.com port: 514 level: error ident: env1 ``` Using that config, we should be able to achieve the following log: ``` May 05 02:16:30 vagrant env1: app.ERROR: fooo {"exception":"[object] (Exception(code: 0): fooo at /var/customers/webs/fastbolt/https/env1.fastbolt.com/src/Pricecalc/UserBundle/Controller/SecurityController.php:36)","username":"anon.","uri":"http://env1.dev.local/login","level":"critical"} [] May 05 02:18:32 vagrant env2: app.ERROR: fooo {"exception":"[object] (Exception(code: 0): fooo at /var/customers/webs/fastbolt/https/env2.fastbolt.com/src/Pricecalc/UserBundle/Controller/SecurityController.php:36)","username":"anon.","uri":"http://env2.dev.local/login","level":"critical"} [] ``` Please let me know if there is anything else I should do, as that`s my first PR/issue here. Commits ------- 9f6f0b6 Allow setting "ident" parameter for SyslogUdpHandler, affects #266
2 parents c720aab + 9f6f0b6 commit b97e237

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
* - [logopts]: defaults to LOG_PID
140140
* - [level]: level name or int value, defaults to DEBUG
141141
* - [bubble]: bool, defaults to true
142+
* - [ident]: string, defaults to
142143
*
143144
* - swift_mailer:
144145
* - from_email: optional if email_prototype is given
@@ -362,7 +363,7 @@ public function getConfigTreeBuilder()
362363
->end()
363364
->scalarNode('filename_format')->defaultValue('{filename}-{date}')->end() //rotating
364365
->scalarNode('date_format')->defaultValue('Y-m-d')->end() //rotating
365-
->scalarNode('ident')->defaultFalse()->end() // syslog
366+
->scalarNode('ident')->defaultFalse()->end() // syslog and syslogudp
366367
->scalarNode('logopts')->defaultValue(LOG_PID)->end() // syslog
367368
->scalarNode('facility')->defaultValue('user')->end() // syslog
368369
->scalarNode('max_files')->defaultValue(0)->end() // rotating

DependencyInjection/MonologExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
458458
$handler['level'],
459459
$handler['bubble'],
460460
));
461+
if ($handler['ident']) {
462+
$definition->addArgument($handler['ident']);
463+
}
461464
break;
462465

463466
case 'swift_mailer':

0 commit comments

Comments
 (0)