mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 04:37:38 +02:00
Merge branch '1.x'
This commit is contained in:
@@ -132,6 +132,20 @@ class NormalizerFormatter implements FormatterInterface
|
|||||||
'file' => $e->getFile().':'.$e->getLine(),
|
'file' => $e->getFile().':'.$e->getLine(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($e instanceof \SoapFault) {
|
||||||
|
if (isset($e->faultcode)) {
|
||||||
|
$data['faultcode'] = $e->faultcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($e->faultactor)) {
|
||||||
|
$data['faultactor'] = $e->faultactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($e->detail)) {
|
||||||
|
$data['detail'] = $e->detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$trace = $e->getTrace();
|
$trace = $e->getTrace();
|
||||||
foreach ($trace as $frame) {
|
foreach ($trace as $frame) {
|
||||||
if (isset($frame['file'])) {
|
if (isset($frame['file'])) {
|
||||||
|
@@ -72,7 +72,7 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
if (!preg_match('{^Y(([/_.-]?m)([/_.-]?d)?)?$}', $dateFormat)) {
|
if (!preg_match('{^Y(([/_.-]?m)([/_.-]?d)?)?$}', $dateFormat)) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Invalid date format - format must be one of '.
|
'Invalid date format - format must be one of '.
|
||||||
'RotatingFileHandler::FILE_PER_DAY ("Y-m-d"), RotatingFileHandler::FILE_PER_MONTH ("Y-m")'.
|
'RotatingFileHandler::FILE_PER_DAY ("Y-m-d"), RotatingFileHandler::FILE_PER_MONTH ("Y-m") '.
|
||||||
'or RotatingFileHandler::FILE_PER_YEAR ("Y"), or you can set one of the '.
|
'or RotatingFileHandler::FILE_PER_YEAR ("Y"), or you can set one of the '.
|
||||||
'date formats using slashes, underscores and/or dots instead of dashes.'
|
'date formats using slashes, underscores and/or dots instead of dashes.'
|
||||||
);
|
);
|
||||||
|
@@ -144,19 +144,25 @@ class SlackHandler extends SocketHandler
|
|||||||
'attachments' => [],
|
'attachments' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($this->formatter) {
|
||||||
|
$message = $this->formatter->format($record);
|
||||||
|
} else {
|
||||||
|
$message = $record['message'];
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->useAttachment) {
|
if ($this->useAttachment) {
|
||||||
$attachment = [
|
$attachment = [
|
||||||
'fallback' => $record['message'],
|
'fallback' => $message,
|
||||||
'color' => $this->getAttachmentColor($record['level']),
|
'color' => $this->getAttachmentColor($record['level']),
|
||||||
'fields' => [],
|
'fields' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->useShortAttachment) {
|
if ($this->useShortAttachment) {
|
||||||
$attachment['title'] = $record['level_name'];
|
$attachment['title'] = $record['level_name'];
|
||||||
$attachment['text'] = $record['message'];
|
$attachment['text'] = $message;
|
||||||
} else {
|
} else {
|
||||||
$attachment['title'] = 'Message';
|
$attachment['title'] = 'Message';
|
||||||
$attachment['text'] = $record['message'];
|
$attachment['text'] = $message;
|
||||||
$attachment['fields'][] = [
|
$attachment['fields'][] = [
|
||||||
'title' => 'Level',
|
'title' => 'Level',
|
||||||
'value' => $record['level_name'],
|
'value' => $record['level_name'],
|
||||||
@@ -206,7 +212,7 @@ class SlackHandler extends SocketHandler
|
|||||||
|
|
||||||
$dataArray['attachments'] = json_encode([$attachment]);
|
$dataArray['attachments'] = json_encode([$attachment]);
|
||||||
} else {
|
} else {
|
||||||
$dataArray['text'] = $record['message'];
|
$dataArray['text'] = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->iconEmoji) {
|
if ($this->iconEmoji) {
|
||||||
|
@@ -85,6 +85,33 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
], $formatted);
|
], $formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormatSoapFaultException()
|
||||||
|
{
|
||||||
|
if (!class_exists('SoapFault')) {
|
||||||
|
$this->markTestSkipped('Requires the soap extension');
|
||||||
|
}
|
||||||
|
|
||||||
|
$formatter = new NormalizerFormatter('Y-m-d');
|
||||||
|
$e = new \SoapFault('foo', 'bar', 'hello', 'world');
|
||||||
|
$formatted = $formatter->format(array(
|
||||||
|
'exception' => $e,
|
||||||
|
));
|
||||||
|
|
||||||
|
unset($formatted['exception']['trace']);
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'exception' => array(
|
||||||
|
'class' => 'SoapFault',
|
||||||
|
'message' => 'bar',
|
||||||
|
'code' => 0,
|
||||||
|
'file' => $e->getFile().':'.$e->getLine(),
|
||||||
|
'faultcode' => 'foo',
|
||||||
|
'faultactor' => 'hello',
|
||||||
|
'detail' => 'world',
|
||||||
|
),
|
||||||
|
), $formatted);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormatToStringExceptionHandle()
|
public function testFormatToStringExceptionHandle()
|
||||||
{
|
{
|
||||||
$formatter = new NormalizerFormatter('Y-m-d');
|
$formatter = new NormalizerFormatter('Y-m-d');
|
||||||
|
@@ -13,6 +13,7 @@ namespace Monolog\Handler;
|
|||||||
|
|
||||||
use Monolog\Test\TestCase;
|
use Monolog\Test\TestCase;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
use Monolog\Formatter\LineFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Greg Kedzierski <greg@gregkedzierski.com>
|
* @author Greg Kedzierski <greg@gregkedzierski.com>
|
||||||
@@ -57,6 +58,23 @@ class SlackHandlerTest extends TestCase
|
|||||||
$this->assertRegexp('/token=myToken&channel=channel1&username=Monolog&text=&attachments=.*$/', $content);
|
$this->assertRegexp('/token=myToken&channel=channel1&username=Monolog&text=&attachments=.*$/', $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWriteContentUsesFormatterIfProvided()
|
||||||
|
{
|
||||||
|
$this->createHandler('myToken', 'channel1', 'Monolog', false);
|
||||||
|
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||||
|
fseek($this->res, 0);
|
||||||
|
$content = fread($this->res, 1024);
|
||||||
|
|
||||||
|
$this->createHandler('myToken', 'channel1', 'Monolog', false);
|
||||||
|
$this->handler->setFormatter(new LineFormatter('foo--%message%'));
|
||||||
|
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test2'));
|
||||||
|
fseek($this->res, 0);
|
||||||
|
$content2 = fread($this->res, 1024);
|
||||||
|
|
||||||
|
$this->assertRegexp('/token=myToken&channel=channel1&username=Monolog&text=test1.*$/', $content);
|
||||||
|
$this->assertRegexp('/token=myToken&channel=channel1&username=Monolog&text=foo--test2.*$/', $content2);
|
||||||
|
}
|
||||||
|
|
||||||
public function testWriteContentWithEmoji()
|
public function testWriteContentWithEmoji()
|
||||||
{
|
{
|
||||||
$this->createHandler('myToken', 'channel1', 'Monolog', true, 'alien');
|
$this->createHandler('myToken', 'channel1', 'Monolog', true, 'alien');
|
||||||
|
Reference in New Issue
Block a user