Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed integer storing via mongodriver

  • Loading branch information...
commit 92ebd570414beea26b53f054486ff1957b67ada6 1 parent 2fe11ab
Vladimir Gorej (char0n) authored
View
8 src/main/php/helpers/LoggerLoggingEventBsonifier.php
@@ -44,11 +44,11 @@ class LoggerLoggingEventBsonifier {
public function bsonify(LoggerLoggingEvent $event) {
$timestampSec = (int) $event->getTimestamp();
$timestampUsec = (int) (($event->getTimestamp() - $timestampSec) * 1000000);
-
+
$document = new ArrayObject(array(
'timestamp' => new MongoDate($timestampSec, $timestampUsec),
'level' => $event->getLevel()->toString(),
- 'thread' => $event->getThreadName(),
+ 'thread' => (int) $event->getThreadName(),
'message' => $event->getMessage(),
'loggerName' => $event->getLoggerName()
));
@@ -69,7 +69,7 @@ protected function addLocationInformation(ArrayObject $document, LoggerLocationI
if ($locationInfo != null) {
$document['fileName'] = $locationInfo->getFileName();
$document['method'] = $locationInfo->getMethodName();
- $document['lineNumber'] = $locationInfo->getLineNumber();
+ $document['lineNumber'] = ($locationInfo->getLineNumber() == 'NA') ? 'NA' : (int) $locationInfo->getLineNumber();
$document['className'] = $locationInfo->getClassName();
}
}
@@ -108,4 +108,4 @@ protected function bsonifyThrowable(Exception $ex) {
return $bsonException;
}
}
-?>
+?>
View
37 src/test/php/helpers/LoggerLoggingEventBsonifierTest.php
@@ -112,5 +112,40 @@ public function testBsonifyThrowableInfoWithInnerException() {
$this->assertEquals('test exception inner', $bsonifiedEvent['exception']['innerException']['message']);
$this->assertContains('[internal function]: LoggerLoggingEventBsonifierTest', $bsonifiedEvent['exception']['stackTrace']);
}
+
+ public function testIsThreadInteger() {
+ $event = new LoggerLoggingEvent(
+ 'testFqcn',
+ self::$logger,
+ LoggerLevel::getLevelWarn(),
+ 'test message'
+ );
+ $bsonifiedEvent = self::$bsonifier->bsonify($event);
+ $this->assertTrue(is_int($bsonifiedEvent['thread']));
+ }
+
+ public function testIsLocationInfoLineNumberIntegerOrNA() {
+ $event = new LoggerLoggingEvent(
+ 'testFqcn',
+ self::$logger,
+ LoggerLevel::getLevelWarn(),
+ 'test message'
+ );
+ $bsonifiedEvent = self::$bsonifier->bsonify($event);
+ $this->assertTrue(is_int($bsonifiedEvent['lineNumber']) || $bsonifiedEvent['lineNumber'] == 'NA');
+ }
+
+ public function testIsThrowableInfoExceptionCodeInteger() {
+ $event = new LoggerLoggingEvent(
+ 'testFqcn',
+ self::$logger,
+ LoggerLevel::getLevelWarn(),
+ 'test message',
+ microtime(true),
+ new TestingException('test exeption', 1, new Exception('test exception inner', 2))
+ );
+ $bsonifiedEvent = self::$bsonifier->bsonify($event);
+ $this->assertTrue(is_int($bsonifiedEvent['exception']['code']));
+ }
}
-?>
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.