Skip to content

Commit

Permalink
Merge branch '1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jul 29, 2016
2 parents 20e09c7 + ced9284 commit 6b0d0c4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/Monolog/Formatter/NormalizerFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ protected function normalizeException(Throwable $e)
'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();
foreach ($trace as $frame) {
if (isset($frame['file'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Handler/RotatingFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function setFilenameFormat($filenameFormat, $dateFormat)
if (!preg_match('{^Y(([/_.-]?m)([/_.-]?d)?)?$}', $dateFormat)) {
throw new InvalidArgumentException(
'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 '.
'date formats using slashes, underscores and/or dots instead of dashes.'
);
Expand Down
14 changes: 10 additions & 4 deletions src/Monolog/Handler/SlackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,25 @@ protected function prepareContentData($record)
'attachments' => [],
];

if ($this->formatter) {
$message = $this->formatter->format($record);
} else {
$message = $record['message'];
}

if ($this->useAttachment) {
$attachment = [
'fallback' => $record['message'],
'fallback' => $message,
'color' => $this->getAttachmentColor($record['level']),
'fields' => [],
];

if ($this->useShortAttachment) {
$attachment['title'] = $record['level_name'];
$attachment['text'] = $record['message'];
$attachment['text'] = $message;
} else {
$attachment['title'] = 'Message';
$attachment['text'] = $record['message'];
$attachment['text'] = $message;
$attachment['fields'][] = [
'title' => 'Level',
'value' => $record['level_name'],
Expand Down Expand Up @@ -206,7 +212,7 @@ protected function prepareContentData($record)

$dataArray['attachments'] = json_encode([$attachment]);
} else {
$dataArray['text'] = $record['message'];
$dataArray['text'] = $message;
}

if ($this->iconEmoji) {
Expand Down
27 changes: 27 additions & 0 deletions tests/Monolog/Formatter/NormalizerFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,33 @@ public function testFormatExceptions()
], $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()
{
$formatter = new NormalizerFormatter('Y-m-d');
Expand Down
18 changes: 18 additions & 0 deletions tests/Monolog/Handler/SlackHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Monolog\Test\TestCase;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;

/**
* @author Greg Kedzierski <greg@gregkedzierski.com>
Expand Down Expand Up @@ -57,6 +58,23 @@ public function testWriteContent()
$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()
{
$this->createHandler('myToken', 'channel1', 'Monolog', true, 'alien');
Expand Down

0 comments on commit 6b0d0c4

Please sign in to comment.