Skip to content

Commit ec5c789

Browse files
author
Desjardins Jérôme
committed
add slack webhook + slackbot
uptate to moonlog 1.22
1 parent 050608c commit ec5c789

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

DependencyInjection/Configuration.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,24 @@
207207
* - [level]: level name or int value, defaults to DEBUG
208208
* - [bubble]: bool, defaults to true
209209
*
210+
* - slackwebhook:
211+
* - webhook_url: slack webhook URL
212+
* - channel: channel name (with starting #)
213+
* - [bot_name]: defaults to Monolog
214+
* - [icon_emoji]: defaults to null
215+
* - [use_attachment]: bool, defaults to true
216+
* - [use_short_attachment]: bool, defaults to false
217+
* - [include_extra]: bool, defaults to false
218+
* - [level]: level name or int value, defaults to DEBUG
219+
* - [bubble]: bool, defaults to true
220+
*
221+
* - slackbot:
222+
* - team: slack team slug
223+
* - token: slackbot token
224+
* - channel: channel name (with starting #)
225+
* - [level]: level name or int value, defaults to DEBUG
226+
* - [bubble]: bool, defaults to true
227+
*
210228
* - cube:
211229
* - url: http/udp url to the cube server
212230
* - [level]: level name or int value, defaults to DEBUG
@@ -351,15 +369,17 @@ public function getConfigTreeBuilder()
351369
->scalarNode('room')->end() // hipchat
352370
->scalarNode('message_format')->defaultValue('text')->end() // hipchat
353371
->scalarNode('api_version')->defaultNull()->end() // hipchat
354-
->scalarNode('channel')->end() // slack
355-
->scalarNode('bot_name')->defaultValue('Monolog')->end() // slack
356-
->scalarNode('use_attachment')->defaultTrue()->end() // slack
357-
->scalarNode('use_short_attachment')->defaultFalse()->end() // slack
358-
->scalarNode('include_extra')->defaultFalse()->end() // slack
359-
->scalarNode('icon_emoji')->defaultNull()->end() // slack
372+
->scalarNode('channel')->end() // slack & slackwebhook & slackbot
373+
->scalarNode('bot_name')->defaultValue('Monolog')->end() // slack & slackwebhook
374+
->scalarNode('use_attachment')->defaultTrue()->end() // slack & slackwebhook
375+
->scalarNode('use_short_attachment')->defaultFalse()->end() // slack & slackwebhook
376+
->scalarNode('include_extra')->defaultFalse()->end() // slack & slackwebhook
377+
->scalarNode('icon_emoji')->defaultNull()->end() // slack & slackwebhook
378+
->scalarNode('webhook_url')->end() // slackwebhook
379+
->scalarNode('slack_team')->end() // slackbot
360380
->scalarNode('notify')->defaultFalse()->end() // hipchat
361381
->scalarNode('nickname')->defaultValue('Monolog')->end() // hipchat
362-
->scalarNode('token')->end() // pushover & hipchat & loggly & logentries & flowdock & rollbar & slack
382+
->scalarNode('token')->end() // pushover & hipchat & loggly & logentries & flowdock & rollbar & slack & slackbot
363383
->scalarNode('source')->end() // flowdock
364384
->booleanNode('use_ssl')->defaultTrue()->end() // logentries & hipchat
365385
->variableNode('user') // pushover
@@ -692,6 +712,14 @@ public function getConfigTreeBuilder()
692712
->ifTrue(function ($v) { return 'slack' === $v['type'] && (empty($v['token']) || empty($v['channel'])); })
693713
->thenInvalid('The token and channel have to be specified to use a SlackHandler')
694714
->end()
715+
->validate()
716+
->ifTrue(function ($v) { return 'slackwebhook' === $v['type'] && (empty($v['webhook_url']) || empty($v['channel'])); })
717+
->thenInvalid('The webhook_url and channel have to be specified to use a SlackWebhookHandler')
718+
->end()
719+
->validate()
720+
->ifTrue(function ($v) { return 'slackbot' === $v['type'] && (empty($v['stack_team']) || empty($v['token']) || empty($v['channel'])); })
721+
->thenInvalid('The stack_team, token and channel have to be specified to use a SlackbotHandler')
722+
->end()
695723
->validate()
696724
->ifTrue(function ($v) { return 'cube' === $v['type'] && empty($v['url']); })
697725
->thenInvalid('The url has to be specified to use a CubeHandler')

DependencyInjection/MonologExtension.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,30 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
532532
));
533533
break;
534534

535+
case 'slackwebhook':
536+
$definition->setArguments(array(
537+
$handler['webhook_url'],
538+
$handler['channel'],
539+
$handler['bot_name'],
540+
$handler['use_attachment'],
541+
$handler['icon_emoji'],
542+
$handler['use_short_attachment'],
543+
$handler['include_extra'],
544+
$handler['level'],
545+
$handler['bubble'],
546+
));
547+
break;
548+
549+
case 'slackbot':
550+
$definition->setArguments(array(
551+
$handler['slack_team'],
552+
$handler['token'],
553+
$handler['channel'],
554+
$handler['level'],
555+
$handler['bubble'],
556+
));
557+
break;
558+
535559
case 'cube':
536560
$definition->setArguments(array(
537561
$handler['url'],
@@ -720,6 +744,8 @@ private function getHandlerClassByType($handlerType)
720744
'newrelic' => 'Monolog\Handler\NewRelicHandler',
721745
'hipchat' => 'Monolog\Handler\HipChatHandler',
722746
'slack' => 'Monolog\Handler\SlackHandler',
747+
'slackwebhook' => 'Monolog\Handler\SlackWebhookHandler',
748+
'slackbot' => 'Monolog\Handler\SlackbotHandler',
723749
'cube' => 'Monolog\Handler\CubeHandler',
724750
'amqp' => 'Monolog\Handler\AmqpHandler',
725751
'error_log' => 'Monolog\Handler\ErrorLogHandler',

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"symfony/dependency-injection": "~2.7|~3.0",
2222
"symfony/config": "~2.7|~3.0",
2323
"symfony/http-kernel": "~2.7|~3.0",
24-
"monolog/monolog": "~1.18"
24+
"monolog/monolog": "~1.22"
2525
},
2626
"require-dev": {
2727
"symfony/yaml": "~2.3|~3.0",

0 commit comments

Comments
 (0)