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()); }
/** * 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); } }
/** * 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); } } }
/** * 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; } }