本文整理汇总了PHP中LoggerOptionConverter::toLevel方法的典型用法代码示例。如果您正苦于以下问题:PHP LoggerOptionConverter::toLevel方法的具体用法?PHP LoggerOptionConverter::toLevel怎么用?PHP LoggerOptionConverter::toLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoggerOptionConverter
的用法示例。
在下文中一共展示了LoggerOptionConverter::toLevel方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setLevelToMatch
/**
* @param string $l the level to match
*/
public function setLevelToMatch($l)
{
if ($l instanceof LoggerLevel) {
$this->levelToMatch = $l;
} else {
$this->levelToMatch = LoggerOptionConverter::toLevel($l, null);
}
}
示例2: explode
/**
* This method must work for the root category as well.
*
* @param array $props array of properties
* @param Logger &$logger
* @param string $optionKey
* @param string $loggerName
* @param string $value
* @return Logger
*/
function &parseCategory($props, &$logger, $optionKey, $loggerName, $value)
{
LoggerLog::debug("LoggerPropertyConfigurator::parseCategory() " . "Parsing for [{$loggerName}] with value=[{$value}].");
// We must skip over ',' but not white space
$st = explode(',', $value);
// If value is not in the form ", appender.." or "", then we should set
// the level of the loggeregory.
if (!(@$value[0] == ',' || empty($value))) {
// just to be on the safe side...
if (sizeof($st) == 0) {
return;
}
$levelStr = current($st);
LoggerLog::debug("LoggerPropertyConfigurator::parseCategory() " . "Level token is [{$levelStr}].");
// If the level value is inherited, set category level value to
// null. We also check that the user has not specified inherited for the
// root category.
if ('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) {
if ($loggerName == LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME) {
LoggerLog::warn("LoggerPropertyConfigurator::parseCategory() " . "The root logger cannot be set to null.");
} else {
$logger->setLevel(null);
}
} else {
$logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug()));
}
}
// Begin by removing all existing appenders.
$logger->removeAllAppenders();
while ($appenderName = next($st)) {
$appenderName = trim($appenderName);
if (empty($appenderName)) {
continue;
}
LoggerLog::debug("LoggerPropertyConfigurator::parseCategory() " . "Parsing appender named [{$appenderName}].");
$appender =& $this->parseAppender($props, $appenderName);
if ($appender !== null) {
$logger->addAppender($appender);
}
}
}
示例3: setLevelMax
/**
* @param string $l the level max to match
*/
function setLevelMax($l)
{
$this->levelMax = LoggerOptionConverter::toLevel($l, null);
}
示例4: tagOpen
/**
* @param mixed $parser
* @param string $tag
* @param array $attribs
*
* @todo In 'LOGGER' case find a better way to detect 'getLogger()' method
*/
private function tagOpen($parser, $tag, $attribs)
{
switch ($tag) {
case 'CONFIGURATION':
case self::XMLNS . ':CONFIGURATION':
if (isset($attribs['THRESHOLD'])) {
$this->repository->setThreshold(LoggerOptionConverter::toLevel($this->subst($attribs['THRESHOLD']), $this->repository->getThreshold()));
}
break;
case 'APPENDER':
case self::XMLNS . ':APPENDER':
unset($this->appender);
$this->appender = null;
$name = $this->subst(@$attribs['NAME']);
$class = $this->subst(@$attribs['CLASS']);
$this->appender = LoggerAppenderPool::getAppenderFromPool($name, $class);
if (isset($attribs['THRESHOLD'])) {
$this->appender->setThreshold(LoggerOptionConverter::toLevel($this->subst($attribs['THRESHOLD']), $this->appender->getThreshold()));
}
$this->state[] = self::APPENDER_STATE;
break;
case 'APPENDER_REF':
case 'APPENDER-REF':
case self::XMLNS . ':APPENDER_REF':
case self::XMLNS . ':APPENDER-REF':
if (isset($attribs['REF']) and !empty($attribs['REF'])) {
$appenderName = $this->subst($attribs['REF']);
$appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
if ($appender !== null) {
switch (end($this->state)) {
case self::LOGGER_STATE:
case self::ROOT_STATE:
$this->logger->addAppender($appender);
break;
}
}
}
break;
case 'FILTER':
case self::XMLNS . ':FILTER':
unset($this->filter);
$this->filter = null;
$filterName = basename($this->subst(@$attribs['CLASS']));
if (!empty($filterName)) {
$this->filter = new $filterName();
$this->state[] = self::FILTER_STATE;
}
break;
case 'LAYOUT':
case self::XMLNS . ':LAYOUT':
$class = @$attribs['CLASS'];
$this->layout = LoggerReflectionUtils::createObject($this->subst($class));
$this->state[] = self::LAYOUT_STATE;
break;
case 'LOGGER':
case self::XMLNS . ':LOGGER':
// $this->logger is assigned by reference.
// Only '$this->logger=null;' destroys referenced object
unset($this->logger);
$this->logger = null;
$loggerName = $this->subst(@$attribs['NAME']);
if (!empty($loggerName)) {
$this->logger = $this->repository->getLogger($loggerName);
if ($this->logger !== null and isset($attribs['ADDITIVITY'])) {
$additivity = LoggerOptionConverter::toBoolean($this->subst($attribs['ADDITIVITY']), true);
$this->logger->setAdditivity($additivity);
}
}
$this->state[] = self::LOGGER_STATE;
break;
case 'LEVEL':
case self::XMLNS . ':LEVEL':
case 'PRIORITY':
case self::XMLNS . ':PRIORITY':
if (!isset($attribs['VALUE'])) {
// LoggerDOMConfigurator::tagOpen() LEVEL value not set
break;
}
if ($this->logger === null) {
// LoggerDOMConfigurator::tagOpen() LEVEL. parent logger is null
break;
}
switch (end($this->state)) {
case self::ROOT_STATE:
$this->logger->setLevel(LoggerOptionConverter::toLevel($this->subst($attribs['VALUE']), $this->logger->getLevel()));
break;
case self::LOGGER_STATE:
$this->logger->setLevel(LoggerOptionConverter::toLevel($this->subst($attribs['VALUE']), $this->logger->getLevel()));
break;
default:
//LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LEVEL state '{$this->state}' not allowed here");
}
break;
//.........这里部分代码省略.........
示例5: setThreshold
/**
* Set the threshold level of this appender.
*
* @param mixed $threshold can be a {@link LoggerLevel} object or a string.
* @see LoggerOptionConverter::toLevel()
*/
public function setThreshold($threshold)
{
if (is_string($threshold)) {
$this->threshold = LoggerOptionConverter::toLevel($threshold, null);
} else {
if ($threshold instanceof LoggerLevel) {
$this->threshold = $threshold;
}
}
}
示例6: parseCategory
/**
* This method must work for the root category as well.
*
* @param array $props array of properties
* @param Logger $logger
* @param string $optionKey
* @param string $loggerName
* @param string $value
* @return Logger
*/
private function parseCategory($props, Logger $logger, $optionKey, $loggerName, $value)
{
// We must skip over ',' but not white space
$st = explode(',', $value);
// If value is not in the form ", appender.." or "", then we should set
// the level of the loggeregory.
if (!(empty($value) || @$value[0] == ',')) {
// just to be on the safe side...
if (count($st) == 0) {
return;
}
$levelStr = current($st);
// If the level value is inherited, set category level value to
// null. We also check that the user has not specified inherited for the
// root category.
if ('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) {
if ($loggerName == self::INTERNAL_ROOT_NAME) {
// TODO: throw exception? "The root logger cannot be set to null."
} else {
$logger->setLevel(null);
}
} else {
$logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug()));
}
}
// TODO: removing should be done by the logger, if necessary and wanted
// $logger->removeAllAppenders();
while ($appenderName = next($st)) {
$appenderName = trim($appenderName);
if (empty($appenderName)) {
continue;
}
$appender = $this->parseAppender($props, $appenderName);
if ($appender !== null) {
$logger->addAppender($appender);
}
}
}
示例7: setLevelToMatch
/**
* @param string $l the level to match
*/
function setLevelToMatch($l)
{
$this->levelToMatch = LoggerOptionConverter::toLevel($l, null);
}
示例8: tagOpen
/**
* @param mixed $parser
* @param string $tag
* @param array $attribs
*
* @todo In 'LOGGER' case find a better way to detect 'getLogger()' method
*/
function tagOpen($parser, $tag, $attribs)
{
switch ($tag) {
case 'CONFIGURATION':
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':CONFIGURATION':
LoggerLog::debug("LoggerDOMConfigurator::tagOpen() CONFIGURATION");
if (isset($attribs['THRESHOLD'])) {
$this->repository->setThreshold(LoggerOptionConverter::toLevel($this->subst($attribs['THRESHOLD']), $this->repository->getThreshold()));
}
if (isset($attribs['DEBUG'])) {
$debug = LoggerOptionConverter::toBoolean($this->subst($attribs['DEBUG']), LoggerLog::internalDebugging());
$this->repository->debug = $debug;
LoggerLog::internalDebugging($debug);
LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LOG4PHP:CONFIGURATION. Internal Debug turned " . ($debug ? 'on' : 'off'));
}
break;
case 'APPENDER':
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':APPENDER':
unset($this->appender);
$this->appender = null;
$name = $this->subst(@$attribs['NAME']);
$class = $this->subst(@$attribs['CLASS']);
LoggerLog::debug("LoggerDOMConfigurator::tagOpen():tag=[{$tag}]:name=[{$name}]:class=[{$class}]");
$this->appender =& LoggerAppender::singleton($name, $class);
if ($this->appender === null) {
LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER cannot instantiate appender '{$name}'");
}
$this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_APPENDER_STATE;
break;
case 'APPENDER_REF':
case 'APPENDER-REF':
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':APPENDER_REF':
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':APPENDER-REF':
if (isset($attribs['REF']) and !empty($attribs['REF'])) {
$appenderName = $this->subst($attribs['REF']);
LoggerLog::debug("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref='{$appenderName}'");
$appender =& LoggerAppender::singleton($appenderName);
if ($appender !== null) {
switch (end($this->state)) {
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE:
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE:
$this->logger->addAppender($appender);
break;
}
} else {
LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref '{$appenderName}' points to a null appender");
}
} else {
LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref not set or empty");
}
break;
case 'FILTER':
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':FILTER':
LoggerLog::debug("LoggerDOMConfigurator::tagOpen() FILTER");
unset($this->filter);
$this->filter = null;
$filterName = basename($this->subst(@$attribs['CLASS']));
if (!empty($filterName)) {
if (!class_exists($filterName)) {
@(include_once LOG4PHP_DIR . "/varia/{$filterName}.php");
}
if (class_exists($filterName)) {
$this->filter = new $filterName();
} else {
LoggerLog::warn("LoggerDOMConfigurator::tagOpen() FILTER. class '{$filterName}' doesnt exist");
}
$this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_FILTER_STATE;
} else {
LoggerLog::warn("LoggerDOMConfigurator::tagOpen() FILTER filter name cannot be empty");
}
break;
case 'LAYOUT':
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':LAYOUT':
$class = @$attribs['CLASS'];
LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LAYOUT class='{$class}'");
$this->layout = LoggerLayout::factory($this->subst($class));
if ($this->layout === null) {
LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LAYOUT unable to instanciate class='{$class}'");
}
$this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_LAYOUT_STATE;
break;
case 'LOGGER':
case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':LOGGER':
// $this->logger is assigned by reference.
// Only '$this->logger=null;' destroys referenced object
unset($this->logger);
$this->logger = null;
$loggerName = $this->subst(@$attribs['NAME']);
if (!empty($loggerName)) {
LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LOGGER. name='{$loggerName}'");
$class = $this->subst(@$attribs['CLASS']);
if (empty($class)) {
$this->logger =& $this->repository->getLogger($loggerName);
//.........这里部分代码省略.........
示例9: doConfigure
private function doConfigure($url, LoggerHierarchy $hierarchy)
{
$config = (require $url);
// set threshold
if (isset($config['threshold'])) {
$hierarchy->setThreshold(LoggerOptionConverter::toLevel($config['threshold'], LoggerLevel::getLevelAll()));
}
// parse and create appenders
if (isset($config['appenders'])) {
foreach ($config['appenders'] as $appenderName => $appenderProperties) {
$appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderProperties['class']);
if ($appender->requiresLayout()) {
if (isset($appenderProperties['layout'])) {
if (isset($appenderProperties['layout']['class']) and !empty($appenderProperties['layout']['class'])) {
$layoutClass = $appenderProperties['layout']['class'];
} else {
$layoutClass = 'LoggerLayoutSimple';
}
$layout = LoggerReflectionUtils::createObject($layoutClass);
if ($layout === null) {
$layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple');
}
if ($layout instanceof LoggerLayoutPattern) {
$layout->setConversionPattern($appenderProperties['layout']['conversionPattern']);
}
$appender->setLayout($layout);
} else {
// TODO: throw exception?
}
}
}
}
// parse and create root logger
if (isset($config['rootLogger'])) {
$rootLogger = $hierarchy->getRootLogger();
if (isset($config['rootLogger']['level'])) {
$rootLogger->setLevel(LoggerOptionConverter::toLevel($config['rootLogger']['level'], LoggerLevel::getLevelDebug()));
if (isset($config['rootLogger']['appenders'])) {
foreach ($config['rootLogger']['appenders'] as $appenderName) {
$appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
if ($appender !== null) {
$rootLogger->addAppender($appender);
}
}
}
}
}
// parse and create loggers
if (isset($config['loggers'])) {
foreach ($config['loggers'] as $loggerName => $loggerProperties) {
if (is_string($loggerName)) {
$logger = $hierarchy->getLogger($loggerName);
if (isset($loggerProperties['level'])) {
$logger->setLevel(LoggerOptionConverter::toLevel($loggerProperties['level'], LoggerLevel::getLevelDebug()));
if (isset($loggerProperties['appenders'])) {
foreach ($loggerProperties['appenders'] as $appenderName) {
$appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
if ($appender !== null) {
$logger->addAppender($appender);
}
}
}
}
} else {
// TODO: throw exception
}
}
}
return true;
}
示例10: doConfigure
private function doConfigure($url, LoggerHierarchy $hierarchy)
{
if (!is_array($url)) {
$config = (require $url);
} else {
$config = $url;
}
// set threshold
if (isset($config['threshold'])) {
$hierarchy->setThreshold(LoggerOptionConverter::toLevel($config['threshold'], LoggerLevel::getLevelAll()));
}
// add renderes
if (isset($config['renderers'])) {
foreach ($config['renderers'] as $renderedClass => $renderingClass) {
$hierarchy->getRendererMap()->addRenderer($renderedClass, $renderingClass);
}
}
// parse and create appenders
if (isset($config['appenders'])) {
foreach ($config['appenders'] as $appenderName => $appenderProperties) {
$appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderProperties['class']);
// unset so that the property wont be drawn up again
unset($appenderProperties['class']);
if ($appender->requiresLayout()) {
if (isset($appenderProperties['layout'])) {
if (isset($appenderProperties['layout']['class']) and !empty($appenderProperties['layout']['class'])) {
$layoutClass = $appenderProperties['layout']['class'];
} else {
$layoutClass = 'LoggerLayoutSimple';
}
$layout = LoggerReflectionUtils::createObject($layoutClass);
if ($layout === null) {
$layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple');
}
if (isset($appenderProperties['file']) && method_exists($appender, 'setFileName')) {
$appender->setFile($appenderProperties['file'], true);
}
if ($layout instanceof LoggerLayoutPattern) {
$layout->setConversionPattern($appenderProperties['layout']['conversionPattern']);
}
$appender->setLayout($layout);
// unset so that the property wont be drawn up again
unset($appenderProperties['layout']);
} else {
// TODO: throw exception?
}
}
// set remaining properties and activate appender
$setter = new LoggerReflectionUtils($appender);
foreach ($appenderProperties as $key => $val) {
$setter->setProperty($key, $val);
}
$setter->activate();
}
}
// parse and create root logger
if (isset($config['rootLogger'])) {
$rootLogger = $hierarchy->getRootLogger();
if (isset($config['rootLogger']['level'])) {
$rootLogger->setLevel(LoggerOptionConverter::toLevel($config['rootLogger']['level'], LoggerLevel::getLevelDebug()));
if (isset($config['rootLogger']['appenders'])) {
foreach ($config['rootLogger']['appenders'] as $appenderName) {
$appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
if ($appender !== null) {
$rootLogger->addAppender($appender);
}
}
}
}
}
// parse and create loggers
if (isset($config['loggers'])) {
foreach ($config['loggers'] as $loggerName => $loggerProperties) {
if (is_string($loggerName)) {
$logger = $hierarchy->getLogger($loggerName);
if (isset($loggerProperties['level'])) {
$logger->setLevel(LoggerOptionConverter::toLevel($loggerProperties['level'], LoggerLevel::getLevelDebug()));
if (isset($loggerProperties['appenders'])) {
foreach ($loggerProperties['appenders'] as $appenderName) {
$appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
if ($appender !== null) {
$logger->addAppender($appender);
}
}
}
}
} else {
// TODO: throw exception
}
}
}
return true;
}
示例11: setThreshold
/**
* Set the threshold level of this appender.
*
* @param mixed $threshold can be a {@link LoggerLevel} object or a string.
* @see LoggerOptionConverter::toLevel()
*/
function setThreshold($threshold)
{
if (is_string($threshold)) {
$this->threshold = LoggerOptionConverter::toLevel($threshold, null);
} elseif (is_a($threshold, 'loggerlevel')) {
$this->threshold = $threshold;
}
}