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());
 }
Example #5
0
 /**
  * Set maximum depth of this diagnostic context. If the current
  * depth is smaller or equal to <var>maxDepth</var>, then no
  * action is taken.
  *
  * <p>This method is a convenient alternative to multiple 
  * {@link pop()} calls. Moreover, it is often the case that at 
  * the end of complex call sequences, the depth of the NDC is
  * unpredictable. The {@link setMaxDepth()} method circumvents
  * this problem.
  *
  * @param integer $maxDepth
  * @see getDepth()
  */
 public static function setMaxDepth($maxDepth)
 {
     $maxDepth = (int) $maxDepth;
     if (LoggerNDC::getDepth() > $maxDepth) {
         self::$stack = array_slice(self::$stack, 0, $maxDepth);
     }
 }
Example #6
0
 /**
  * This method returns the NDC for this event. It will return the
  * correct content even if the event was generated in a different
  * thread or even on a different machine. The {@link LoggerNDC::get()} method
  * should <b>never</b> be called directly.
  * @return string  
  */
 public function getNDC()
 {
     if ($this->ndcLookupRequired) {
         $this->ndcLookupRequired = false;
         $this->ndc = LoggerNDC::get();
     }
     return $this->ndc;
 }
 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);
 }
 /**
  * Set maximum depth of this diagnostic context. If the current
  * depth is smaller or equal to <var>maxDepth</var>, then no
  * action is taken.
  *
  * <p>This method is a convenient alternative to multiple 
  * {@link pop()} calls. Moreover, it is often the case that at 
  * the end of complex call sequences, the depth of the NDC is
  * unpredictable. The {@link setMaxDepth()} method circumvents
  * this problem.
  *
  * @param integer $maxDepth
  * @see getDepth()
  * @static
  */
 public static function setMaxDepth($maxDepth)
 {
     $maxDepth = (int) $maxDepth;
     if ($maxDepth <= self::HT_SIZE) {
         if (LoggerNDC::getDepth() > $maxDepth) {
             $GLOBALS['log4php.LoggerNDC.ht'] = array_slice($GLOBALS['log4php.LoggerNDC.ht'], $maxDepth);
         }
     }
 }
Example #9
0
<?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");
Example #10
0
 /**
  * Set maximum depth of this diagnostic context. If the current
  * depth is smaller or equal to <var>maxDepth</var>, then no
  * action is taken.
  *
  * <p>This method is a convenient alternative to multiple 
  * {@link pop()} calls. Moreover, it is often the case that at 
  * the end of complex call sequences, the depth of the NDC is
  * unpredictable. The {@link setMaxDepth()} method circumvents
  * this problem.
  *
  * @param integer $maxDepth
  * @see getDepth()
  * @static
  */
 function setMaxDepth($maxDepth)
 {
     LoggerLog::debug("LoggerNDC::setMaxDepth() maxDepth='{$maxDepth}'");
     $maxDepth = (int) $maxDepth;
     if ($maxDepth <= LOGGER_NDC_HT_SIZE) {
         if (LoggerNDC::getDepth() > $maxDepth) {
             $GLOBALS['log4php.LoggerNDC.ht'] = array_slice($GLOBALS['log4php.LoggerNDC.ht'], $maxDepth);
         }
         $GLOBALS['log4php.LoggerNDC.maxDepth'] = $maxDepth;
     }
 }
Example #11
0
 /**
  * This method returns the NDC for this event. It will return the
  * correct content even if the event was generated in a different
  * thread or even on a different machine. The {@link LoggerNDC::get()} method
  * should <b>never</b> be called directly.
  * @return string  
  */
 function getNDC()
 {
     if ($this->ndcLookupRequired) {
         $this->ndcLookupRequired = false;
         $this->ndc = implode(' ', LoggerNDC::get());
     }
     return $this->ndc;
 }
Example #12
0
 function __destruct()
 {
     if ($this->enabled && function_exists("xdebug_is_enabled") && xdebug_is_enabled()) {
     }
     LoggerNDC::pop();
     LoggerManager::shutdown();
 }