[15162] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * log4php is a PHP port of the log4j java logging package.
|
---|
| 4 | *
|
---|
| 5 | * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
|
---|
| 6 | * <p>Design, strategies and part of the methods documentation are developed by log4j team
|
---|
| 7 | * (Ceki Gülcü as log4j project founder and
|
---|
| 8 | * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
|
---|
| 9 | *
|
---|
| 10 | * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
|
---|
| 11 | * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
|
---|
| 12 | *
|
---|
| 13 | * <p>This software is published under the terms of the LGPL License
|
---|
| 14 | * a copy of which has been included with this distribution in the LICENSE file.</p>
|
---|
| 15 | *
|
---|
| 16 | * @package log4php
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * LOG4PHP_DIR points to the log4php root directory.
|
---|
| 21 | *
|
---|
| 22 | * If not defined it will be set automatically when the first package classfile
|
---|
| 23 | * is included
|
---|
| 24 | *
|
---|
| 25 | * @var string
|
---|
| 26 | */
|
---|
| 27 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
|
---|
| 28 |
|
---|
| 29 | require_once(LOG4PHP_DIR . '/LoggerHierarchy.php');
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | * Use the LoggerManager to get Logger instances.
|
---|
| 33 | *
|
---|
| 34 | * @author VxR <vxr@vxr.it>
|
---|
| 35 | * @version $Revision: 1.18 $
|
---|
| 36 | * @package log4php
|
---|
| 37 | * @see Logger
|
---|
| 38 | * @todo create a configurator selector
|
---|
| 39 | */
|
---|
| 40 | class LoggerManager {
|
---|
| 41 |
|
---|
| 42 | /**
|
---|
| 43 | * check if a given logger exists.
|
---|
| 44 | *
|
---|
| 45 | * @param string $name logger name
|
---|
| 46 | * @static
|
---|
| 47 | * @return boolean
|
---|
| 48 | */
|
---|
| 49 | function exists($name)
|
---|
| 50 | {
|
---|
| 51 | $repository =& LoggerManager::getLoggerRepository();
|
---|
| 52 | return $repository->exists($name);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * Returns an array this whole Logger instances.
|
---|
| 57 | *
|
---|
| 58 | * @static
|
---|
| 59 | * @see Logger
|
---|
| 60 | * @return array
|
---|
| 61 | */
|
---|
| 62 | function getCurrentLoggers()
|
---|
| 63 | {
|
---|
| 64 | $repository =& LoggerManager::getLoggerRepository();
|
---|
| 65 | return $repository->getCurrentLoggers();
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
| 69 | * Returns the root logger.
|
---|
| 70 | *
|
---|
| 71 | * @static
|
---|
| 72 | * @return object
|
---|
| 73 | * @see LoggerRoot
|
---|
| 74 | */
|
---|
| 75 | function &getRootLogger()
|
---|
| 76 | {
|
---|
| 77 | $repository =& LoggerManager::getLoggerRepository();
|
---|
| 78 | return $repository->getRootLogger();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /**
|
---|
| 82 | * Returns the specified Logger.
|
---|
| 83 | *
|
---|
| 84 | * @param string $name logger name
|
---|
| 85 | * @param LoggerFactory $factory a {@link LoggerFactory} instance or null
|
---|
| 86 | * @static
|
---|
| 87 | * @return Logger
|
---|
| 88 | */
|
---|
| 89 | function &getLogger($name, $factory = null)
|
---|
| 90 | {
|
---|
| 91 | $repository =& LoggerManager::getLoggerRepository();
|
---|
| 92 | return $repository->getLogger($name, $factory);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | /**
|
---|
| 96 | * Returns the LoggerHierarchy.
|
---|
| 97 | *
|
---|
| 98 | * @static
|
---|
| 99 | * @return LoggerHierarchy
|
---|
| 100 | */
|
---|
| 101 | function &getLoggerRepository()
|
---|
| 102 | {
|
---|
| 103 | return LoggerHierarchy::singleton();
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * Destroy loggers object tree.
|
---|
| 109 | *
|
---|
| 110 | * @static
|
---|
| 111 | * @return boolean
|
---|
| 112 | */
|
---|
| 113 | function resetConfiguration()
|
---|
| 114 | {
|
---|
| 115 | $repository =& LoggerManager::getLoggerRepository();
|
---|
| 116 | return $repository->resetConfiguration();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /**
|
---|
| 120 | * Does nothing.
|
---|
| 121 | * @static
|
---|
| 122 | */
|
---|
| 123 | function setRepositorySelector($selector, $guard)
|
---|
| 124 | {
|
---|
| 125 | return;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | /**
|
---|
| 129 | * Safely close all appenders.
|
---|
| 130 | * @static
|
---|
| 131 | */
|
---|
| 132 | function shutdown()
|
---|
| 133 | {
|
---|
| 134 | $repository =& LoggerManager::getLoggerRepository();
|
---|
| 135 | return $repository->shutdown();
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | // ---------------------------------------------------------------------------
|
---|
| 140 | // ---------------------------------------------------------------------------
|
---|
| 141 | // ---------------------------------------------------------------------------
|
---|
| 142 |
|
---|
| 143 | if (!defined('LOG4PHP_DEFAULT_INIT_OVERRIDE')) {
|
---|
| 144 | if (isset($_ENV['log4php.defaultInitOverride'])) {
|
---|
| 145 | /**
|
---|
| 146 | * @ignore
|
---|
| 147 | */
|
---|
| 148 | define('LOG4PHP_DEFAULT_INIT_OVERRIDE',
|
---|
| 149 | LoggerOptionConverter::toBoolean($_ENV['log4php.defaultInitOverride'], false)
|
---|
| 150 | );
|
---|
| 151 | } elseif (isset($GLOBALS['log4php.defaultInitOverride'])) {
|
---|
| 152 | /**
|
---|
| 153 | * @ignore
|
---|
| 154 | */
|
---|
| 155 | define('LOG4PHP_DEFAULT_INIT_OVERRIDE',
|
---|
| 156 | LoggerOptionConverter::toBoolean($GLOBALS['log4php.defaultInitOverride'], false)
|
---|
| 157 | );
|
---|
| 158 | } else {
|
---|
| 159 | /**
|
---|
| 160 | * Controls init execution
|
---|
| 161 | *
|
---|
| 162 | * With this constant users can skip the default init procedure that is
|
---|
| 163 | * called when this file is included.
|
---|
| 164 | *
|
---|
| 165 | * <p>If it is not user defined, log4php tries to autoconfigure using (in order):</p>
|
---|
| 166 | *
|
---|
| 167 | * - the <code>$_ENV['log4php.defaultInitOverride']</code> variable.
|
---|
| 168 | * - the <code>$GLOBALS['log4php.defaultInitOverride']</code> global variable.
|
---|
| 169 | * - defaults to <i>false</i>
|
---|
| 170 | *
|
---|
| 171 | * @var boolean
|
---|
| 172 | */
|
---|
| 173 | define('LOG4PHP_DEFAULT_INIT_OVERRIDE', false);
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | if (!defined('LOG4PHP_CONFIGURATION')) {
|
---|
| 178 | if (isset($_ENV['log4php.configuration'])) {
|
---|
| 179 | /**
|
---|
| 180 | * @ignore
|
---|
| 181 | */
|
---|
| 182 | define('LOG4PHP_CONFIGURATION', trim($_ENV['log4php.configuration']));
|
---|
| 183 | } else {
|
---|
| 184 | /**
|
---|
| 185 | * Configuration file.
|
---|
| 186 | *
|
---|
| 187 | * <p>This constant tells configurator classes where the configuration
|
---|
| 188 | * file is located.</p>
|
---|
| 189 | * <p>If not set by user, log4php tries to set it automatically using
|
---|
| 190 | * (in order):</p>
|
---|
| 191 | *
|
---|
| 192 | * - the <code>$_ENV['log4php.configuration']</code> enviroment variable.
|
---|
| 193 | * - defaults to 'log4php.properties'.
|
---|
| 194 | *
|
---|
| 195 | * @var string
|
---|
| 196 | */
|
---|
| 197 | define('LOG4PHP_CONFIGURATION', 'C:\mydir\pdt\workspace\feature-module-paygent\data\downloads\module\mdl_paygent\log4php.properties');
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | if (!defined('LOG4PHP_CONFIGURATOR_CLASS')) {
|
---|
| 202 | if ( strtolower(substr( LOG4PHP_CONFIGURATION, -4 )) == '.xml') {
|
---|
| 203 | /**
|
---|
| 204 | * @ignore
|
---|
| 205 | */
|
---|
| 206 | define('LOG4PHP_CONFIGURATOR_CLASS', '/xml/LoggerDOMConfigurator');
|
---|
| 207 | } else {
|
---|
| 208 | /**
|
---|
| 209 | * Holds the configurator class name.
|
---|
| 210 | *
|
---|
| 211 | * <p>This constant is set with the fullname (path included but non the
|
---|
| 212 | * .php extension) of the configurator class that init procedure will use.</p>
|
---|
| 213 | * <p>If not set by user, log4php tries to set it automatically.</p>
|
---|
| 214 | * <p>If {@link LOG4PHP_CONFIGURATION} has '.xml' extension set the
|
---|
| 215 | * constants to '{@link LOG4PHP_DIR}/xml/{@link LoggerDOMConfigurator}'.</p>
|
---|
| 216 | * <p>Otherwise set the constants to
|
---|
| 217 | * '{@link LOG4PHP_DIR}/{@link LoggerPropertyConfigurator}'.</p>
|
---|
| 218 | *
|
---|
| 219 | * <p><b>Security Note</b>: classfile pointed by this constant will be brutally
|
---|
| 220 | * included with a:
|
---|
| 221 | * <code>@include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php");</code></p>
|
---|
| 222 | *
|
---|
| 223 | * @var string
|
---|
| 224 | */
|
---|
| 225 | define('LOG4PHP_CONFIGURATOR_CLASS', LOG4PHP_DIR . '/LoggerPropertyConfigurator');
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | if (!LOG4PHP_DEFAULT_INIT_OVERRIDE) {
|
---|
| 230 | if (!LoggerManagerDefaultInit())
|
---|
| 231 | LoggerLog::warn("LOG4PHP main() Default Init failed.");
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | /**
|
---|
| 235 | * Default init procedure.
|
---|
| 236 | *
|
---|
| 237 | * <p>This procedure tries to configure the {@link LoggerHierarchy} using the
|
---|
| 238 | * configurator class defined via {@link LOG4PHP_CONFIGURATOR_CLASS} that tries
|
---|
| 239 | * to load the configurator file defined in {@link LOG4PHP_CONFIGURATION}.
|
---|
| 240 | * If something goes wrong a warn is raised.</p>
|
---|
| 241 | * <p>Users can skip this procedure using {@link LOG4PHP_DEFAULT_INIT_OVERRIDE}
|
---|
| 242 | * constant.</p>
|
---|
| 243 | *
|
---|
| 244 | * @return boolean
|
---|
| 245 | */
|
---|
| 246 | function LoggerManagerDefaultInit()
|
---|
| 247 | {
|
---|
| 248 | $configuratorClass = basename(LOG4PHP_CONFIGURATOR_CLASS);
|
---|
| 249 | if (!class_exists($configuratorClass)) {
|
---|
| 250 | @include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php");
|
---|
| 251 | }
|
---|
| 252 | if (class_exists($configuratorClass)) {
|
---|
| 253 |
|
---|
| 254 | return call_user_func(array($configuratorClass, 'configure'), LOG4PHP_CONFIGURATION);
|
---|
| 255 |
|
---|
| 256 | } else {
|
---|
| 257 | LoggerLog::warn("LoggerManagerDefaultInit() Configurator '{$configuratorClass}' doesnt exists");
|
---|
| 258 | return false;
|
---|
| 259 | }
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | ?> |
---|