public function testLoggerNDC() { LoggerNDC::clear(); $layout = new LoggerLayoutPattern('{ndc}'); $message = $layout->formatMessage(new Logger("root"), Logger::INFO, ''); $this->assertEquals('' . PHP_EOL, $message); LoggerNDC::push("ndc"); $message = $layout->formatMessage(new Logger("root"), Logger::INFO, ''); $this->assertEquals('ndc' . PHP_EOL, $message); }
public function testNDC() { LoggerNDC::push('foo'); LoggerNDC::push('bar'); $event = LoggerTestHelper::getErrorEvent("testmessage"); $layout = new LoggerLayoutXml(); $layout->activateOptions(); $actual = $layout->format($event); $thread = $event->getThreadName(); $timestamp = number_format($event->getTimeStamp() * 1000, 0, '', ''); $expected = "<log4php:event logger=\"test\" level=\"ERROR\" thread=\"{$thread}\" timestamp=\"{$timestamp}\">" . PHP_EOL . "<log4php:message><![CDATA[testmessage]]></log4php:message>" . PHP_EOL . "<log4php:NDC><![CDATA[<![CDATA[foo bar]]>]]></log4php:NDC>" . PHP_EOL . "<log4php:locationInfo class=\"LoggerLoggingEvent\" file=\"NA\" line=\"NA\" " . "method=\"getLocationInformation\" />" . PHP_EOL . "</log4php:event>" . PHP_EOL; self::assertEquals($expected, $actual); LoggerNDC::clear(); }
public function testLoggerNDC() { $logger = new Logger("testLogger"); $layout = new LoggerLayoutSimple(); $this->assertEquals('testLogger [INFO] - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message")); LoggerNDC::push("stack1"); $this->assertEquals('testLogger [INFO] stack1 - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message")); LoggerNDC::push("stack2"); $this->assertEquals('testLogger [INFO] stack1 stack2 - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message")); LoggerNDC::pop(); $this->assertEquals('testLogger [INFO] stack1 - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message")); LoggerNDC::pop(); $this->assertEquals('testLogger [INFO] - test message' . PHP_EOL, $layout->formatMessage($logger, Logger::INFO, "test message")); }
public function testMaxDepth() { // Clear stack; add some testing data LoggerNDC::clear(); LoggerNDC::push('1'); LoggerNDC::push('2'); LoggerNDC::push('3'); LoggerNDC::push('4'); LoggerNDC::push('5'); LoggerNDC::push('6'); self::assertSame('1 2 3 4 5 6', LoggerNDC::get()); // Edge case, should not change stack LoggerNDC::setMaxDepth(6); self::assertSame('1 2 3 4 5 6', LoggerNDC::get()); self::assertSame(6, LoggerNDC::getDepth()); LoggerNDC::setMaxDepth(3); self::assertSame('1 2 3', LoggerNDC::get()); self::assertSame(3, LoggerNDC::getDepth()); LoggerNDC::setMaxDepth(0); self::assertSame('', LoggerNDC::get()); self::assertSame(0, LoggerNDC::getDepth()); }
public function testNDC() { LoggerNDC::push('foo'); LoggerNDC::push('bar'); LoggerNDC::push('baz'); $converter = new LoggerPatternConverterNDC($this->info); $expected = 'foo bar baz'; $actual = $converter->convert($this->event); self::assertEquals($expected, $actual); }
<?php /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // START SNIPPET: doxia require_once dirname(__FILE__) . '/../../main/php/Logger.php'; Logger::configure(dirname(__FILE__) . '/../resources/ndc.properties'); $logger = Logger::getRootLogger(); LoggerNDC::push('conn=1234'); $logger->debug("just received a new connection"); LoggerNDC::push('client=ab23'); $logger->debug("some more messages that can"); $logger->debug("now related to a client"); LoggerNDC::pop(); LoggerNDC::pop(); $logger->debug("back and waiting for new connections");
<?php /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ require_once dirname(__FILE__) . '/../../main/php/Logger.php'; Logger::configure(dirname(__FILE__) . '/../resources/mdc.properties'); $logger = Logger::getRootLogger(); LoggerNDC::push('Context Message'); $logger->debug("Testing NDC"); LoggerNDC::pop();
function __construct() { //read enabled and level from config file $this->enabled = false; $this->level = self::ALL; $this->entries = array(); $this->l4plogger =& LoggerManager::getLogger(''); LoggerNDC::push($_SERVER['UNIQUE_ID']); }