/** * Adds an appender to the pool. * The appender must be named for this operation. * @param LoggerAppender $appender */ public static function add(LoggerAppender $appender) { $name = $appender->getName(); if (empty($name)) { trigger_error('log4php: Cannot add unnamed appender to pool.', E_USER_WARNING); return; } if (isset(self::$appenders[$name])) { trigger_error("log4php: Appender [{$name}] already exists in pool. Overwriting existing appender.", E_USER_WARNING); } self::$appenders[$name] = $appender; }
public function __construct($name = '') { parent::__construct($name); $this->logBuffer = array(); $this->logLimit = 50; $this->emitter = new Evenement\EventEmitter(); }
public function __construct($name = '') { parent::__construct($name); $this->host = self::DEFAULT_MONGO_URL_PREFIX . self::DEFAULT_MONGO_HOST; $this->port = self::DEFAULT_MONGO_PORT; $this->databaseName = self::DEFAULT_DB_NAME; $this->collectionName = self::DEFAULT_COLLECTION_NAME; }
/** * Add a {@link LoggerAppenderConsole} that uses * the {@link LoggerLayoutTTCC} to the root category. * * @param string $url not used here * @static */ function configure($url = null) { $root =& LoggerManager::getRootLogger(); $appender =& LoggerAppender::singleton('A1', 'LoggerAppenderConsole'); $layout = LoggerLayout::factory('LoggerLayoutTTCC'); $appender->setLayout($layout); $root->addAppender($appender); }
/** * Singleton * * @param string $name appender name * @param string $class create or get a reference instance of this class * @return LoggerAppender */ function singleton($name, $class = '') { static $instances; if (!empty($name)) { if (!isset($instances[$name])) { if (!empty($class)) { $appender = LoggerAppender::factory($name, $class); if ($appender !== null) { $instances[$name] = $appender; return $instances[$name]; } } return null; } return $instances[$name]; } return null; }
/** * Checks whether an appender is attached to this logger instance. * * @param LoggerAppender $appender * @return boolean */ public function isAttached(LoggerAppender $appender) { return isset($this->appenders[$appender->getName()]); }
/** * Is the appender passed as parameter attached to this category? * * @param LoggerAppender $appender */ public function isAttached($appender) { return isset($this->aai[$appender->getName()]); }
/** * Constructor. * * @param string $name appender name */ public function __construct($name = '') { parent::__construct($name); }
/** * Is the appender passed as parameter attached to this category? * * @param LoggerAppender $appender */ function isAttached($appender) { return in_array($appender->getName(), array_keys($this->aai)); }
public function reset() { $this->close(); parent::reset(); }
/** * Constructor. * * @param string $name appender name */ function __construct($name) { parent::__construct($name); }
/** * Constructor. * This apender doesn't require a layout. * @param string $name appender name */ public function __construct($name = '') { parent::__construct($name); $this->requiresLayout = false; }
/** * Parses filter config, creates the filter and adds it to the appender's * filter chain. * @param LoggerAppender $appender * @param array $config Filter configuration. */ private function createAppenderFilter(LoggerAppender $appender, $config) { $name = $appender->getName(); $class = $config['class']; if (!class_exists($class)) { $this->warn("Nonexistant filter class [{$class}] specified on appender [{$name}]. Skipping filter definition."); return; } $filter = new $class(); if (!$filter instanceof LoggerFilter) { $this->warn("Invalid filter class [{$class}] sepcified on appender [{$name}]. Skipping filter definition."); return; } if (isset($config['params'])) { $this->setOptions($filter, $config['params']); } $filter->activateOptions(); $appender->addFilter($filter); }
/** * @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); } else { $className = basename($class); if (!class_exists($className)) { @(include_once "{$class}.php"); } if (!class_exists($className)) { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LOGGER. " . "cannot find '{$className}'."); } else { if (in_array('getlogger', get_class_methods($className))) { $this->logger =& call_user_func(array($className, 'getlogger'), $loggerName); } else { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LOGGER. " . "class '{$className}' doesnt implement 'getLogger()' method."); } } } if ($this->logger !== null and isset($attribs['ADDITIVITY'])) { $additivity = LoggerOptionConverter::toBoolean($this->subst($attribs['ADDITIVITY']), true); $this->logger->setAdditivity($additivity); } } else { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LOGGER. Attribute 'name' is not set or is empty."); } $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE; break; case 'LEVEL': case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':LEVEL': case 'PRIORITY': case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':PRIORITY': if (!isset($attribs['VALUE'])) { LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL value not set"); break; } LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL value={$attribs['VALUE']}"); if ($this->logger === null) { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LEVEL. parent logger is null"); break; } switch (end($this->state)) { case LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE: $this->logger->setLevel(LoggerOptionConverter::toLevel($this->subst($attribs['VALUE']), $this->logger->getLevel())); LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL root level is now '{$attribs['VALUE']}' "); break; case LOG4PHP_LOGGER_DOM_CONFIGURATOR_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; case 'PARAM': case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':PARAM': LoggerLog::debug("LoggerDOMConfigurator::tagOpen() PARAM"); if (!isset($attribs['NAME'])) { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . "attribute 'name' not defined."); break; } if (!isset($attribs['VALUE'])) { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . "attribute 'value' not defined."); break; } switch (end($this->state)) { case LOG4PHP_LOGGER_DOM_CONFIGURATOR_APPENDER_STATE: if ($this->appender !== null) { $this->setter($this->appender, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE'])); } else { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . " trying to set property to a null appender."); } break; case LOG4PHP_LOGGER_DOM_CONFIGURATOR_LAYOUT_STATE: if ($this->layout !== null) { $this->setter($this->layout, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE'])); } else { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . " trying to set property to a null layout."); } break; case LOG4PHP_LOGGER_DOM_CONFIGURATOR_FILTER_STATE: if ($this->filter !== null) { $this->setter($this->filter, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE'])); } else { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . " trying to set property to a null filter."); } break; default: LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM state '{$this->state}' not allowed here"); } break; case 'RENDERER': case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':RENDERER': $renderedClass = $this->subst(@$attribs['RENDEREDCLASS']); $renderingClass = $this->subst(@$attribs['RENDERINGCLASS']); LoggerLog::debug("LoggerDOMConfigurator::tagOpen() RENDERER renderedClass='{$renderedClass}' renderingClass='{$renderingClass}'"); if (!empty($renderedClass) and !empty($renderingClass)) { $renderer = LoggerObjectRenderer::factory($renderingClass); if ($renderer === null) { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() RENDERER cannot instantiate '{$renderingClass}'"); } else { $this->repository->setRenderer($renderedClass, $renderer); } } else { LoggerLog::warn("LoggerDOMConfigurator::tagOpen() RENDERER renderedClass or renderingClass is empty"); } break; case 'ROOT': case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':ROOT': LoggerLog::debug("LoggerDOMConfigurator::tagOpen() ROOT"); $this->logger =& LoggerManager::getRootLogger(); $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE; break; } }
public function __construct($name = '') { parent::__construct($name); $this->firstAppend = true; }
public function __construct($name = '') { parent::__construct($name); $this->host = self::DEFAULT_MONGO_URL_PREFIX . self::DEFAULT_MONGO_HOST; $this->port = self::DEFAULT_MONGO_PORT; $this->databaseName = self::DEFAULT_DB_NAME; $this->collectionName = self::DEFAULT_COLLECTION_NAME; $this->timeout = self::DEFAULT_TIMEOUT_VALUE; $this->requiresLayout = false; }
/** * @param array $props array of properties * @param string $appenderName * @return LoggerAppender */ function &parseAppender($props, $appenderName) { $appender =& LoggerAppender::singleton($appenderName); if ($appender !== null) { LoggerLog::debug("LoggerPropertyConfigurator::parseAppender() " . "Appender [{$appenderName}] was already parsed."); return $appender; } // Appender was not previously initialized. $prefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_APPENDER_PREFIX . $appenderName; $layoutPrefix = $prefix . ".layout"; $appenderClass = @$props[$prefix]; if (!empty($appenderClass)) { $appender =& LoggerAppender::singleton($appenderName, $appenderClass); if ($appender === null) { LoggerLog::warn("LoggerPropertyConfigurator::parseAppender() " . "Could not instantiate appender named [{$appenderName}]."); return null; } } else { LoggerLog::warn("LoggerPropertyConfigurator::parseAppender() " . "Could not instantiate appender named [{$appenderName}] with null className."); return null; } $appender->setName($appenderName); if ($appender->requiresLayout()) { LoggerLog::debug("LoggerPropertyConfigurator::parseAppender() " . "Parsing layout section for [{$appenderName}]."); $layoutClass = @$props[$layoutPrefix]; $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); if (empty($layoutClass)) { LoggerLog::warn("LoggerPropertyConfigurator::parseAppender() " . "layout class is empty in '{$layoutPrefix}'. Using Simple layout"); $layout = LoggerLayout::factory('LoggerLayoutSimple'); } else { $layout = LoggerLayout::factory($layoutClass); if ($layout === null) { LoggerLog::warn("LoggerPropertyConfigurator::parseAppender() " . "cannot create layout '{$layoutClass}'. Using Simple layout"); $layout = LoggerLayout::factory('LoggerLayoutSimple'); } } LoggerLog::debug("LoggerPropertyConfigurator::parseAppender() " . "Parsing layout options for [{$appenderName}]."); LoggerPropertySetter::setPropertiesByObject($layout, $props, $layoutPrefix . "."); LoggerLog::debug("LoggerPropertyConfigurator::parseAppender() " . "End Parsing layout options for [{$appenderName}]."); $appender->setLayout($layout); } LoggerPropertySetter::setPropertiesByObject($appender, $props, $prefix . "."); LoggerLog::debug("LoggerPropertyConfigurator::parseAppender() " . "Parsed [{$appenderName}] options."); return $appender; }
public function close() { if ($this->getFlushOnShutdown()) { $this->sendLogsArrayToAMQP($this->logsStash); $this->cleanStashedLogs(); } $this->setAMQPExchange(null); $this->setAMQPConnection(null); parent::close(); }