Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We now log throwable #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/php/layouts/LoggerLayoutGelf.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,13 @@ public function getShortMessage(LoggerLoggingEvent $event) {
* @return string
*/
public function getFullMessage(LoggerLoggingEvent $event) {
$throwableInformation = $event->getThrowableInformation();
$throwableInformationString = '';
if(!is_null($throwableInformation)) {
$throwableInformationString = implode("\n", $throwableInformation->getStringRepresentation());
}
return $this->cleanNonUtfSymbols(
$event->getRenderedMessage()
$event->getRenderedMessage() . $throwableInformationString
);
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/php/layouts/LoggerLayoutGelfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ public function testShortMessageCutting() {

}

public function testMessageWithThrowable() {

$message = str_repeat("with Throwable\n", 40);
$exception = new \Exception('Test');
$expectedMessage = str_repeat("with Throwable\n", 40).$exception;
$event = new LoggerLoggingEvent(__CLASS__, new Logger("test"), LoggerLevel::getLevelFatal(), $message, null, $throwable = $exception);

$layout = new LoggerLayoutGelf();
$layout->activateOptions();

$expectedShortMessageLength = $layout->getShortMessageLength();
$this->assertEquals($expectedShortMessageLength, mb_strlen($layout->getShortMessage($event)));
$this->assertEquals($expectedMessage, $layout->getFullMessage($event));

}

public function testNonUnicodeCharsReplacement() {
$invalidUtf8String = str_repeat(chr(193), 10);
$event = LoggerTestHelper::getErrorEvent($invalidUtf8String);
Expand Down