public function testLoggerMDC()
 {
     $logger = new Logger("testLogger");
     $layout = new LoggerLayoutSimple();
     $this->assertEquals('testLogger [INFO] - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message"));
     LoggerMDC::put("foo", "bar");
     $this->assertEquals('testLogger [INFO] foo=bar - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message"));
     LoggerMDC::put("zip", "tar");
     $this->assertEquals('testLogger [INFO] foo=bar zip=tar - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message"));
     LoggerMDC::remove("foo");
     $this->assertEquals('testLogger [INFO] zip=tar - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message"));
     LoggerMDC::remove("zip");
     $this->assertEquals('testLogger [INFO] - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message"));
 }
Пример #2
0
 public function testPatterns()
 {
     // Create some data to test with
     LoggerMDC::put('key1', 'valueofkey1');
     LoggerMDC::put('key2', 'valueofkey2');
     LoggerMDC::put(3, 'valueofkey3');
     $expected = array('key1' => 'valueofkey1', 'key2' => 'valueofkey2', 3 => 'valueofkey3');
     $actual = LoggerMDC::getMap();
     self::assertSame($expected, $actual);
     $event = LoggerTestHelper::getInfoEvent("Test message");
     // Pattern with 1 key
     $actual = $this->formatEvent($event, $this->pattern1);
     $expected = "INFO  test: valueofkey1 Test message";
     self::assertEquals($expected, $actual);
     // Pattern with 2 keys
     $actual = $this->formatEvent($event, $this->pattern2);
     $expected = "INFO  test: valueofkey1 valueofkey2 Test message";
     self::assertEquals($expected, $actual);
     // Pattern with 3 keys (one numeric)
     $actual = $this->formatEvent($event, $this->pattern3);
     $expected = "INFO  test: valueofkey1 valueofkey2 valueofkey3 Test message";
     self::assertEquals($expected, $actual);
     // Pattern with non-existant key
     $actual = $this->formatEvent($event, $this->pattern4);
     $expected = "INFO  test:  Test message";
     self::assertEquals($expected, $actual);
     // Pattern with an empty key
     $actual = $this->formatEvent($event, $this->pattern5);
     $expected = "INFO  test: key1=valueofkey1, key2=valueofkey2, 3=valueofkey3 Test message";
     self::assertEquals($expected, $actual);
     // Test key removal
     LoggerMDC::remove('key1');
     $value = LoggerMDC::get('key1');
     self::assertEquals('', $value);
     // Pattern with 1 key, now removed
     $actual = $this->formatEvent($event, $this->pattern1);
     $expected = "INFO  test:  Test message";
     self::assertEquals($expected, $actual);
 }