1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-11 23:54:04 +02:00

Use constants for Slack colors

This commit is contained in:
Haralan Dobrev
2016-11-14 23:06:48 +02:00
parent 0956a74897
commit 115f6710b1
2 changed files with 21 additions and 12 deletions

View File

@@ -25,6 +25,14 @@ use Monolog\Formatter\FormatterInterface;
*/
class SlackRecord
{
const COLOR_DANGER = 'danger';
const COLOR_WARNING = 'warning';
const COLOR_GOOD = 'good';
const COLOR_DEFAULT = '#e3e4e6';
/**
* Slack channel (encoded ID or name)
* @var string
@@ -194,13 +202,13 @@ class SlackRecord
{
switch (true) {
case $level >= Logger::ERROR:
return 'danger';
return self::COLOR_DANGER;
case $level >= Logger::WARNING:
return 'warning';
return self::COLOR_WARNING;
case $level >= Logger::INFO:
return 'good';
return self::COLOR_GOOD;
default:
return '#e3e4e6';
return self::COLOR_DEFAULT;
}
}

View File

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
use Monolog\TestCase;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\Slack\SlackRecord;
/**
* @author Greg Kedzierski <greg@gregkedzierski.com>
@@ -111,14 +112,14 @@ class SlackHandlerTest extends TestCase
public function provideLevelColors()
{
return array(
array(Logger::DEBUG, '%23e3e4e6'), // escaped #e3e4e6
array(Logger::INFO, 'good'),
array(Logger::NOTICE, 'good'),
array(Logger::WARNING, 'warning'),
array(Logger::ERROR, 'danger'),
array(Logger::CRITICAL, 'danger'),
array(Logger::ALERT, 'danger'),
array(Logger::EMERGENCY,'danger'),
array(Logger::DEBUG, urlencode(SlackRecord::COLOR_DEFAULT)),
array(Logger::INFO, SlackRecord::COLOR_GOOD),
array(Logger::NOTICE, SlackRecord::COLOR_GOOD),
array(Logger::WARNING, SlackRecord::COLOR_WARNING),
array(Logger::ERROR, SlackRecord::COLOR_DANGER),
array(Logger::CRITICAL, SlackRecord::COLOR_DANGER),
array(Logger::ALERT, SlackRecord::COLOR_DANGER),
array(Logger::EMERGENCY,SlackRecord::COLOR_DANGER),
);
}