mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 20:27:31 +02:00
Fix issues highlighted by @stof on first code review
This commit is contained in:
@@ -15,7 +15,9 @@ use Monolog\Formatter\LineFormatter;
|
|||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends logs to Fleep.io using WebHook integrations
|
* Sends logs to Fleep.io using Webhook integrations
|
||||||
|
*
|
||||||
|
* You'll need a Fleep.io account to use this handler.
|
||||||
*
|
*
|
||||||
* @see https://fleep.io/integrations/webhooks/ Fleep Webhooks Documentation
|
* @see https://fleep.io/integrations/webhooks/ Fleep Webhooks Documentation
|
||||||
* @author Ando Roots <ando@sqroot.eu>
|
* @author Ando Roots <ando@sqroot.eu>
|
||||||
@@ -23,9 +25,6 @@ use Monolog\Logger;
|
|||||||
class FleepHookHandler extends AbstractProcessingHandler
|
class FleepHookHandler extends AbstractProcessingHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Fleep.io webhooks URI
|
|
||||||
*/
|
|
||||||
const HOOK_ENDPOINT = 'https://fleep.io/hook/';
|
const HOOK_ENDPOINT = 'https://fleep.io/hook/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,11 +51,10 @@ class FleepHookHandler extends AbstractProcessingHandler
|
|||||||
/**
|
/**
|
||||||
* Construct a new Fleep.io Handler.
|
* Construct a new Fleep.io Handler.
|
||||||
*
|
*
|
||||||
* You'll need a Fleep.op account to use this handler.
|
|
||||||
* For instructions on how to create a new web hook in your conversations
|
* For instructions on how to create a new web hook in your conversations
|
||||||
* see https://fleep.io/integrations/webhooks/
|
* see https://fleep.io/integrations/webhooks/
|
||||||
*
|
*
|
||||||
* @param string $token Webhook token (ex: mTZG6s-XRfKdNTJtpVyVaA)
|
* @param string $token Webhook token
|
||||||
* @param bool|int $level The minimum logging level at which this handler will be triggered
|
* @param bool|int $level The minimum logging level at which this handler will be triggered
|
||||||
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
||||||
* @throws \LogicException
|
* @throws \LogicException
|
||||||
@@ -73,14 +71,6 @@ class FleepHookHandler extends AbstractProcessingHandler
|
|||||||
parent::__construct($level, $bubble);
|
parent::__construct($level, $bubble);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getToken()
|
|
||||||
{
|
|
||||||
return $this->token;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -94,10 +84,9 @@ class FleepHookHandler extends AbstractProcessingHandler
|
|||||||
*
|
*
|
||||||
* Overloaded to remove empty context and extra arrays from the end of the log message.
|
* Overloaded to remove empty context and extra arrays from the end of the log message.
|
||||||
*
|
*
|
||||||
* @author Ando Roots <ando@sqroot.eu>
|
|
||||||
* @return LineFormatter
|
* @return LineFormatter
|
||||||
*/
|
*/
|
||||||
public function getDefaultFormatter()
|
protected function getDefaultFormatter()
|
||||||
{
|
{
|
||||||
return new LineFormatter(null, null, true, true);
|
return new LineFormatter(null, null, true, true);
|
||||||
|
|
||||||
@@ -106,7 +95,6 @@ class FleepHookHandler extends AbstractProcessingHandler
|
|||||||
/**
|
/**
|
||||||
* Handles a log record
|
* Handles a log record
|
||||||
*
|
*
|
||||||
* @author Ando Roots <ando@sqroot.eu>
|
|
||||||
* @param array $record
|
* @param array $record
|
||||||
*/
|
*/
|
||||||
protected function write(array $record)
|
protected function write(array $record)
|
||||||
@@ -118,7 +106,6 @@ class FleepHookHandler extends AbstractProcessingHandler
|
|||||||
/**
|
/**
|
||||||
* Prepares the record for sending to Fleep
|
* Prepares the record for sending to Fleep
|
||||||
*
|
*
|
||||||
* @author Ando Roots <ando@sqroot.eu>
|
|
||||||
* @param string $message The formatted log message to send
|
* @param string $message The formatted log message to send
|
||||||
*/
|
*/
|
||||||
protected function send($message)
|
protected function send($message)
|
||||||
@@ -137,7 +124,6 @@ class FleepHookHandler extends AbstractProcessingHandler
|
|||||||
/**
|
/**
|
||||||
* Sends a new Curl request
|
* Sends a new Curl request
|
||||||
*
|
*
|
||||||
* @author Ando Roots <ando@sqroot.eu>
|
|
||||||
* @param array $options Curl parameters, including the endpoint URL and POST payload
|
* @param array $options Curl parameters, including the endpoint URL and POST payload
|
||||||
*/
|
*/
|
||||||
protected function execCurl(array $options)
|
protected function execCurl(array $options)
|
||||||
@@ -154,7 +140,6 @@ class FleepHookHandler extends AbstractProcessingHandler
|
|||||||
/**
|
/**
|
||||||
* Adds or overwrites a curl option
|
* Adds or overwrites a curl option
|
||||||
*
|
*
|
||||||
* @author Ando Roots <ando@sqroot.eu>
|
|
||||||
* @param array $options An assoc array of Curl options, indexed by CURL_* constants
|
* @param array $options An assoc array of Curl options, indexed by CURL_* constants
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
|
@@ -58,7 +58,22 @@ class FleepHookHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testConstructorSetsExpectedDefaults()
|
public function testConstructorSetsExpectedDefaults()
|
||||||
{
|
{
|
||||||
$this->assertEquals(self::TOKEN, $this->handler->getToken());
|
// Test that the $token is saved when calling the constructor
|
||||||
|
$token = self::TOKEN;
|
||||||
|
$handler = $this->mockHandler(array('execCurl'));
|
||||||
|
$handler->expects($this->once())
|
||||||
|
->method('execCurl')
|
||||||
|
->with(
|
||||||
|
$this->callback(
|
||||||
|
function ($curlOpts) use ($token) {
|
||||||
|
return substr($curlOpts[CURLOPT_URL], -strlen($token)) === $token;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->sendLog($handler);
|
||||||
|
|
||||||
|
// Test that default values are assigned to $level and $bubble
|
||||||
$this->assertEquals(Logger::DEBUG, $this->handler->getLevel());
|
$this->assertEquals(Logger::DEBUG, $this->handler->getLevel());
|
||||||
$this->assertEquals(true, $this->handler->getBubble());
|
$this->assertEquals(true, $this->handler->getBubble());
|
||||||
}
|
}
|
||||||
@@ -102,7 +117,7 @@ class FleepHookHandlerTest extends TestCase
|
|||||||
$expectedFormatter = new LineFormatter(null, null, true, true);
|
$expectedFormatter = new LineFormatter(null, null, true, true);
|
||||||
$expected = $expectedFormatter->format($record);
|
$expected = $expectedFormatter->format($record);
|
||||||
|
|
||||||
$handlerFormatter = $this->handler->getDefaultFormatter();
|
$handlerFormatter = $this->handler->getFormatter();
|
||||||
$actual = $handlerFormatter->format($record);
|
$actual = $handlerFormatter->format($record);
|
||||||
|
|
||||||
$this->assertEquals($expected, $actual, 'Empty context and extra arrays should not be rendered');
|
$this->assertEquals($expected, $actual, 'Empty context and extra arrays should not be rendered');
|
||||||
|
Reference in New Issue
Block a user