diff --git a/CHANGELOG b/CHANGELOG index 4490db5..b579a06 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +SlackBundle v1.4.0 +================== +- Feature: Monolog-Logger uses colored attachments based on the log level (by @jdecoster) +- Patch: Quoting Services to Support Symfony > 2.8 (by @carlosmasip) +- Patch: Fix deprecation in configuration +- Patch: Enable Symfony 3.0 and PHP 7 + SlackBundle v1.3.0 ================== - Feature: File upload service now accepts an array of channels, string usage is deprecated diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0fc2bd3..db421b1 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -27,7 +27,7 @@ public function getConfigTreeBuilder() ->end() ->integerNode('limit_retries') ->defaultValue(3) - ->cannotBeEmpty() + ->min(1) ->info('The amount of retries for the connection if the Rate Limits of Slack are reached') ->end() ->end(); diff --git a/Monolog/Handler/SlackHandler.php b/Monolog/Handler/SlackHandler.php index 3758a8f..cbb8217 100644 --- a/Monolog/Handler/SlackHandler.php +++ b/Monolog/Handler/SlackHandler.php @@ -2,6 +2,7 @@ namespace DZunke\SlackBundle\Monolog\Handler; +use DZunke\SlackBundle\Slack\Entity\MessageAttachment; use DZunke\SlackBundle\Slack\Messaging; use Monolog\Formatter\LineFormatter; use Monolog\Handler\AbstractProcessingHandler; @@ -47,7 +48,28 @@ public function __construct(Messaging $messaging, $channel, $username, $level = protected function write(array $record) { - $this->messagingClient->message($this->channel, $record["formatted"], $this->username); + $attachment = new MessageAttachment(); + + switch($record['level']) { + case Logger::DEBUG: + case Logger::INFO: + $attachment->setColor('good'); + break; + case Logger::NOTICE: + case Logger::WARNING: + $attachment->setColor('warning'); + break; + case Logger::ERROR: + case Logger::CRITICAL: + case Logger::ALERT: + case Logger::EMERGENCY: + $attachment->setColor('danger'); + break; + } + + $attachment->addField($record['level_name'], $record['formatted']); + + $this->messagingClient->message($this->channel, '', $this->username, [$attachment]); } /** diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 85a0e42..b984113 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -8,16 +8,16 @@ services: dz.slack.client: class: DZunke\SlackBundle\Slack\Client - arguments: [@dz.slack.connection] + arguments: ["@dz.slack.connection"] dz.slack.messaging: class: DZunke\SlackBundle\Slack\Messaging - arguments: [@dz.slack.client, @dz.slack.identity_bag] + arguments: ["@dz.slack.client", "@dz.slack.identity_bag"] dz.slack.channels: class: DZunke\SlackBundle\Slack\Channels - arguments: [@dz.slack.client] + arguments: ["@dz.slack.client"] dz.slack.users: class: DZunke\SlackBundle\Slack\Users - arguments: [@dz.slack.client] + arguments: ["@dz.slack.client"] diff --git a/composer.json b/composer.json index f898737..a2d9d9c 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "exclude": ["/Tests"] }, "require": { - "php": ">=5.4.0", + "php": ">=5.4", + "symfony/symfony": "~2.3|~3.0", "guzzle/guzzle": ">=3.7.0" }, "autoload": {