diff --git a/src/main/php/layouts/LoggerLayoutGelf.php b/src/main/php/layouts/LoggerLayoutGelf.php index 8aa4a17..adf7291 100644 --- a/src/main/php/layouts/LoggerLayoutGelf.php +++ b/src/main/php/layouts/LoggerLayoutGelf.php @@ -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 ); } diff --git a/src/test/php/layouts/LoggerLayoutGelfTest.php b/src/test/php/layouts/LoggerLayoutGelfTest.php index 9e3efea..62ea18e 100644 --- a/src/test/php/layouts/LoggerLayoutGelfTest.php +++ b/src/test/php/layouts/LoggerLayoutGelfTest.php @@ -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);