Commit a34797c058facc66519a79015b1a48a9dd07e308

Authored by Conrad Vermeulen
1 parent d663dfc2

KTS-3268

"Logging"
Implemented. Added

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8717 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 67 changed files with 11343 additions and 248 deletions
config/dmsDefaults.php
... ... @@ -97,7 +97,6 @@ if (!defined('PATH_SEPARATOR')) {
97 97 }
98 98 }
99 99  
100   -require_once(KT_LIB_DIR . '/Log.inc');
101 100 require_once(KT_LIB_DIR . '/validation/customerror.php');
102 101  
103 102  
... ... @@ -136,53 +135,39 @@ class KTInit {
136 135 // {{{ setupLogging()
137 136 function setupLogging () {
138 137 global $default;
139   - require_once(KT_LIB_DIR . '/Log.inc');
140 138 $oKTConfig =& KTConfig::getSingleton();
141   -
142 139 if(!defined('APP_NAME')) {
143 140 define('APP_NAME', $oKTConfig->get('ui/appName', 'KnowledgeTree'));
144 141 }
145   - $logLevel = $default->logLevel;
146   - if (!is_numeric($logLevel)) {
147   - $logLevel = @constant($logLevel);
148   - if (is_null($logLevel)) {
149   - $logLevel = @constant('ERROR');
150   - }
151   - }
152   - $default->log = new KTLegacyLog($oKTConfig->get('urls/logDirectory'), $logLevel);
153   - $res = $default->log->initialiseLogFile();
154   - if (PEAR::isError($res)) {
155   - $this->handleInitError($res);
156   - // returns only in checkup
157   - return $res;
158   - }
159   - $default->queryLog = new KTLegacyLog($oKTConfig->get('urls/logDirectory'), $logLevel, 'query');
160   - $res = $default->queryLog->initialiseLogFile();
161   - if (PEAR::isError($res)) {
162   - $this->handleInitError($res);
163   - // returns only in checkup
164   - return $res;
165   - }
166   - $default->timerLog = new KTLegacyLog($oKTConfig->get('urls/logDirectory'), $logLevel, 'timer');
167   - $res = $default->timerLog->initialiseLogFile();
168   - if (PEAR::isError($res)) {
169   - $this->handleInitError($res);
170   - // returns only in checkup
171   - return $res;
172   - }
173 142  
174   - require_once('Log.php');
175   - $default->phpErrorLog =& Log::factory('composite');
  143 + define('KT_LOG4PHP_DIR', KT_DIR . '/thirdparty/apache-log4php/src/main/php' . DIRECTORY_SEPARATOR);
  144 + define('LOG4PHP_CONFIGURATION', KT_DIR . '/config/ktlog.ini');
  145 + define('LOG4PHP_DEFAULT_INIT_OVERRIDE', true);
176 146  
177   - if ($default->phpErrorLogFile) {
178   - $fileLog =& Log::factory('file', $oKTConfig->get('urls/logDirectory') . '/php_error_log', 'KT', array(), $logLevel);
179   - $default->phpErrorLog->addChild($fileLog);
180   - }
  147 + require_once(KT_LOG4PHP_DIR . 'LoggerManager.php');
  148 + require_once(KT_LOG4PHP_DIR . 'LoggerPropertyConfigurator.php');
181 149  
182   - if ($default->developmentWindowLog) {
183   - $windowLog =& Log::factory('win', 'LogWindow', 'BLAH');
184   - $default->phpErrorLog->addChild($windowLog);
185   - }
  150 + $configurator = new LoggerPropertyConfigurator();
  151 + $repository = LoggerManager::getLoggerRepository();
  152 + $properties = @parse_ini_file(LOG4PHP_CONFIGURATION);
  153 + $properties['log4php.appender.default'] = 'LoggerAppenderDailyFile';
  154 + $properties['log4php.appender.default.layout'] = 'LoggerPatternLayout';
  155 + $properties['log4php.appender.default.layout.conversionPattern'] = '%d{Y-m-d | H:i:s} | %p | %t | %r | %X{userid} | %X{db} | %c | %M | %m%n';
  156 + $properties['log4php.appender.default.datePattern'] = 'Y-m-d';
  157 + $properties['log4php.appender.default.file'] = KT_DIR . '/var/log/kt%s.log.txt';
  158 +
  159 + session_start();
  160 + $configurator->doConfigureProperties($properties, $repository);
  161 +
  162 + $userId = isset($_SESSION['userID'])?$_SESSION['userID']:'n/a';
  163 +
  164 + LoggerMDC::put('userid', $userId);
  165 + LoggerMDC::put('db', $oKTConfig->get('db/dbName'));
  166 +
  167 + $default->log = LoggerManager::getLogger('default');
  168 + $default->queryLog = LoggerManager::getLogger('sql');
  169 + $default->timerLog = LoggerManager::getLogger('timer');
  170 + $default->phpErrorLog = LoggerManager::getLogger('php');
186 171 }
187 172 // }}}
188 173  
... ... @@ -336,37 +321,35 @@ class KTInit {
336 321  
337 322  
338 323 static protected $handlerMapping = array(
339   - E_WARNING=>PEAR_LOG_WARNING,
340   - E_USER_WARNING=>PEAR_LOG_WARNING,
341   - E_NOTICE=>PEAR_LOG_NOTICE,
342   - E_USER_NOTICE=>PEAR_LOG_NOTICE,
343   - E_ERROR=>PEAR_LOG_ERR,
344   - E_USER_ERROR=>PEAR_LOG_ERR,
  324 + E_WARNING=>'warn',
  325 + E_USER_WARNING=>'warn',
  326 + E_NOTICE=>'info',
  327 + E_USER_NOTICE=>'info',
  328 + E_ERROR=>'error',
  329 + E_USER_ERROR=>'error'
345 330 );
346 331  
347 332 // {{{ handlePHPError()
348 333 static function handlePHPError($code, $message, $file, $line) {
349 334 global $default;
350 335  
  336 + $priority = 'info';
351 337 if (array_key_exists($code, KTInit::$handlerMapping))
352 338 {
353 339 $priority = KTInit::$handlerMapping[$code];
354 340 }
355   - else
  341 +
  342 + if (empty($priority))
356 343 {
357   - $priority = PEAR_LOG_INFO;
  344 + $priority = 'info';
358 345 }
359 346  
360 347 $msg = $message . ' in ' . $file . ' at line ' . $line;
361   - if ($priority == PEAR_LOG_ERR)
362   - {
363   - $default->log->error($msg);
364   - }
365 348  
366   - if (!empty($default->phpErrorLog)) {
367   - $default->phpErrorLog->log($msg, $priority);
  349 + if (isset($default->phpErrorLog))
  350 + {
  351 + $default->phpErrorLog->$priority($msg);
368 352 }
369   - return false;
370 353 }
371 354  
372 355 // }}}
... ...
config/ktlog.ini 0 โ†’ 100644
  1 +log4php.rootLogger = INFO, default
  2 +;log4php.logger.sql= DEBUG
  3 +;log4php.logger.timer= DEBUG
  4 +log4php.logger.php= ERROR
0 5 \ No newline at end of file
... ...
lib/Log.inc deleted
1   -<?php
2   -/**
3   - * $Id$
4   - *
5   - * File logging class.
6   - *
7   - * KnowledgeTree Community Edition
8   - * Document Management Made Simple
9   - * Copyright (C) 2008 KnowledgeTree Inc.
10   - * Portions copyright The Jam Warehouse Software (Pty) Limited
11   - *
12   - * This program is free software; you can redistribute it and/or modify it under
13   - * the terms of the GNU General Public License version 3 as published by the
14   - * Free Software Foundation.
15   - *
16   - * This program is distributed in the hope that it will be useful, but WITHOUT
17   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19   - * details.
20   - *
21   - * You should have received a copy of the GNU General Public License
22   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
23   - *
24   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
25   - * California 94120-7775, or email info@knowledgetree.com.
26   - *
27   - * The interactive user interfaces in modified source and object code versions
28   - * of this program must display Appropriate Legal Notices, as required under
29   - * Section 5 of the GNU General Public License version 3.
30   - *
31   - * In accordance with Section 7(b) of the GNU General Public License version 3,
32   - * these Appropriate Legal Notices must retain the display of the "Powered by
33   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
34   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
35   - * must display the words "Powered by KnowledgeTree" and retain the original
36   - * copyright notice.
37   - *
38   - */
39   -
40   -require_once(KT_LIB_DIR . '/database/datetime.inc');
41   -// define error levels
42   -define("DEBUG", 0);
43   -define("INFO", 1);
44   -define("ERROR", 2);
45   -
46   -class KTLegacyLog {
47   - /**
48   - * The minimum logging level- log everything with
49   - * this error level and higher
50   - */
51   - var $minimumLoggingLevel = INFO;
52   -
53   - /**
54   - * The directory to save logs to
55   - */
56   - var $logDirectory;
57   -
58   - /**
59   - * The file to log the output to
60   - */
61   - var $logFile;
62   -
63   - /**
64   - * Default constructor
65   - *
66   - * @param string the path to the logfile to write to
67   - * @param int the desired level to log at
68   - * @param string log file name prefix
69   - */
70   - function KTLegacyLog($logDirectory, $logLevel = INFO, $sLogFilePrefix = "log") {
71   - $this->logDirectory = $logDirectory;
72   - $this->minimumLoggingLevel = $logLevel;
73   - $this->sLogFilePrefix = $sLogFilePrefix;
74   - }
75   -
76   - static function running_user() {
77   - if (substr(PHP_OS, 0, 3) == "WIN") {
78   - return null;
79   - }
80   - if (extension_loaded("posix")) {
81   - $uid = posix_getuid();
82   - $userdetails = posix_getpwuid($uid);
83   - return $userdetails['name'];
84   - }
85   - if (file_exists('/usr/bin/whoami')) {
86   - return exec('/usr/bin/whoami');
87   - }
88   - if (file_exists('/usr/bin/id')) {
89   - return exec('/usr/bin/id -nu');
90   - }
91   - return null;
92   - }
93   -
94   - /**
95   - * Creates the log file from the current datetime
96   - */
97   - function initialiseLogFile() {
98   - global $default;
99   - $user = $this->running_user();
100   - if (!file_exists($this->logDirectory)) {
101   - $res = @mkdir($this->logDirectory, 0755);
102   - if ($res === false) {
103   - return new PEAR_Error('Failed to create log directory (check permissions)');
104   - }
105   - }
106   -
107   - if ($user) {
108   - $this->logFile = sprintf("%s/%s-%s.%s.txt", $this->logDirectory, $this->sLogFilePrefix, date("Y-m-d"), $user);
109   - } else {
110   - $this->logFile = sprintf("%s/%s-%s.txt", $this->logDirectory, $this->sLogFilePrefix, date("Y-m-d"));
111   - }
112   - if (!file_exists($this->logFile)) {
113   - $res = @touch($this->logFile);
114   - if ($res === false) {
115   - return new PEAR_Error('Failed to create log file ' . $this->logFile . ' (check permissions)');
116   - }
117   - }
118   - if (!is_writable($this->logFile)) {
119   - return new PEAR_Error('Cannot write to log file ' . $this->logFile . ' (check permissions)');
120   - }
121   - }
122   -
123   - /**
124   - * Log a debug entry
125   - *
126   - * @param string the message to write to the log file
127   - */
128   - function debug($logEntry) {
129   - $this->writeLog($this->prefixEntry($logEntry, "DEBUG"), DEBUG);
130   - }
131   -
132   - /**
133   - * Log an info entry
134   - *
135   - * @param string the message to write to the log file
136   - */
137   - function info($logEntry) {
138   - $this->writeLog($this->prefixEntry($logEntry, "INFO"), INFO);
139   - }
140   -
141   - /**
142   - * Log an error entry
143   - *
144   - * @param string the message to write to the log file
145   - */
146   - function error($logEntry) {
147   - $this->writeLog($this->prefixEntry($logEntry, "ERROR"), ERROR);
148   - }
149   -
150   - /**
151   - * Writes to the log file, checking that the log level is within
152   - * the minimum logging level
153   - *
154   - * @param string the message to write to the log file
155   - * @param int the error level to log at
156   - */
157   - function writeLog($logEntry, $logLevel) {
158   - if ($logLevel >= $this->minimumLoggingLevel) {
159   - if (@$fp = fopen($this->logFile, "a")) {
160   - fwrite($fp, $logEntry);
161   - }
162   - @fclose($fp);
163   - }
164   - }
165   -
166   - /**
167   - * Prefixes the log entry with the current date time, the logging level
168   - * and the page that called it
169   - *
170   - * @param string the message to write to the log file
171   - * @param int the error level to log at
172   - */
173   - function prefixEntry($logEntry, $logLevel) {
174   - return getCurrentDateTime() . " (" . getenv("REMOTE_ADDR") . ") $logLevel: $logEntry\n";
175   - }
176   -}
177   -?>
lib/cache/cache.inc.php
... ... @@ -6,31 +6,31 @@
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2008 KnowledgeTree Inc.
8 8 * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23 23 * California 94120-7775, or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 30 * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
34 34 * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 */
... ... @@ -69,7 +69,7 @@ class KTCache {
69 69 }
70 70  
71 71 $aOptions['cacheDir'] = $oKTConfig->get('cache/cacheDirectory') . "/";
72   - $user = KTLegacyLog::running_user();
  72 + $user = KTUtil::running_user();
73 73 if ($user) {
74 74 $aOptions['cacheDir'] .= $user . '/';
75 75 }
... ...
lib/database/dbutil.inc
... ... @@ -67,8 +67,9 @@ class DBUtil {
67 67 $sQuery = $query;
68 68 }
69 69 $res = $db->query($sQuery, $aParams);
70   - if ($default->queryLog) {
71   - $default->queryLog->debug('Query: ' . DBUtil::lastQuery($db));
  70 + if ($default->queryLog->isDebugEnabled())
  71 + {
  72 + $default->queryLog->debug(DBUtil::lastQuery($db));
72 73 }
73 74 if (PEAR::isError($res))
74 75 {
... ... @@ -129,8 +130,12 @@ class DBUtil {
129 130  
130 131 function logQueryError($query, $result) {
131 132 global $default;
132   - $default->log->error('Problem Query: ' . $query);
133   - $default->log->error('Problem: ' . $result->getMessage());
  133 + if (!$default->queryLog->isDebugEnabled())
  134 + {
  135 + // if debug is enabled, the query is already logged.
  136 + $default->queryLog->error($query);
  137 + }
  138 + $default->log->error('Query error: ' . $result->getMessage());
134 139 }
135 140  
136 141 function runQueries($aQueries, $db = null) {
... ... @@ -153,7 +158,8 @@ class DBUtil {
153 158 // $default->log->debug('AutoInsert called for table ' . $sTable);
154 159 $db =& DBUtil::getDB();
155 160 $res = $db->autoExecute($sTable, $aFieldValues);
156   - if ($default->queryLog) {
  161 + if ($default->queryLog->isDebugEnabled())
  162 + {
157 163 $default->queryLog->debug('Query: ' . DBUtil::lastQuery($db));
158 164 }
159 165 if ($res === DB_OK) {
... ...
thirdparty/apache-log4php/INSTALL 0 โ†’ 100644
  1 + Licensed to the Apache Software Foundation (ASF) under one or more
  2 + contributor license agreements. See the NOTICE file distributed with
  3 + this work for additional information regarding copyright ownership.
  4 + The ASF licenses this file to You under the Apache License, Version 2.0
  5 + (the "License"); you may not use this file except in compliance with
  6 + the License. You may obtain a copy of the License at
  7 +
  8 + http://www.apache.org/licenses/LICENSE-2.0
  9 +
  10 + Unless required by applicable law or agreed to in writing, software
  11 + distributed under the License is distributed on an "AS IS" BASIS,
  12 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + See the License for the specific language governing permissions and
  14 + limitations under the License.
  15 +
  16 +------------------------------------------------------------------------------
  17 + INSTALLATION
  18 +------------------------------------------------------------------------------
  19 +
  20 +1. Before starting installing this package check if the following external
  21 + programs are installed:
  22 +
  23 + a. PHP (version 4.2.x or above).
  24 + For logging location infos (see src/log4php/spi/LoggerLocationInfo.php)
  25 + for details) a PHP version >= 4.3.0 must be installed
  26 +
  27 +2. Extract the tarball to a dir (ex: {YOUR_PATH}).
  28 +
  29 + If you want to include log4php under an include_path dir
  30 + consider step (a).
  31 +
  32 + If you want to include log4php wherever You want consider
  33 + step (b).
  34 +
  35 + a. Create a log4php dir under an include_path.
  36 + Copy '{YOUR_PATH}/src/log4php' under an '{an_include_path}/log4php'.
  37 +
  38 + define LOG4PHP_DIR as follow (recommended):
  39 +
  40 + define('LOG4PHP_DIR', 'log4php');
  41 +
  42 + or use directly:
  43 +
  44 + require_once('log4php/LoggerManager.php');
  45 +
  46 + LOG4PHP_DIR will be set automatically to '{an_include_path}/log4php'
  47 + (with path expansion).
  48 +
  49 + b. Copy '{YOUR_PATH}/src/log4php' to the dir where You want log4php will
  50 + reside (ex: {MY_LOG4PHP_PATH}).
  51 + Define the constant 'LOG4PHP_DIR' to '{MY_LOG4PHP_PATH}' and use
  52 +
  53 + require_once( LOG4PHP_DIR . '/LoggerManager.php' );
  54 +
  55 + or directly:
  56 +
  57 + require_once( '{MY_LOG4PHP_PATH}/LoggerManager.php' );
  58 +
  59 + and LOG4PHP_DIR will be set automatically with
  60 + '{MY_LOG4PHP_PATH}' (with path expansion).
  61 +
  62 +3. That's all!
  63 +
  64 +------------------------------------------------------------------------------
  65 + $Revision: 609885 $
  66 +------------------------------------------------------------------------------
  67 +
0 68 \ No newline at end of file
... ...
thirdparty/apache-log4php/LICENSE 0 โ†’ 100644
  1 + Apache License
  2 + Version 2.0, January 2004
  3 + http://www.apache.org/licenses/
  4 +
  5 + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
  6 +
  7 + 1. Definitions.
  8 +
  9 + "License" shall mean the terms and conditions for use, reproduction,
  10 + and distribution as defined by Sections 1 through 9 of this document.
  11 +
  12 + "Licensor" shall mean the copyright owner or entity authorized by
  13 + the copyright owner that is granting the License.
  14 +
  15 + "Legal Entity" shall mean the union of the acting entity and all
  16 + other entities that control, are controlled by, or are under common
  17 + control with that entity. For the purposes of this definition,
  18 + "control" means (i) the power, direct or indirect, to cause the
  19 + direction or management of such entity, whether by contract or
  20 + otherwise, or (ii) ownership of fifty percent (50%) or more of the
  21 + outstanding shares, or (iii) beneficial ownership of such entity.
  22 +
  23 + "You" (or "Your") shall mean an individual or Legal Entity
  24 + exercising permissions granted by this License.
  25 +
  26 + "Source" form shall mean the preferred form for making modifications,
  27 + including but not limited to software source code, documentation
  28 + source, and configuration files.
  29 +
  30 + "Object" form shall mean any form resulting from mechanical
  31 + transformation or translation of a Source form, including but
  32 + not limited to compiled object code, generated documentation,
  33 + and conversions to other media types.
  34 +
  35 + "Work" shall mean the work of authorship, whether in Source or
  36 + Object form, made available under the License, as indicated by a
  37 + copyright notice that is included in or attached to the work
  38 + (an example is provided in the Appendix below).
  39 +
  40 + "Derivative Works" shall mean any work, whether in Source or Object
  41 + form, that is based on (or derived from) the Work and for which the
  42 + editorial revisions, annotations, elaborations, or other modifications
  43 + represent, as a whole, an original work of authorship. For the purposes
  44 + of this License, Derivative Works shall not include works that remain
  45 + separable from, or merely link (or bind by name) to the interfaces of,
  46 + the Work and Derivative Works thereof.
  47 +
  48 + "Contribution" shall mean any work of authorship, including
  49 + the original version of the Work and any modifications or additions
  50 + to that Work or Derivative Works thereof, that is intentionally
  51 + submitted to Licensor for inclusion in the Work by the copyright owner
  52 + or by an individual or Legal Entity authorized to submit on behalf of
  53 + the copyright owner. For the purposes of this definition, "submitted"
  54 + means any form of electronic, verbal, or written communication sent
  55 + to the Licensor or its representatives, including but not limited to
  56 + communication on electronic mailing lists, source code control systems,
  57 + and issue tracking systems that are managed by, or on behalf of, the
  58 + Licensor for the purpose of discussing and improving the Work, but
  59 + excluding communication that is conspicuously marked or otherwise
  60 + designated in writing by the copyright owner as "Not a Contribution."
  61 +
  62 + "Contributor" shall mean Licensor and any individual or Legal Entity
  63 + on behalf of whom a Contribution has been received by Licensor and
  64 + subsequently incorporated within the Work.
  65 +
  66 + 2. Grant of Copyright License. Subject to the terms and conditions of
  67 + this License, each Contributor hereby grants to You a perpetual,
  68 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
  69 + copyright license to reproduce, prepare Derivative Works of,
  70 + publicly display, publicly perform, sublicense, and distribute the
  71 + Work and such Derivative Works in Source or Object form.
  72 +
  73 + 3. Grant of Patent License. Subject to the terms and conditions of
  74 + this License, each Contributor hereby grants to You a perpetual,
  75 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
  76 + (except as stated in this section) patent license to make, have made,
  77 + use, offer to sell, sell, import, and otherwise transfer the Work,
  78 + where such license applies only to those patent claims licensable
  79 + by such Contributor that are necessarily infringed by their
  80 + Contribution(s) alone or by combination of their Contribution(s)
  81 + with the Work to which such Contribution(s) was submitted. If You
  82 + institute patent litigation against any entity (including a
  83 + cross-claim or counterclaim in a lawsuit) alleging that the Work
  84 + or a Contribution incorporated within the Work constitutes direct
  85 + or contributory patent infringement, then any patent licenses
  86 + granted to You under this License for that Work shall terminate
  87 + as of the date such litigation is filed.
  88 +
  89 + 4. Redistribution. You may reproduce and distribute copies of the
  90 + Work or Derivative Works thereof in any medium, with or without
  91 + modifications, and in Source or Object form, provided that You
  92 + meet the following conditions:
  93 +
  94 + (a) You must give any other recipients of the Work or
  95 + Derivative Works a copy of this License; and
  96 +
  97 + (b) You must cause any modified files to carry prominent notices
  98 + stating that You changed the files; and
  99 +
  100 + (c) You must retain, in the Source form of any Derivative Works
  101 + that You distribute, all copyright, patent, trademark, and
  102 + attribution notices from the Source form of the Work,
  103 + excluding those notices that do not pertain to any part of
  104 + the Derivative Works; and
  105 +
  106 + (d) If the Work includes a "NOTICE" text file as part of its
  107 + distribution, then any Derivative Works that You distribute must
  108 + include a readable copy of the attribution notices contained
  109 + within such NOTICE file, excluding those notices that do not
  110 + pertain to any part of the Derivative Works, in at least one
  111 + of the following places: within a NOTICE text file distributed
  112 + as part of the Derivative Works; within the Source form or
  113 + documentation, if provided along with the Derivative Works; or,
  114 + within a display generated by the Derivative Works, if and
  115 + wherever such third-party notices normally appear. The contents
  116 + of the NOTICE file are for informational purposes only and
  117 + do not modify the License. You may add Your own attribution
  118 + notices within Derivative Works that You distribute, alongside
  119 + or as an addendum to the NOTICE text from the Work, provided
  120 + that such additional attribution notices cannot be construed
  121 + as modifying the License.
  122 +
  123 + You may add Your own copyright statement to Your modifications and
  124 + may provide additional or different license terms and conditions
  125 + for use, reproduction, or distribution of Your modifications, or
  126 + for any such Derivative Works as a whole, provided Your use,
  127 + reproduction, and distribution of the Work otherwise complies with
  128 + the conditions stated in this License.
  129 +
  130 + 5. Submission of Contributions. Unless You explicitly state otherwise,
  131 + any Contribution intentionally submitted for inclusion in the Work
  132 + by You to the Licensor shall be under the terms and conditions of
  133 + this License, without any additional terms or conditions.
  134 + Notwithstanding the above, nothing herein shall supersede or modify
  135 + the terms of any separate license agreement you may have executed
  136 + with Licensor regarding such Contributions.
  137 +
  138 + 6. Trademarks. This License does not grant permission to use the trade
  139 + names, trademarks, service marks, or product names of the Licensor,
  140 + except as required for reasonable and customary use in describing the
  141 + origin of the Work and reproducing the content of the NOTICE file.
  142 +
  143 + 7. Disclaimer of Warranty. Unless required by applicable law or
  144 + agreed to in writing, Licensor provides the Work (and each
  145 + Contributor provides its Contributions) on an "AS IS" BASIS,
  146 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  147 + implied, including, without limitation, any warranties or conditions
  148 + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
  149 + PARTICULAR PURPOSE. You are solely responsible for determining the
  150 + appropriateness of using or redistributing the Work and assume any
  151 + risks associated with Your exercise of permissions under this License.
  152 +
  153 + 8. Limitation of Liability. In no event and under no legal theory,
  154 + whether in tort (including negligence), contract, or otherwise,
  155 + unless required by applicable law (such as deliberate and grossly
  156 + negligent acts) or agreed to in writing, shall any Contributor be
  157 + liable to You for damages, including any direct, indirect, special,
  158 + incidental, or consequential damages of any character arising as a
  159 + result of this License or out of the use or inability to use the
  160 + Work (including but not limited to damages for loss of goodwill,
  161 + work stoppage, computer failure or malfunction, or any and all
  162 + other commercial damages or losses), even if such Contributor
  163 + has been advised of the possibility of such damages.
  164 +
  165 + 9. Accepting Warranty or Additional Liability. While redistributing
  166 + the Work or Derivative Works thereof, You may choose to offer,
  167 + and charge a fee for, acceptance of support, warranty, indemnity,
  168 + or other liability obligations and/or rights consistent with this
  169 + License. However, in accepting such obligations, You may act only
  170 + on Your own behalf and on Your sole responsibility, not on behalf
  171 + of any other Contributor, and only if You agree to indemnify,
  172 + defend, and hold each Contributor harmless for any liability
  173 + incurred by, or claims asserted against, such Contributor by reason
  174 + of your accepting any such warranty or additional liability.
  175 +
  176 + END OF TERMS AND CONDITIONS
  177 +
  178 + APPENDIX: How to apply the Apache License to your work.
  179 +
  180 + To apply the Apache License to your work, attach the following
  181 + boilerplate notice, with the fields enclosed by brackets "[]"
  182 + replaced with your own identifying information. (Don't include
  183 + the brackets!) The text should be enclosed in the appropriate
  184 + comment syntax for the file format. We also recommend that a
  185 + file or class name and description of purpose be included on the
  186 + same "printed page" as the copyright notice for easier
  187 + identification within third-party archives.
  188 +
  189 + Copyright [yyyy] [name of copyright owner]
  190 +
  191 + Licensed under the Apache License, Version 2.0 (the "License");
  192 + you may not use this file except in compliance with the License.
  193 + You may obtain a copy of the License at
  194 +
  195 + http://www.apache.org/licenses/LICENSE-2.0
  196 +
  197 + Unless required by applicable law or agreed to in writing, software
  198 + distributed under the License is distributed on an "AS IS" BASIS,
  199 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  200 + See the License for the specific language governing permissions and
  201 + limitations under the License.
... ...
thirdparty/apache-log4php/NOTICE 0 โ†’ 100644
  1 +Apache log4php
  2 +Copyright 2004-2007 The Apache Software Foundation
  3 +
  4 +This product includes software developed by
  5 +The Apache Software Foundation (http://www.apache.org/).
  6 +
... ...
thirdparty/apache-log4php/README 0 โ†’ 100644
  1 +Apache log4php is an effort undergoing incubation at The Apache
  2 +Software Foundation (ASF), sponsored by the Logging Services Project.
  3 +Incubation is required of all newly accepted projects until a further
  4 +review indicates that the infrastructure, communications, and
  5 +decision making process have stabilized in a manner consistent
  6 +with other successful ASF projects. While incubation status
  7 +is not necessarily a reflection of the completeness or
  8 +stability of the code, it does indicate that the project has yet
  9 +to be fully endorsed by the ASF.
... ...
thirdparty/apache-log4php/TODO 0 โ†’ 100644
  1 + Licensed to the Apache Software Foundation (ASF) under one or more
  2 + contributor license agreements. See the NOTICE file distributed with
  3 + this work for additional information regarding copyright ownership.
  4 + The ASF licenses this file to You under the Apache License, Version 2.0
  5 + (the "License"); you may not use this file except in compliance with
  6 + the License. You may obtain a copy of the License at
  7 +
  8 + http://www.apache.org/licenses/LICENSE-2.0
  9 +
  10 + Unless required by applicable law or agreed to in writing, software
  11 + distributed under the License is distributed on an "AS IS" BASIS,
  12 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + See the License for the specific language governing permissions and
  14 + limitations under the License.
  15 +
  16 +
  17 +
  18 +
  19 +TODO
  20 +====
  21 +
  22 +General
  23 +-------
  24 +
  25 + o Compare log4php 1.0 with log4j 1.3 (see http://wiki.apache.org/logging-log4j/Log4jv13Features)
  26 + o Define supported PHP 5 versions
  27 + o Investigate JMS (javax.jms.Message)
  28 + o Integration with PHPMQ? (see http://sourceforge.net/projects/phpmq/)
  29 +
  30 +New features
  31 +------------
  32 +
  33 +Appenders:
  34 +
  35 + o Chainsaw integration (see http://logging.apache.org/log4j/docs/chainsaw.html)
  36 + o LoggerAppenderNagios (see http://freshmeat.net/projects/nagiosappender/)
  37 + o LoggerAppenderMunin ?
  38 + o New LoggerAppenderDB? Should support as many RDBMS's out there. Probably PDO (see http://php.net/pdo)
  39 + o LoggerAppenderFeed
  40 + - with AtomLayout / RssLayout
  41 + o Windows Event stuff...
  42 + o LoggerAppenderTelnet
  43 + o LoggarAppenderUDP
  44 + o LoggerAppenderJMS
  45 + o LoggerAppenderSNMPTrap
  46 + o LoggerAppenderNNTP
  47 + o LoggerAppenderICMP
  48 + o LoggerAppenderSyslog
  49 + - add option to log to another syslog server?
  50 +
  51 +Plugins: a powerful mechanism for log4php users to add/extend log4php operating on the LoggerRepository
  52 +
  53 + o PluginEvent
  54 + o PluginRegistry
  55 + o PluginSkeleton
  56 +
  57 +Receivers: can be thought of as the opposite of Appenders
  58 +
  59 + o CustomSQLDBReceiver
  60 + o DBReceiver
  61 + o SocketHubReceiver
  62 + o SocketReceiver
  63 + o LogFilePatternReceiver
  64 + o UDPReceiver
  65 + o XMLSocketReceiver
  66 +
  67 +Watchdogs: will watch a "source" for changed/updated configuration data
  68 +
  69 +New filters:
  70 + o ExpressionFilter
  71 + o ReflectionFilter
  72 + o PropertyFilter
  73 + o MapFilter
  74 + o LocationInfoFilter
  75 + o AndFilter
  76 +
  77 +Configuration
  78 +-------------
  79 +Change LoggerDOMConfigurator to use the DOM extension (see http://php.net/dom)
  80 +
  81 +Testing
  82 +-------
  83 +Complete unit test suite
  84 +
  85 +Documentation
  86 +-------------
  87 +Porting log4j manual with examples (see http://logging.apache.org/log4j/docs/manual.html)
  88 +
... ...
thirdparty/apache-log4php/build.xml 0 โ†’ 100644
  1 +<!--
  2 + Licensed to the Apache Software Foundation (ASF) under one or more
  3 + contributor license agreements. See the NOTICE file distributed with
  4 + this work for additional information regarding copyright ownership.
  5 + The ASF licenses this file to You under the Apache License, Version 2.0
  6 + (the "License"); you may not use this file except in compliance with
  7 + the License. You may obtain a copy of the License at
  8 +
  9 + http://www.apache.org/licenses/LICENSE-2.0
  10 +
  11 + Unless required by applicable law or agreed to in writing, software
  12 + distributed under the License is distributed on an "AS IS" BASIS,
  13 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 + See the License for the specific language governing permissions and
  15 + limitations under the License.
  16 +
  17 +-->
  18 +<project name="log4php" default="compile">
  19 +
  20 + <property name="svnrepo.url" value="https://svn.apache.org/repos/asf"/>
  21 + <property name="svnsite.url" value="${svnrepo.url}/incubator/log4php/site"/>
  22 + <available property="svn-available" file="target/site-deploy/.svn"/>
  23 +
  24 + <!-- Use Maven 2 to build or manually place ant-contrib (http://ant-contrib.sf.net) on path -->
  25 + <taskdef name="foreach" classname="net.sf.antcontrib.logic.ForEach" />
  26 +
  27 + <target name="compile-file">
  28 + <exec executable="php" failonerror="true">
  29 + <arg value="-l"/>
  30 + <arg value="${src.php}"/>
  31 + </exec>
  32 + </target>
  33 +
  34 + <target name="compile">
  35 + <foreach target="compile-file" param="src.php">
  36 + <path>
  37 + <fileset dir="." includes="src/main/php/**/*.php"/>
  38 + </path>
  39 + </foreach>
  40 + </target>
  41 +
  42 + <target name="test-compile">
  43 + <foreach target="compile-file" param="src.php">
  44 + <path>
  45 + <fileset dir="." includes="src/test/php/**/*.php"/>
  46 + <fileset dir="." includes="src/examples/php/**/*.php"/>
  47 + </path>
  48 + </foreach>
  49 + </target>
  50 +
  51 + <target name="php-file">
  52 + <exec executable="php" failonerror="true" dir="target">
  53 + <arg value="-f"/>
  54 + <arg value="${src.php}"/>
  55 + </exec>
  56 + </target>
  57 +
  58 + <target name="test">
  59 + <!-- PHPUnit3 must be installed for this to work.
  60 + See http://www.phpunit.de -->
  61 + <!-- TODO: change dir to "target", needs changes in some tests -->
  62 + <mkdir dir="target"/>
  63 + <exec executable="PHPUnit" failonerror="true" dir="src/test/php">
  64 + <arg value="AllTests"/>
  65 + <arg value="AllTests.php"/>
  66 + </exec>
  67 + <foreach target="php-file" param="src.php">
  68 + <path>
  69 + <fileset dir="." includes="src/examples/php/**/*.php" excludes="**/server.php"/>
  70 + </path>
  71 + </foreach>
  72 + </target>
  73 +
  74 + <target name="apidocs">
  75 + <!-- PHPDoc must be installed for this to work. -->
  76 + <mkdir dir="target/site/apidocs"/>
  77 + <exec executable="phpdoc" failonerror="true">
  78 + <arg value="-d"/>
  79 + <arg value="src/main/php"/>
  80 + <arg value="-t"/>
  81 + <arg value="target/site/apidocs"/>
  82 + </exec>
  83 + </target>
  84 +
  85 +
  86 + <target name="fixcrlf">
  87 + <fixcrlf srcdir="." includes="**/*.php, **/*.xml, **/*.properties, **/*.ini" tab="remove"/>
  88 + </target>
  89 +
  90 + <target name="checkout-site" unless="svn-available">
  91 + <exec executable="svn">
  92 + <arg value="co"/>
  93 + <arg value="${svnsite.url}"/>
  94 + <arg value="target/site-deploy"/>
  95 + </exec>
  96 + </target>
  97 +
  98 + <target name="update-site" if="svn-available">
  99 + <exec executable="svn" dir="target/site-deploy" failonerror="true">
  100 + <arg value="update"/>
  101 + </exec>
  102 + </target>
  103 +
  104 + <target name="post-site" depends="checkout-site, update-site"/>
  105 +
  106 + <target name="mime=html">
  107 + <exec executable="svn">
  108 + <arg value="propset"/>
  109 + <arg value="svn:mime-type"/>
  110 + <arg value="text/html"/>
  111 + <arg value="${src.html}"/>
  112 + </exec>
  113 + </target>
  114 +
  115 + <target name="mime=css">
  116 + <exec executable="svn">
  117 + <arg value="propset"/>
  118 + <arg value="svn:mime-type"/>
  119 + <arg value="text/css"/>
  120 + <arg value="${src.css}"/>
  121 + </exec>
  122 + </target>
  123 +
  124 + <target name="site-deploy">
  125 + <!-- Add any new files (and generate innocuous warnings for the existing content) -->
  126 + <delete file="target/site-deploy/svn-commit.tmp~"/>
  127 + <exec executable="bash" dir="target/site-deploy" failonerror="true">
  128 + <arg line='-c "svn add --force *"'/>
  129 + </exec>
  130 + <foreach target="mime=html" param="src.html">
  131 + <path>
  132 + <fileset dir="target/site-deploy" includes="**/*.html"/>
  133 + </path>
  134 + </foreach>
  135 + <foreach target="mime=css" param="src.css">
  136 + <path>
  137 + <fileset dir="target/site-deploy" includes="**/*.css"/>
  138 + </path>
  139 + </foreach>
  140 + <!-- requires that SVN_EDITOR, VISUAL or EDITOR being set to edit commit description -->
  141 + <exec executable="svn" dir="target/site-deploy" failonerror="true">
  142 + <arg value="commit"/>
  143 + </exec>
  144 + </target>
  145 +
  146 +</project>
... ...
thirdparty/apache-log4php/pom.xml 0 โ†’ 100644
  1 +<!--
  2 + Licensed to the Apache Software Foundation (ASF) under one or more
  3 + contributor license agreements. See the NOTICE file distributed with
  4 + this work for additional information regarding copyright ownership.
  5 + The ASF licenses this file to You under the Apache License, Version 2.0
  6 + (the "License"); you may not use this file except in compliance with
  7 + the License. You may obtain a copy of the License at
  8 +
  9 + http://www.apache.org/licenses/LICENSE-2.0
  10 +
  11 + Unless required by applicable law or agreed to in writing, software
  12 + distributed under the License is distributed on an "AS IS" BASIS,
  13 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 + See the License for the specific language governing permissions and
  15 + limitations under the License.
  16 +
  17 +-->
  18 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  19 + <modelVersion>4.0.0</modelVersion>
  20 + <groupId>log4j</groupId>
  21 + <artifactId>apache-log4php</artifactId>
  22 + <packaging>jar</packaging>
  23 + <version>2.0-SNAPSHOT</version>
  24 + <name>Apache log4php.</name>
  25 + <description>Logging framework for PHP.</description>
  26 + <url>http://incubator.apache.org:80/log4php</url>
  27 + <issueManagement>
  28 + <system>JIRA</system>
  29 + <url>http://issues.apache.org/jira/</url>
  30 + </issueManagement>
  31 +<mailingLists>
  32 + <mailingList>
  33 + <name>log4php-user</name>
  34 + <subscribe>log4php-user-subscribe@logging.apache.org</subscribe>
  35 + <unsubscribe>log4php-user-unsubscribe@logging.apache.org</unsubscribe>
  36 + <post>log4php-user@logging.apache.org</post>
  37 + <archive>http://mail-archives.apache.org/mod_mbox/logging-log4php-user/</archive>
  38 + <otherArchives>
  39 + <otherArchive>http://markmail.org/search/list:org.apache.logging.log4php-user</otherArchive>
  40 + </otherArchives>
  41 + </mailingList>
  42 + <mailingList>
  43 + <name>log4php-dev</name>
  44 + <subscribe>log4php-dev-subscribe@logging.apache.org</subscribe>
  45 + <unsubscribe>log4php-dev-unsubscribe@logging.apache.org</unsubscribe>
  46 + <post>log4php-dev@logging.apache.org</post>
  47 + <archive>http://mail-archives.apache.org/mod_mbox/logging-log4php-dev/</archive>
  48 + <otherArchives>
  49 + <otherArchive>http://markmail.org/search/list:org.apache.logging.log4php-dev</otherArchive>
  50 + </otherArchives>
  51 + </mailingList>
  52 +</mailingLists>
  53 +<licenses>
  54 + <license>
  55 + <name>Apache License, Version 2.0</name>
  56 + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  57 + <distribution>repo</distribution>
  58 + </license>
  59 +</licenses>
  60 +<scm>
  61 + <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/log4php</connection>
  62 + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/log4php</developerConnection>
  63 + <url>http://svn.apache.org/viewcvs.cgi/incubator/log4php</url>
  64 +</scm>
  65 +<organization>
  66 + <name>Apache Software Foundation</name>
  67 + <url>http://www.apache.org</url>
  68 +</organization>
  69 +<build>
  70 + <plugins>
  71 + <plugin>
  72 + <artifactId>maven-surefire-plugin</artifactId>
  73 + <configuration>
  74 + <workingDirectory>target</workingDirectory>
  75 + </configuration>
  76 + </plugin>
  77 + <plugin>
  78 + <artifactId>maven-antrun-plugin</artifactId>
  79 + <executions>
  80 + <execution>
  81 + <phase>compile</phase>
  82 + <id>compile</id>
  83 + <configuration>
  84 + <tasks>
  85 + <ant target="compile"/>
  86 + </tasks>
  87 + </configuration>
  88 + <goals>
  89 + <goal>run</goal>
  90 + </goals>
  91 + </execution>
  92 + <execution>
  93 + <phase>test-compile</phase>
  94 + <id>test-compile</id>
  95 + <configuration>
  96 + <tasks>
  97 + <ant target="test-compile"/>
  98 + </tasks>
  99 + </configuration>
  100 + <goals>
  101 + <goal>run</goal>
  102 + </goals>
  103 + </execution>
  104 + <execution>
  105 + <phase>test</phase>
  106 + <id>test</id>
  107 + <configuration>
  108 + <tasks>
  109 + <ant target="test"/>
  110 + </tasks>
  111 + </configuration>
  112 + <goals>
  113 + <goal>run</goal>
  114 + </goals>
  115 + </execution>
  116 + <execution>
  117 + <phase>site</phase>
  118 + <id>site</id>
  119 + <configuration>
  120 + <tasks>
  121 + <ant target="apidocs"/>
  122 + <taskdef name="replaceregexp" classname="org.apache.tools.ant.taskdefs.optional.ReplaceRegExp" />
  123 + <replaceregexp file="target/site/source-repository.html" match="/tags/[^ &quot;&apos;&lt;]*" replace="/trunk" flags="g"/>
  124 + <replaceregexp match="Documentation generated on .* by " replace="Documentation generated by " flags="g">
  125 + <fileset dir="target/site/apidocs" includes="**/*.html"/>
  126 + </replaceregexp>
  127 +
  128 + </tasks>
  129 + </configuration>
  130 + <goals>
  131 + <goal>run</goal>
  132 + </goals>
  133 + </execution>
  134 + <execution>
  135 + <phase>post-site</phase>
  136 + <id>post-site</id>
  137 + <configuration>
  138 + <tasks>
  139 + <ant target="post-site"/>
  140 + </tasks>
  141 + </configuration>
  142 + <goals>
  143 + <goal>run</goal>
  144 + </goals>
  145 + </execution>
  146 + <execution>
  147 + <phase>site-deploy</phase>
  148 + <id>site-deploy</id>
  149 + <configuration>
  150 + <tasks>
  151 + <ant target="site-deploy"/>
  152 + </tasks>
  153 + </configuration>
  154 + <goals>
  155 + <goal>run</goal>
  156 + </goals>
  157 + </execution>
  158 + </executions>
  159 + <dependencies>
  160 + <dependency>
  161 + <groupId>ant</groupId>
  162 + <artifactId>ant-nodeps</artifactId>
  163 + <version>1.6.5</version>
  164 + </dependency>
  165 + <dependency>
  166 + <groupId>ant-contrib</groupId>
  167 + <artifactId>ant-contrib</artifactId>
  168 + <version>1.0b2</version>
  169 + </dependency>
  170 + </dependencies>
  171 + </plugin>
  172 + <plugin>
  173 + <artifactId>maven-assembly-plugin</artifactId>
  174 + <configuration>
  175 + <descriptors>
  176 + <descriptor>src/assembly/bin.xml</descriptor>
  177 + </descriptors>
  178 + <appendAssemblyId>false</appendAssemblyId>
  179 + </configuration>
  180 + <executions>
  181 + <execution>
  182 + <goals>
  183 + <goal>assembly</goal>
  184 + </goals>
  185 + </execution>
  186 + </executions>
  187 + </plugin>
  188 + <plugin>
  189 + <groupId>org.codehaus.mojo</groupId>
  190 + <artifactId>rat-maven-plugin</artifactId>
  191 + </plugin>
  192 + </plugins>
  193 +</build>
  194 + <dependencies>
  195 + </dependencies>
  196 + <reporting>
  197 + <excludeDefaults>true</excludeDefaults>
  198 + <plugins>
  199 + <plugin>
  200 + <artifactId>maven-project-info-reports-plugin</artifactId>
  201 + <reportSets>
  202 + <reportSet>
  203 + <reports>
  204 + <report>scm</report>
  205 + <report>dependencies</report>
  206 + <report>issue-tracking</report>
  207 + <report>mailing-list</report>
  208 + <report>license</report>
  209 + </reports>
  210 + </reportSet>
  211 + </reportSets>
  212 + </plugin>
  213 + <plugin>
  214 + <artifactId>maven-release-plugin</artifactId>
  215 + <configuration>
  216 + <goals>site-deploy</goals>
  217 + </configuration>
  218 + </plugin>
  219 + <plugin>
  220 + <artifactId>maven-changes-plugin</artifactId>
  221 + <reportSets>
  222 + <reportSet>
  223 + <reports>
  224 + <report>changes-report</report>
  225 + </reports>
  226 + </reportSet>
  227 + </reportSets>
  228 + <configuration>
  229 + <issueLinkTemplate>%URL%/browse/%ISSUE%</issueLinkTemplate>
  230 + </configuration>
  231 + </plugin>
  232 + </plugins>
  233 + </reporting>
  234 + <distributionManagement>
  235 + <site>
  236 + <id>logging.site</id>
  237 + <url>file:///${user.dir}/target/site-deploy</url>
  238 + </site>
  239 + </distributionManagement>
  240 +</project>
... ...
thirdparty/apache-log4php/src/assembly/bin.xml 0 โ†’ 100644
  1 +<!--
  2 + Licensed to the Apache Software Foundation (ASF) under one or more
  3 + contributor license agreements. See the NOTICE file distributed with
  4 + this work for additional information regarding copyright ownership.
  5 + The ASF licenses this file to You under the Apache License, Version 2.0
  6 + (the "License"); you may not use this file except in compliance with
  7 + the License. You may obtain a copy of the License at
  8 +
  9 + http://www.apache.org/licenses/LICENSE-2.0
  10 +
  11 + Unless required by applicable law or agreed to in writing, software
  12 + distributed under the License is distributed on an "AS IS" BASIS,
  13 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 + See the License for the specific language governing permissions and
  15 + limitations under the License.
  16 +
  17 +-->
  18 +<assembly>
  19 + <id>src</id>
  20 + <formats>
  21 + <format>zip</format>
  22 + <format>tar.gz</format>
  23 + </formats>
  24 + <baseDirectory>apache-log4php-${project.version}-incubating</baseDirectory>
  25 + <includeSiteDirectory>true</includeSiteDirectory>
  26 + <fileSets>
  27 + <fileSet>
  28 + <includes>
  29 + <include>LICENSE</include>
  30 + <include>NOTICE</include>
  31 + <include>README</include>
  32 + <include>INSTALL</include>
  33 + <include>build.xml</include>
  34 + <include>pom.xml</include>
  35 + <include>src/**</include>
  36 + </includes>
  37 + </fileSet>
  38 + </fileSets>
  39 +
  40 +</assembly>
... ...
thirdparty/apache-log4php/src/changes/changes.xml 0 โ†’ 100644
  1 +<!--
  2 + Licensed to the Apache Software Foundation (ASF) under one or more
  3 + contributor license agreements. See the NOTICE file distributed with
  4 + this work for additional information regarding copyright ownership.
  5 + The ASF licenses this file to You under the Apache License, Version 2.0
  6 + (the "License"); you may not use this file except in compliance with
  7 + the License. You may obtain a copy of the License at
  8 +
  9 + http://www.apache.org/licenses/LICENSE-2.0
  10 +
  11 + Unless required by applicable law or agreed to in writing, software
  12 + distributed under the License is distributed on an "AS IS" BASIS,
  13 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 + See the License for the specific language governing permissions and
  15 + limitations under the License.
  16 +
  17 +-->
  18 +<document>
  19 + <properties>
  20 + <title>Apache log4php.</title>
  21 + </properties>
  22 + <body>
  23 + <release version="2.0" description="PHP 5 compatibility">
  24 + <action type="fix" issue="LOG4PHP-3">Maven 2.0 build</action>
  25 + <action type="fix" issue="LOG4PHP-7">Updated source file headers with current ASF notice</action>
  26 + <action type="fix">PHP 5 compatibility modification.</action>
  27 + </release>
  28 + </body>
  29 +</document>
... ...
thirdparty/apache-log4php/src/main/php/Logger.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + * @category log4php
  19 + * @package log4php
  20 + * @author Marco Vassura
  21 + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22 + * @version SVN: $Id: Logger.php 635069 2008-03-08 20:19:11Z carnold $
  23 + * @link http://logging.apache.org/log4php
  24 + */
  25 +
  26 +/**
  27 + * @ignore
  28 + */
  29 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  30 +
  31 +/**
  32 + */
  33 +require_once(LOG4PHP_DIR . '/LoggerLevel.php');
  34 +require_once(LOG4PHP_DIR . '/spi/LoggerLoggingEvent.php');
  35 +
  36 +/**
  37 + * This class has been deprecated and replaced by the Logger subclass.
  38 + *
  39 + * @author Marco Vassura
  40 + * @version $Revision: 635069 $
  41 + * @package log4php
  42 + * @see Logger
  43 + */
  44 +class Logger {
  45 +
  46 + /**
  47 + * Additivity is set to true by default, that is children inherit the
  48 + * appenders of their ancestors by default.
  49 + * @var boolean
  50 + */
  51 + protected $additive = true;
  52 +
  53 + /**
  54 + * @var string fully qualified class name
  55 + */
  56 + protected $fqcn = 'LoggerCategory';
  57 +
  58 + /**
  59 + * @var LoggerLevel The assigned level of this category.
  60 + */
  61 + var $level = null;
  62 +
  63 + /**
  64 + * @var string name of this category.
  65 + */
  66 + protected $name = '';
  67 +
  68 + /**
  69 + * @var Logger The parent of this category.
  70 + */
  71 + protected $parent = null;
  72 +
  73 + /**
  74 + * @var LoggerHierarchy the object repository
  75 + */
  76 + var $repository = null;
  77 +
  78 + /**
  79 + * @var array collection of appenders
  80 + * @see LoggerAppender
  81 + */
  82 + var $aai = array();
  83 +
  84 +/* --------------------------------------------------------------------------*/
  85 +/* --------------------------------------------------------------------------*/
  86 +/* --------------------------------------------------------------------------*/
  87 +
  88 + /**
  89 + * Constructor.
  90 + *
  91 + * @param string $name Category name
  92 + */
  93 + public function __construct($name)
  94 + {
  95 + $this->name = $name;
  96 + }
  97 +
  98 + /**
  99 + * Add a new Appender to the list of appenders of this Category instance.
  100 + *
  101 + * @param LoggerAppender $newAppender
  102 + */
  103 + public function addAppender($newAppender)
  104 + {
  105 + $appenderName = $newAppender->getName();
  106 + $this->aai[$appenderName] = $newAppender;
  107 + }
  108 +
  109 + /**
  110 + * If assertion parameter is false, then logs msg as an error statement.
  111 + *
  112 + * @param bool $assertion
  113 + * @param string $msg message to log
  114 + */
  115 + public function assertLog($assertion = true, $msg = '')
  116 + {
  117 + if ($assertion == false) {
  118 + $this->error($msg);
  119 + }
  120 + }
  121 +
  122 + /**
  123 + * Call the appenders in the hierarchy starting at this.
  124 + *
  125 + * @param LoggerLoggingEvent $event
  126 + */
  127 + public function callAppenders($event)
  128 + {
  129 + if (sizeof($this->aai) > 0) {
  130 + foreach (array_keys($this->aai) as $appenderName) {
  131 + $this->aai[$appenderName]->doAppend($event);
  132 + }
  133 + }
  134 + if ($this->parent != null and $this->getAdditivity()) {
  135 + $this->parent->callAppenders($event);
  136 + }
  137 + }
  138 +
  139 + /**
  140 + * Log a message object with the DEBUG level including the caller.
  141 + *
  142 + * @param mixed $message message
  143 + * @param mixed $caller caller object or caller string id
  144 + */
  145 + public function debug($message, $caller = null)
  146 + {
  147 + $debugLevel = LoggerLevel::getLevelDebug();
  148 + if ($this->repository->isDisabled($debugLevel)) {
  149 + return;
  150 + }
  151 + if ($debugLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
  152 + $this->forcedLog($this->fqcn, $caller, $debugLevel, $message);
  153 + }
  154 + }
  155 +
  156 + /**
  157 + * Log a message object with the ERROR level including the caller.
  158 + *
  159 + * @param mixed $message message
  160 + * @param mixed $caller caller object or caller string id
  161 + */
  162 + public function error($message, $caller = null)
  163 + {
  164 + $errorLevel = LoggerLevel::getLevelError();
  165 + if ($this->repository->isDisabled($errorLevel)) {
  166 + return;
  167 + }
  168 + if ($errorLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
  169 + $this->forcedLog($this->fqcn, $caller, $errorLevel, $message);
  170 + }
  171 + }
  172 +
  173 + /**
  174 + * Deprecated. Please use LoggerManager::exists() instead.
  175 + *
  176 + * @param string $name
  177 + * @see LoggerManager::exists()
  178 + * @deprecated
  179 + */
  180 + public function exists($name)
  181 + {
  182 + return LoggerManager::exists($name);
  183 + }
  184 +
  185 + /**
  186 + * Log a message object with the FATAL level including the caller.
  187 + *
  188 + * @param mixed $message message
  189 + * @param mixed $caller caller object or caller string id
  190 + */
  191 + public function fatal($message, $caller = null)
  192 + {
  193 + $fatalLevel = LoggerLevel::getLevelFatal();
  194 + if ($this->repository->isDisabled($fatalLevel)) {
  195 + return;
  196 + }
  197 + if ($fatalLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
  198 + $this->forcedLog($this->fqcn, $caller, $fatalLevel, $message);
  199 + }
  200 + }
  201 +
  202 + /**
  203 + * This method creates a new logging event and logs the event without further checks.
  204 + *
  205 + * It should not be called directly. Use {@link info()}, {@link debug()}, {@link warn()},
  206 + * {@link error()} and {@link fatal()} wrappers.
  207 + *
  208 + * @param string $fqcn Fully Qualified Class Name of the Logger
  209 + * @param mixed $caller caller object or caller string id
  210 + * @param LoggerLevel $level log level
  211 + * @param mixed $message message
  212 + * @see LoggerLoggingEvent
  213 + */
  214 + public function forcedLog($fqcn, $caller, $level, $message)
  215 + {
  216 + // $fqcn = is_object($caller) ? get_class($caller) : (string)$caller;
  217 + $this->callAppenders(new LoggerLoggingEvent($fqcn, $this, $level, $message));
  218 + }
  219 +
  220 + /**
  221 + * Get the additivity flag for this Category instance.
  222 + * @return boolean
  223 + */
  224 + public function getAdditivity()
  225 + {
  226 + return $this->additive;
  227 + }
  228 +
  229 + /**
  230 + * Get the appenders contained in this category as an array.
  231 + * @return array collection of appenders
  232 + */
  233 + public function getAllAppenders()
  234 + {
  235 + return array_values($this->aai);
  236 + }
  237 +
  238 + /**
  239 + * Look for the appender named as name.
  240 + * @return LoggerAppender
  241 + */
  242 + public function getAppender($name)
  243 + {
  244 + return $this->aai[$name];
  245 + }
  246 +
  247 + /**
  248 + * Please use the {@link getEffectiveLevel()} method instead.
  249 + * @deprecated
  250 + */
  251 + public function getChainedPriority()
  252 + {
  253 + return $this->getEffectiveLevel();
  254 + }
  255 +
  256 + /**
  257 + * Please use {@link LoggerManager::getCurrentLoggers()} instead.
  258 + * @deprecated
  259 + */
  260 + public function getCurrentCategories()
  261 + {
  262 + return LoggerManager::getCurrentLoggers();
  263 + }
  264 +
  265 + /**
  266 + * Please use {@link LoggerManager::getLoggerRepository()} instead.
  267 + * @deprecated
  268 + */
  269 + public function getDefaultHierarchy()
  270 + {
  271 + return LoggerManager::getLoggerRepository();
  272 + }
  273 +
  274 + /**
  275 + * @deprecated Use {@link getLoggerRepository()}
  276 + * @return LoggerHierarchy
  277 + */
  278 + public function getHierarchy()
  279 + {
  280 + return $this->getLoggerRepository();
  281 + }
  282 +
  283 + /**
  284 + * Starting from this category, search the category hierarchy for a non-null level and return it.
  285 + * @see LoggerLevel
  286 + * @return LoggerLevel or null
  287 + */
  288 + public function getEffectiveLevel()
  289 + {
  290 + for($c = $this; $c != null; $c = $c->parent) {
  291 + if($c->getLevel() !== null)
  292 + return $c->getLevel();
  293 + }
  294 + return null;
  295 + }
  296 +
  297 + /**
  298 + * Retrieve a category with named as the name parameter.
  299 + * @return Logger
  300 + */
  301 + public function getInstance($name)
  302 + {
  303 + return LoggerManager::getLogger($name);
  304 + }
  305 +
  306 + /**
  307 + * Returns the assigned Level, if any, for this Category.
  308 + * @return LoggerLevel or null
  309 + */
  310 + public function getLevel()
  311 + {
  312 + return $this->level;
  313 + }
  314 +
  315 + /**
  316 + * Get a Logger by name (Delegate to {@link LoggerManager})
  317 + * @param string $name logger name
  318 + * @param LoggerFactory $factory a {@link LoggerFactory} instance or null
  319 + * @return Logger
  320 + * @static
  321 + */
  322 + public function getLogger($name, $factory = null)
  323 + {
  324 + return LoggerManager::getLogger($name, $factory);
  325 + }
  326 +
  327 + /**
  328 + * Return the the repository where this Category is attached.
  329 + * @return LoggerHierarchy
  330 + */
  331 + public function getLoggerRepository()
  332 + {
  333 + return $this->repository;
  334 + }
  335 +
  336 + /**
  337 + * Return the category name.
  338 + * @return string
  339 + */
  340 + public function getName()
  341 + {
  342 + return $this->name;
  343 + }
  344 +
  345 + /**
  346 + * Returns the parent of this category.
  347 + * @return Logger
  348 + */
  349 + public function getParent()
  350 + {
  351 + return $this->parent;
  352 + }
  353 +
  354 + /**
  355 + * Please use getLevel() instead.
  356 + * @deprecated
  357 + */
  358 + public function getPriority()
  359 + {
  360 + return $this->getLevel();
  361 + }
  362 +
  363 + /**
  364 + * Return the inherited ResourceBundle for this category.
  365 + */
  366 + public function getResourceBundle()
  367 + {
  368 + return;
  369 + }
  370 +
  371 + /**
  372 + * Returns the string resource corresponding to key in this category's inherited resource bundle.
  373 + */
  374 + public function getResourceBundleString($key)
  375 + {
  376 + return;
  377 + }
  378 +
  379 + /**
  380 + * Return the root of the default category hierarchy.
  381 + * @return LoggerRoot
  382 + */
  383 + public function getRoot()
  384 + {
  385 + return LoggerManager::getRootLogger();
  386 + }
  387 +
  388 + /**
  389 + * get the Root Logger (Delegate to {@link LoggerManager})
  390 + * @return LoggerRoot
  391 + * @static
  392 + */
  393 + public function getRootLogger()
  394 + {
  395 + return LoggerManager::getRootLogger();
  396 + }
  397 +
  398 + /**
  399 + * Log a message object with the INFO Level.
  400 + *
  401 + * @param mixed $message message
  402 + * @param mixed $caller caller object or caller string id
  403 + */
  404 + public function info($message, $caller = null)
  405 + {
  406 + $infoLevel = LoggerLevel::getLevelInfo();
  407 + if ($this->repository->isDisabled($infoLevel)) {
  408 + return;
  409 + }
  410 + if ($infoLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
  411 + $this->forcedLog($this->fqcn, $caller, $infoLevel, $message);
  412 + }
  413 + }
  414 +
  415 + /**
  416 + * Is the appender passed as parameter attached to this category?
  417 + *
  418 + * @param LoggerAppender $appender
  419 + */
  420 + public function isAttached($appender)
  421 + {
  422 + return isset($this->aai[$appender->getName()]);
  423 + }
  424 +
  425 + /**
  426 + * Check whether this category is enabled for the DEBUG Level.
  427 + * @return boolean
  428 + */
  429 + public function isDebugEnabled()
  430 + {
  431 + $debugLevel = LoggerLevel::getLevelDebug();
  432 + if ($this->repository->isDisabled($debugLevel)) {
  433 + return false;
  434 + }
  435 + return ($debugLevel->isGreaterOrEqual($this->getEffectiveLevel()));
  436 + }
  437 +
  438 + /**
  439 + * Check whether this category is enabled for a given Level passed as parameter.
  440 + *
  441 + * @param LoggerLevel level
  442 + * @return boolean
  443 + */
  444 + public function isEnabledFor($level)
  445 + {
  446 + if ($this->repository->isDisabled($level)) {
  447 + return false;
  448 + }
  449 + return (bool)($level->isGreaterOrEqual($this->getEffectiveLevel()));
  450 + }
  451 +
  452 + /**
  453 + * Check whether this category is enabled for the info Level.
  454 + * @return boolean
  455 + * @see LoggerLevel
  456 + */
  457 + public function isInfoEnabled()
  458 + {
  459 + $infoLevel = LoggerLevel::getLevelInfo();
  460 + if ($this->repository->isDisabled($infoLevel)) {
  461 + return false;
  462 + }
  463 + return ($infoLevel->isGreaterOrEqual($this->getEffectiveLevel()));
  464 + }
  465 +
  466 + /**
  467 + * Log a localized and parameterized message.
  468 + */
  469 + public function l7dlog($priority, $key, $params, $t)
  470 + {
  471 + return;
  472 + }
  473 +
  474 + /**
  475 + * This generic form is intended to be used by wrappers.
  476 + *
  477 + * @param LoggerLevel $priority a valid level
  478 + * @param mixed $message message
  479 + * @param mixed $caller caller object or caller string id
  480 + */
  481 + public function log($priority, $message, $caller = null)
  482 + {
  483 + if ($this->repository->isDisabled($priority)) {
  484 + return;
  485 + }
  486 + if ($priority->isGreaterOrEqual($this->getEffectiveLevel())) {
  487 + $this->forcedLog($this->fqcn, $caller, $priority, $message);
  488 + }
  489 + }
  490 +
  491 + /**
  492 + * Remove all previously added appenders from this Category instance.
  493 + */
  494 + public function removeAllAppenders()
  495 + {
  496 + $appenderNames = array_keys($this->aai);
  497 + $enumAppenders = sizeof($appenderNames);
  498 + for ($i = 0; $i < $enumAppenders; $i++) {
  499 + $this->removeAppender($appenderNames[$i]);
  500 + }
  501 + }
  502 +
  503 + /**
  504 + * Remove the appender passed as parameter form the list of appenders.
  505 + *
  506 + * @param mixed $appender can be an appender name or a {@link LoggerAppender} object
  507 + */
  508 + public function removeAppender($appender)
  509 + {
  510 + if ($appender instanceof loggerappender) {
  511 + $appender->close();
  512 + unset($this->aai[$appender->getName()]);
  513 + } elseif (is_string($appender) and isset($this->aai[$appender])) {
  514 + $this->aai[$appender]->close();
  515 + unset($this->aai[$appender]);
  516 + }
  517 + }
  518 +
  519 + /**
  520 + * Set the additivity flag for this Category instance.
  521 + *
  522 + * @param boolean $additive
  523 + */
  524 + public function setAdditivity($additive)
  525 + {
  526 + $this->additive = (bool)$additive;
  527 + }
  528 +
  529 + /**
  530 + * @deprecated Please use {@link setLevel()} instead.
  531 + * @see setLevel()
  532 + */
  533 + public function setPriority($priority)
  534 + {
  535 + $this->setLevel($priority);
  536 + }
  537 +
  538 + /**
  539 + * Only the Hierarchy class can set the hierarchy of a
  540 + * category.
  541 + *
  542 + * @param LoggerHierarchy $repository
  543 + */
  544 + public function setHierarchy($repository)
  545 + {
  546 + $this->repository = $repository;
  547 + }
  548 +
  549 + /**
  550 + * Set the level of this Category.
  551 + *
  552 + * @param LoggerLevel $level a level string or a level constant
  553 + */
  554 + public function setLevel($level)
  555 + {
  556 + $this->level = $level;
  557 + }
  558 +
  559 + public function setParent($logger) {
  560 + if ($logger instanceof Logger) {
  561 + $this->parent = $logger;
  562 + }
  563 + }
  564 +
  565 + /**
  566 + * Set the resource bundle to be used with localized logging methods
  567 + */
  568 + public function setResourceBundle($bundle)
  569 + {
  570 + return;
  571 + }
  572 +
  573 + /**
  574 + * @deprecated use {@link LoggerManager::shutdown()} instead.
  575 + * @see LoggerManager::shutdown()
  576 + */
  577 + public function shutdown()
  578 + {
  579 + LoggerManager::shutdown();
  580 + }
  581 +
  582 + /**
  583 + * Log a message with the WARN level.
  584 + *
  585 + * @param mixed $message message
  586 + * @param mixed $caller caller object or caller string id
  587 + */
  588 + public function warn($message, $caller = null)
  589 + {
  590 + $warnLevel = LoggerLevel::getLevelWarn();
  591 + if ($this->repository->isDisabled($warnLevel)) {
  592 + return;
  593 + }
  594 + if ($warnLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
  595 + $this->forcedLog($this->fqcn, $caller, $warnLevel, $message);
  596 + }
  597 + }
  598 +
  599 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerAppender.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +/**
  28 + * Abstract class that defines output logs strategies.
  29 + *
  30 + * @author Marco Vassura
  31 + * @version $Revision: 635069 $
  32 + * @package log4php
  33 + */
  34 +abstract class LoggerAppender {
  35 +
  36 + /**
  37 + * Factory
  38 + *
  39 + * @param string $name appender name
  40 + * @param string $class create an instance of this appender class
  41 + * @return LoggerAppender
  42 + */
  43 + public static function factory($name, $class)
  44 + {
  45 + $class = basename($class);
  46 + if (!empty($class)) {
  47 +
  48 + if (!class_exists($class))
  49 + include_once(LOG4PHP_DIR . "/appenders/{$class}.php");
  50 + if (class_exists($class))
  51 + return new $class($name);
  52 + }
  53 + return null;
  54 + }
  55 +
  56 + /**
  57 + * Singleton
  58 + *
  59 + * @param string $name appender name
  60 + * @param string $class create or get a reference instance of this class
  61 + * @return LoggerAppender
  62 + */
  63 + public static function singleton($name, $class = '')
  64 + {
  65 + static $instances;
  66 +
  67 + if (!empty($name)) {
  68 + if (!isset($instances[$name])) {
  69 + if (!empty($class)) {
  70 + $appender = self::factory($name, $class);
  71 + if ($appender !== null) {
  72 + $instances[$name] = $appender;
  73 + return $instances[$name];
  74 + }
  75 + }
  76 + return null;
  77 + }
  78 + return $instances[$name];
  79 + }
  80 + return null;
  81 + }
  82 +
  83 + /* --------------------------------------------------------------------------*/
  84 + /* --------------------------------------------------------------------------*/
  85 + /* --------------------------------------------------------------------------*/
  86 +
  87 + /**
  88 + * Add a filter to the end of the filter list.
  89 + *
  90 + * @param LoggerFilter $newFilter add a new LoggerFilter
  91 + * @abstract
  92 + */
  93 + abstract public function addFilter($newFilter);
  94 +
  95 + /**
  96 + * Clear the list of filters by removing all the filters in it.
  97 + * @abstract
  98 + */
  99 + abstract function clearFilters();
  100 +
  101 + /**
  102 + * Return the first filter in the filter chain for this Appender.
  103 + * The return value may be <i>null</i> if no is filter is set.
  104 + * @return LoggerFilter
  105 + */
  106 + abstract function getFilter();
  107 +
  108 + /**
  109 + * Release any resources allocated.
  110 + * Subclasses of {@link LoggerAppender} should implement
  111 + * this method to perform proper closing procedures.
  112 + * @abstract
  113 + */
  114 + abstract public function close();
  115 +
  116 + /**
  117 + * This method performs threshold checks and invokes filters before
  118 + * delegating actual logging to the subclasses specific <i>append()</i> method.
  119 + * @param LoggerLoggingEvent $event
  120 + * @abstract
  121 + */
  122 + abstract public function doAppend($event);
  123 +
  124 + /**
  125 + * Get the name of this appender.
  126 + * @return string
  127 + */
  128 + abstract public function getName();
  129 +
  130 + /**
  131 + * Do not use this method.
  132 + *
  133 + * @param object $errorHandler
  134 + */
  135 + abstract public function setErrorHandler($errorHandler);
  136 +
  137 + /**
  138 + * Do not use this method.
  139 + * @return object Returns the ErrorHandler for this appender.
  140 + */
  141 + abstract public function getErrorHandler();
  142 +
  143 + /**
  144 + * Set the Layout for this appender.
  145 + *
  146 + * @param LoggerLayout $layout
  147 + */
  148 + abstract public function setLayout($layout);
  149 +
  150 + /**
  151 + * Returns this appender layout.
  152 + * @return LoggerLayout
  153 + */
  154 + abstract public function getLayout();
  155 +
  156 + /**
  157 + * Set the name of this appender.
  158 + *
  159 + * The name is used by other components to identify this appender.
  160 + *
  161 + * @param string $name
  162 + */
  163 + abstract public function setName($name);
  164 +
  165 + /**
  166 + * Configurators call this method to determine if the appender
  167 + * requires a layout.
  168 + *
  169 + * <p>If this method returns <i>true</i>, meaning that layout is required,
  170 + * then the configurator will configure a layout using the configuration
  171 + * information at its disposal. If this method returns <i>false</i>,
  172 + * meaning that a layout is not required, then layout configuration will be
  173 + * skipped even if there is available layout configuration
  174 + * information at the disposal of the configurator.</p>
  175 + *
  176 + * <p>In the rather exceptional case, where the appender
  177 + * implementation admits a layout but can also work without it, then
  178 + * the appender should return <i>true</i>.</p>
  179 + *
  180 + * @return boolean
  181 + */
  182 + abstract public function requiresLayout();
  183 +
  184 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerAppenderSkeleton.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +/**
  28 + */
  29 +require_once(LOG4PHP_DIR . '/LoggerAppender.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  31 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  32 +
  33 +/**
  34 + * Abstract superclass of the other appenders in the package.
  35 + *
  36 + * This class provides the code for common functionality, such as
  37 + * support for threshold filtering and support for general filters.
  38 + *
  39 + * @author Marco Vassura
  40 + * @author Sergio Strampelli
  41 + * @version $Revision: 635069 $
  42 + * @package log4php
  43 + * @abstract
  44 + */
  45 +abstract class LoggerAppenderSkeleton extends LoggerAppender {
  46 +
  47 + /**
  48 + * @var boolean closed appender flag
  49 + */
  50 + protected $closed = false;
  51 +
  52 + /**
  53 + * @var object unused
  54 + */
  55 + protected $errorHandler;
  56 +
  57 + /**
  58 + * The first filter in the filter chain
  59 + * @var LoggerFilter
  60 + */
  61 + protected $headFilter = null;
  62 +
  63 + /**
  64 + * LoggerLayout for this appender. It can be null if appender has its own layout
  65 + * @var LoggerLayout
  66 + */
  67 + protected $layout = null;
  68 +
  69 + /**
  70 + * @var string Appender name
  71 + */
  72 + protected $name;
  73 +
  74 + /**
  75 + * The last filter in the filter chain
  76 + * @var LoggerFilter
  77 + */
  78 + protected $tailFilter = null;
  79 +
  80 + /**
  81 + * @var LoggerLevel There is no level threshold filtering by default.
  82 + */
  83 + protected $threshold = null;
  84 +
  85 + /**
  86 + * @var boolean needs a layout formatting ?
  87 + */
  88 + protected $requiresLayout = false;
  89 +
  90 + /**
  91 + * Constructor
  92 + *
  93 + * @param string $name appender name
  94 + */
  95 + public function __construct($name) {
  96 + $this->name = $name;
  97 + $this->clearFilters();
  98 + }
  99 +
  100 + /**
  101 + * @param LoggerFilter $newFilter add a new LoggerFilter
  102 + * @see LoggerAppender::addFilter()
  103 + */
  104 + public function addFilter($newFilter) {
  105 + if($this->headFilter === null) {
  106 + $this->headFilter = $newFilter;
  107 + $this->tailFilter = $this->headFilter;
  108 + } else {
  109 + $this->tailFilter->next = $newFilter;
  110 + $this->tailFilter = $this->tailFilter->next;
  111 + }
  112 + }
  113 +
  114 + /**
  115 + * Derived appenders should override this method if option structure
  116 + * requires it.
  117 + */
  118 + abstract public function activateOptions();
  119 +
  120 + /**
  121 + * Subclasses of {@link LoggerAppenderSkeleton} should implement
  122 + * this method to perform actual logging.
  123 + *
  124 + * @param LoggerLoggingEvent $event
  125 + * @see doAppend()
  126 + * @abstract
  127 + */
  128 + abstract protected function append($event);
  129 +
  130 + /**
  131 + * @see LoggerAppender::clearFilters()
  132 + */
  133 + public function clearFilters()
  134 + {
  135 + unset($this->headFilter);
  136 + unset($this->tailFilter);
  137 + $this->headFilter = null;
  138 + $this->tailFilter = null;
  139 + }
  140 +
  141 + /**
  142 + * Finalize this appender by calling the derived class' <i>close()</i> method.
  143 + */
  144 + public function finalize()
  145 + {
  146 + // An appender might be closed then garbage collected. There is no
  147 + // point in closing twice.
  148 + if ($this->closed) return;
  149 +
  150 + LoggerLog::debug("LoggerAppenderSkeleton::finalize():name=[{$this->name}].");
  151 +
  152 + $this->close();
  153 + }
  154 +
  155 + /**
  156 + * Do not use this method.
  157 + * @see LoggerAppender::getErrorHandler()
  158 + * @return object
  159 + */
  160 + public function getErrorHandler()
  161 + {
  162 + return $this->errorHandler;
  163 + }
  164 +
  165 + /**
  166 + * @see LoggerAppender::getFilter()
  167 + * @return LoggerFilter
  168 + */
  169 + public function getFilter()
  170 + {
  171 + return $this->headFilter;
  172 + }
  173 +
  174 + /**
  175 + * Return the first filter in the filter chain for this Appender.
  176 + * The return value may be <i>null</i> if no is filter is set.
  177 + * @return LoggerFilter
  178 + */
  179 + public function getFirstFilter()
  180 + {
  181 + return $this->headFilter;
  182 + }
  183 +
  184 + /**
  185 + * @see LoggerAppender::getLayout()
  186 + * @return LoggerLayout
  187 + */
  188 + public function getLayout()
  189 + {
  190 + return $this->layout;
  191 + }
  192 +
  193 + /**
  194 + * @see LoggerAppender::getName()
  195 + * @return string
  196 + */
  197 + public function getName()
  198 + {
  199 + return $this->name;
  200 + }
  201 +
  202 + /**
  203 + * Returns this appenders threshold level.
  204 + * See the {@link setThreshold()} method for the meaning of this option.
  205 + * @return LoggerLevel
  206 + */
  207 + public function getThreshold()
  208 + {
  209 + return $this->threshold;
  210 + }
  211 +
  212 + /**
  213 + * Check whether the message level is below the appender's threshold.
  214 + *
  215 + *
  216 + * If there is no threshold set, then the return value is always <i>true</i>.
  217 + * @param LoggerLevel $priority
  218 + * @return boolean true if priority is greater or equal than threshold
  219 + */
  220 + public function isAsSevereAsThreshold($priority)
  221 + {
  222 + if ($this->threshold === null)
  223 + return true;
  224 +
  225 + return $priority->isGreaterOrEqual($this->getThreshold());
  226 + }
  227 +
  228 + /**
  229 + * @see LoggerAppender::doAppend()
  230 + * @param LoggerLoggingEvent $event
  231 + */
  232 + public function doAppend($event)
  233 + {
  234 + LoggerLog::debug("LoggerAppenderSkeleton::doAppend()");
  235 +
  236 + if ($this->closed) {
  237 + LoggerLog::debug("LoggerAppenderSkeleton::doAppend() Attempted to append to closed appender named [{$this->name}].");
  238 + return;
  239 + }
  240 + if(!$this->isAsSevereAsThreshold($event->getLevel())) {
  241 + LoggerLog::debug("LoggerAppenderSkeleton::doAppend() event level is less severe than threshold.");
  242 + return;
  243 + }
  244 +
  245 + $f = $this->getFirstFilter();
  246 +
  247 + while($f !== null) {
  248 + switch ($f->decide($event)) {
  249 + case LOG4PHP_LOGGER_FILTER_DENY: return;
  250 + case LOG4PHP_LOGGER_FILTER_ACCEPT: return $this->append($event);
  251 + case LOG4PHP_LOGGER_FILTER_NEUTRAL: $f = $f->getNext();
  252 + }
  253 + }
  254 + $this->append($event);
  255 + }
  256 +
  257 +
  258 + /**
  259 + * @see LoggerAppender::requiresLayout()
  260 + * @return boolean
  261 + */
  262 + public function requiresLayout()
  263 + {
  264 + return $this->requiresLayout;
  265 + }
  266 +
  267 + /**
  268 + * @see LoggerAppender::setErrorHandler()
  269 + * @param object
  270 + */
  271 + public function setErrorHandler($errorHandler)
  272 + {
  273 + if($errorHandler == null) {
  274 + // We do not throw exception here since the cause is probably a
  275 + // bad config file.
  276 + LoggerLog::warn("You have tried to set a null error-handler.");
  277 + } else {
  278 + $this->errorHandler = $errorHandler;
  279 + }
  280 + }
  281 +
  282 + /**
  283 + * @see LoggerAppender::setLayout()
  284 + * @param LoggerLayout $layout
  285 + */
  286 + public function setLayout($layout)
  287 + {
  288 + if ($this->requiresLayout())
  289 + $this->layout = $layout;
  290 + }
  291 +
  292 + /**
  293 + * @see LoggerAppender::setName()
  294 + * @param string $name
  295 + */
  296 + public function setName($name)
  297 + {
  298 + $this->name = $name;
  299 + }
  300 +
  301 + /**
  302 + * Set the threshold level of this appender.
  303 + *
  304 + * @param mixed $threshold can be a {@link LoggerLevel} object or a string.
  305 + * @see LoggerOptionConverter::toLevel()
  306 + */
  307 + public function setThreshold($threshold)
  308 + {
  309 + if (is_string($threshold)) {
  310 + $this->threshold = LoggerOptionConverter::toLevel($threshold, null);
  311 + }elseif ($threshold instanceof LoggerLevel) {
  312 + $this->threshold = $threshold;
  313 + }
  314 + }
  315 +
  316 + /**
  317 + * Perform actions before object serialization.
  318 + *
  319 + * Call {@link finalize()} to properly close the appender.
  320 + */
  321 + function __sleep()
  322 + {
  323 + $this->finalize();
  324 + return array_keys(get_object_vars($this));
  325 + }
  326 +
  327 + /**
  328 + * Perform actions after object de-serialization.
  329 + *
  330 + * Call {@link activateOptions()} to properly setup the appender.
  331 + */
  332 + function __wakeup()
  333 + {
  334 + $this->activateOptions();
  335 + }
  336 +
  337 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerBasicConfigurator.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +require_once(LOG4PHP_DIR . '/spi/LoggerConfigurator.php');
  28 +require_once(LOG4PHP_DIR . '/layouts/LoggerLayoutTTCC.php');
  29 +require_once(LOG4PHP_DIR . '/appenders/LoggerAppenderConsole.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerManager.php');
  31 +
  32 +/**
  33 + * Use this class to quickly configure the package.
  34 + *
  35 + * <p>For file based configuration see {@link LoggerPropertyConfigurator}.
  36 + * <p>For XML based configuration see {@link LoggerDOMConfigurator}.
  37 + *
  38 + * @author Marco Vassura
  39 + * @version $Revision: 635069 $
  40 + * @package log4php
  41 + */
  42 +class LoggerBasicConfigurator implements LoggerConfigurator {
  43 +
  44 + /**
  45 + * Add a {@link LoggerAppenderConsole} that uses
  46 + * the {@link LoggerLayoutTTCC} to the root category.
  47 + *
  48 + * @param string $url not used here
  49 + */
  50 + public static function configure($url = null)
  51 + {
  52 + $root = LoggerManager::getRootLogger();
  53 + $appender = new LoggerAppenderConsole('A1');
  54 + $appender->setLayout( new LoggerLayoutTTCC() );
  55 + $root->addAppender($appender);
  56 + }
  57 +
  58 + /**
  59 + * Reset the default hierarchy to its default.
  60 + * It is equivalent to
  61 + * <code>
  62 + * LoggerManager::resetConfiguration();
  63 + * </code>
  64 + *
  65 + * @see LoggerHierarchy::resetConfiguration()
  66 + * @static
  67 + */
  68 + public static function resetConfiguration()
  69 + {
  70 + LoggerManager::resetConfiguration();
  71 + }
  72 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerDefaultCategoryFactory.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +require_once(LOG4PHP_DIR . '/spi/LoggerFactory.php');
  28 +require_once(LOG4PHP_DIR . '/Logger.php');
  29 +
  30 +/**
  31 + * Creates instances of {@link Logger} with a given name.
  32 + *
  33 + * @author Marco Vassura
  34 + * @version $Revision: 635069 $
  35 + * @package log4php
  36 + * @since 0.5
  37 + */
  38 +class LoggerDefaultCategoryFactory extends LoggerFactory {
  39 +
  40 + /**
  41 + * @param string $name
  42 + * @return Logger
  43 + */
  44 + public function makeNewLoggerInstance($name)
  45 + {
  46 + return new Logger($name);
  47 + }
  48 +}
  49 +
... ...
thirdparty/apache-log4php/src/main/php/LoggerHierarchy.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +/**
  28 + */
  29 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerLevel.php');
  31 +require_once(LOG4PHP_DIR . '/LoggerRoot.php');
  32 +require_once(LOG4PHP_DIR . '/or/LoggerRendererMap.php');
  33 +require_once(LOG4PHP_DIR . '/LoggerDefaultCategoryFactory.php');
  34 +
  35 +/**
  36 + * This class is specialized in retrieving loggers by name and also maintaining
  37 + * the logger hierarchy.
  38 + *
  39 + * <p>The casual user does not have to deal with this class directly.</p>
  40 + *
  41 + * <p>The structure of the logger hierarchy is maintained by the
  42 + * getLogger method. The hierarchy is such that children link
  43 + * to their parent but parents do not have any pointers to their
  44 + * children. Moreover, loggers can be instantiated in any order, in
  45 + * particular descendant before ancestor.</p>
  46 + *
  47 + * <p>In case a descendant is created before a particular ancestor,
  48 + * then it creates a provision node for the ancestor and adds itself
  49 + * to the provision node. Other descendants of the same ancestor add
  50 + * themselves to the previously created provision node.</p>
  51 + *
  52 + * @author Marco Vassura
  53 + * @version $Revision: 635069 $
  54 + * @package log4php
  55 + */
  56 +class LoggerHierarchy {
  57 +
  58 + /**
  59 + * @var object currently unused
  60 + */
  61 + protected $defaultFactory;
  62 +
  63 + /**
  64 + * @var boolean activate internal logging
  65 + * @see LoggerLog
  66 + */
  67 + public $debug = false;
  68 +
  69 + /**
  70 + * @var array hierarchy tree. saves here all loggers
  71 + */
  72 + protected $ht = array();
  73 +
  74 + /**
  75 + * @var LoggerRoot
  76 + */
  77 + protected $root = null;
  78 +
  79 + /**
  80 + * @var LoggerRendererMap
  81 + */
  82 + protected $rendererMap;
  83 +
  84 + /**
  85 + * @var LoggerLevel main level threshold
  86 + */
  87 + protected $threshold;
  88 +
  89 + /**
  90 + * @var boolean currently unused
  91 + */
  92 + protected $emittedNoAppenderWarning = false;
  93 +
  94 + /**
  95 + * @var boolean currently unused
  96 + */
  97 + protected $emittedNoResourceBundleWarning = false;
  98 +
  99 + public static function singleton()
  100 + {
  101 + static $instance;
  102 +
  103 + if (!isset($instance))
  104 + $instance = new LoggerHierarchy(new LoggerRoot());
  105 + return $instance;
  106 + }
  107 +
  108 + /**
  109 + * Create a new logger hierarchy.
  110 + * @param object $root the root logger
  111 + */
  112 + protected function __construct($root)
  113 + {
  114 + $this->root = $root;
  115 + // Enable all level levels by default.
  116 + $this->setThreshold(LoggerLevel::getLevelAll());
  117 + $this->root->setHierarchy($this);
  118 + $this->rendererMap = new LoggerRendererMap();
  119 + $this->defaultFactory = new LoggerDefaultCategoryFactory();
  120 + }
  121 +
  122 + /**
  123 + * Add a HierarchyEventListener event to the repository.
  124 + * Not Yet Impl.
  125 + */
  126 + public function addHierarchyEventListener($listener)
  127 + {
  128 + return;
  129 + }
  130 +
  131 + /**
  132 + * Add an object renderer for a specific class.
  133 + * @param string $classToRender
  134 + * @param LoggerObjectRenderer $or
  135 + */
  136 + public function addRenderer($classToRender, $or)
  137 + {
  138 + $this->rendererMap->put($classToRender, $or);
  139 + }
  140 +
  141 + /**
  142 + * This call will clear all logger definitions from the internal hashtable.
  143 + */
  144 + public function clear()
  145 + {
  146 + $this->ht = array();
  147 + }
  148 +
  149 + public function emitNoAppenderWarning($cat)
  150 + {
  151 + return;
  152 + }
  153 +
  154 + /**
  155 + * Check if the named logger exists in the hierarchy.
  156 + * @param string $name
  157 + * @return boolean
  158 + */
  159 + public function exists($name)
  160 + {
  161 + return isset($this->ht[$name]);
  162 + }
  163 +
  164 + /**
  165 + * Not Implemented.
  166 + * @param Logger $logger
  167 + * @param LoggerAppender $appender
  168 + */
  169 + public function fireAddAppenderEvent($logger, $appender)
  170 + {
  171 + return;
  172 + }
  173 +
  174 + /**
  175 + * @deprecated Please use {@link getCurrentLoggers()} instead.
  176 + */
  177 + public function getCurrentCategories()
  178 + {
  179 + return $this->getCurrentLoggers();
  180 + }
  181 +
  182 + /**
  183 + * Returns all the currently defined categories in this hierarchy as an array.
  184 + * @return array
  185 + */
  186 + public function getCurrentLoggers()
  187 + {
  188 + return array_values($this->ht);
  189 + }
  190 +
  191 + /**
  192 + * Return a new logger instance named as the first parameter using the default factory.
  193 + *
  194 + * @param string $name logger name
  195 + * @param LoggerFactory $factory a {@link LoggerFactory} instance or null
  196 + * @return Logger
  197 + */
  198 + public function getLogger($name, $factory = null)
  199 + {
  200 + if ($factory === null) {
  201 + return $this->getLoggerByFactory($name, $this->defaultFactory);
  202 + } else {
  203 + return $this->getLoggerByFactory($name, $factory);
  204 + }
  205 + }
  206 +
  207 + /**
  208 + * Return a new logger instance named as the first parameter using the default factory.
  209 + *
  210 + * @param string $name logger name
  211 + * @return Logger
  212 + * @todo merge with {@link getLogger()}
  213 + */
  214 + public function getLoggerByFactory($name, $factory)
  215 + {
  216 + if (!isset($this->ht[$name])) {
  217 + $this->ht[$name] = $factory->makeNewLoggerInstance($name);
  218 + $this->ht[$name]->setHierarchy($this);
  219 + $nodes = explode('.', $name);
  220 + $firstNode = array_shift($nodes);
  221 + if ( $firstNode != $name and isset($this->ht[$firstNode])) {
  222 + $this->ht[$name]->setParent($this->ht[$firstNode]);
  223 + } else {
  224 + $this->ht[$name]->setParent($this->root);
  225 + }
  226 + if (sizeof($nodes) > 0) {
  227 + // find parent node
  228 + foreach ($nodes as $node) {
  229 + $parentNode = "$firstNode.$node";
  230 + if (isset($this->ht[$parentNode]) and $parentNode != $name) {
  231 + $this->ht[$name]->setParent($this->ht[$parentNode]);
  232 + }
  233 + $firstNode .= ".$node";
  234 + }
  235 + }
  236 + }
  237 + return $this->ht[$name];
  238 + }
  239 +
  240 + /**
  241 + * @return LoggerRendererMap Get the renderer map for this hierarchy.
  242 + */
  243 + public function getRendererMap()
  244 + {
  245 + return $this->rendererMap;
  246 + }
  247 +
  248 + /**
  249 + * @return LoggerRoot Get the root of this hierarchy.
  250 + */
  251 + public function getRootLogger()
  252 + {
  253 + if (!isset($this->root) or $this->root == null)
  254 + $this->root = new LoggerRoot();
  255 + return $this->root;
  256 + }
  257 +
  258 + /**
  259 + * @return LoggerLevel Returns the threshold Level.
  260 + */
  261 + public function getThreshold()
  262 + {
  263 + return $this->threshold;
  264 + }
  265 +
  266 + /**
  267 + * This method will return true if this repository is disabled
  268 + * for level object passed as parameter and false otherwise.
  269 + * @return boolean
  270 + */
  271 + public function isDisabled($level)
  272 + {
  273 + return ($this->threshold->level > $level->level);
  274 + }
  275 +
  276 + /**
  277 + * @deprecated Deprecated with no replacement.
  278 + */
  279 + public function overrideAsNeeded($override)
  280 + {
  281 + return;
  282 + }
  283 +
  284 + /**
  285 + * Reset all values contained in this hierarchy instance to their
  286 + * default.
  287 + *
  288 + * This removes all appenders from all categories, sets
  289 + * the level of all non-root categories to <i>null</i>,
  290 + * sets their additivity flag to <i>true</i> and sets the level
  291 + * of the root logger to {@link LOGGER_LEVEL_DEBUG}. Moreover,
  292 + * message disabling is set its default "off" value.
  293 + *
  294 + * <p>Existing categories are not removed. They are just reset.
  295 + *
  296 + * <p>This method should be used sparingly and with care as it will
  297 + * block all logging until it is completed.</p>
  298 + */
  299 + public function resetConfiguration()
  300 + {
  301 + $root = $this->getRootLogger();
  302 +
  303 + $root->setLevel(LoggerLevel::getLevelDebug());
  304 + $this->setThreshold(LoggerLevel::getLevelAll());
  305 + $this->shutDown();
  306 + $loggers = $this->getCurrentLoggers();
  307 + $enumLoggers = sizeof($loggers);
  308 + for ($i = 0; $i < $enumLoggers; $i++) {
  309 + $loggers[$i]->setLevel(null);
  310 + $loggers[$i]->setAdditivity(true);
  311 + $loggers[$i]->setResourceBundle(null);
  312 + $loggers[$i]->removeAllAppenders();
  313 + }
  314 + $this->rendererMap->clear();
  315 + }
  316 +
  317 + /**
  318 + * @deprecated Deprecated with no replacement.
  319 + */
  320 + public function setDisableOverride($override)
  321 + {
  322 + return;
  323 + }
  324 +
  325 + /**
  326 + * Used by subclasses to add a renderer to the hierarchy passed as parameter.
  327 + * @param string $renderedClass a LoggerRenderer class name
  328 + * @param LoggerRenderer $renderer
  329 + *
  330 + */
  331 + public function setRenderer($renderedClass, $renderer)
  332 + {
  333 + $this->rendererMap->put($renderedClass, $renderer);
  334 + }
  335 +
  336 + /**
  337 + * set a new threshold level
  338 + *
  339 + * @param LoggerLevel $l
  340 + */
  341 + public function setThreshold($l)
  342 + {
  343 + if ($l !== null)
  344 + $this->threshold = $l;
  345 + }
  346 +
  347 + /**
  348 + * Shutting down a hierarchy will <i>safely</i> close and remove
  349 + * all appenders in all categories including the root logger.
  350 + *
  351 + * <p>Some appenders such as {@link LoggerSocketAppender}
  352 + * need to be closed before the
  353 + * application exists. Otherwise, pending logging events might be
  354 + * lost.
  355 + *
  356 + * <p>The shutdown method is careful to close nested
  357 + * appenders before closing regular appenders. This is allows
  358 + * configurations where a regular appender is attached to a logger
  359 + * and again to a nested appender.
  360 + */
  361 + public function shutdown()
  362 + {
  363 + $this->root->removeAllAppenders();
  364 + $cats = $this->getCurrentLoggers();
  365 + $enumCats = sizeof($cats);
  366 + if ($enumCats > 0) {
  367 + for ($i = 0; $i < $enumCats; $i++) {
  368 + $cats[$i]->removeAllAppenders();
  369 + }
  370 + }
  371 + }
  372 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerLayout.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + * @package log4php
  19 + */
  20 +
  21 +/**
  22 + * @ignore
  23 + */
  24 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  25 +
  26 +/**
  27 + * Extend this abstract class to create your own log layout format.
  28 + *
  29 + * @author Marco Vassura
  30 + * @version $Revision: 635069 $
  31 + * @package log4php
  32 + * @abstract
  33 + */
  34 +abstract class LoggerLayout {
  35 +
  36 + /**
  37 + * Creates LoggerLayout instances with the given class name.
  38 + *
  39 + * @param string $class
  40 + * @return LoggerLayout
  41 + */
  42 + public static function factory($class)
  43 + {
  44 + if (!empty($class)) {
  45 + $class = basename($class);
  46 + if (!class_exists($class))
  47 + include_once(LOG4PHP_DIR . "/layouts/{$class}.php");
  48 + if (class_exists($class))
  49 + return new $class();
  50 + }
  51 + return null;
  52 + }
  53 +
  54 + /**
  55 + * Override this method
  56 + */
  57 + abstract function activateOptions();
  58 +
  59 + /**
  60 + * Override this method to create your own layout format.
  61 + *
  62 + * @param LoggerLoggingEvent
  63 + * @return string
  64 + */
  65 + public function format($event)
  66 + {
  67 + return $event->getRenderedMessage();
  68 + }
  69 +
  70 + /**
  71 + * Returns the content type output by this layout.
  72 + * @return string
  73 + */
  74 + public function getContentType()
  75 + {
  76 + return "text/plain";
  77 + }
  78 +
  79 + /**
  80 + * Returns the footer for the layout format.
  81 + * @return string
  82 + */
  83 + public function getFooter()
  84 + {
  85 + return null;
  86 + }
  87 +
  88 + /**
  89 + * Returns the header for the layout format.
  90 + * @return string
  91 + */
  92 + public function getHeader()
  93 + {
  94 + return null;
  95 + }
  96 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerLevel.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +/**
  28 + */
  29 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  30 +
  31 +define('LOG4PHP_LEVEL_OFF_INT', 2147483647);
  32 +define('LOG4PHP_LEVEL_FATAL_INT', 50000);
  33 +define('LOG4PHP_LEVEL_ERROR_INT', 40000);
  34 +define('LOG4PHP_LEVEL_WARN_INT', 30000);
  35 +define('LOG4PHP_LEVEL_INFO_INT', 20000);
  36 +define('LOG4PHP_LEVEL_DEBUG_INT', 10000);
  37 +define('LOG4PHP_LEVEL_ALL_INT', -2147483647);
  38 +
  39 +/**
  40 + * Defines the minimum set of levels recognized by the system, that is
  41 + * <i>OFF</i>, <i>FATAL</i>, <i>ERROR</i>,
  42 + * <i>WARN</i>, <i>INFO</i, <i>DEBUG</i> and
  43 + * <i>ALL</i>.
  44 + *
  45 + * <p>The <i>LoggerLevel</i> class may be subclassed to define a larger
  46 + * level set.</p>
  47 + *
  48 + * @author Marco Vassura
  49 + * @version $Revision: 635069 $
  50 + * @package log4php
  51 + * @since 0.5
  52 + */
  53 +class LoggerLevel {
  54 +
  55 + /**
  56 + * @var integer
  57 + */
  58 + public $level;
  59 +
  60 + /**
  61 + * @var string
  62 + */
  63 + public $levelStr;
  64 +
  65 + /**
  66 + * @var integer
  67 + */
  68 + public $syslogEquivalent;
  69 +
  70 + /**
  71 + * Constructor
  72 + *
  73 + * @param integer $level
  74 + * @param string $levelStr
  75 + * @param integer $syslogEquivalent
  76 + */
  77 + public function __construct($level, $levelStr, $syslogEquivalent)
  78 + {
  79 + $this->level = $level;
  80 + $this->levelStr = $levelStr;
  81 + $this->syslogEquivalent = $syslogEquivalent;
  82 + }
  83 +
  84 + /**
  85 + * Two priorities are equal if their level fields are equal.
  86 + *
  87 + * @param object $o
  88 + * @return boolean
  89 + */
  90 + public function equals($o)
  91 + {
  92 + if ($o instanceof LoggerLevel) {
  93 + return ($this->level == $o->level);
  94 + } else {
  95 + return false;
  96 + }
  97 + }
  98 +
  99 + /**
  100 + * Returns an Off Level
  101 + * @static
  102 + * @return LoggerLevel
  103 + */
  104 + public static function getLevelOff()
  105 + {
  106 + static $level;
  107 + if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_OFF_INT, 'OFF', 0);
  108 + return $level;
  109 + }
  110 +
  111 + /**
  112 + * Returns a Fatal Level
  113 + * @static
  114 + * @return LoggerLevel
  115 + */
  116 + public static function getLevelFatal()
  117 + {
  118 + static $level;
  119 + if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_FATAL_INT, 'FATAL', 0);
  120 + return $level;
  121 + }
  122 +
  123 + /**
  124 + * Returns an Error Level
  125 + * @static
  126 + * @return LoggerLevel
  127 + */
  128 + public static function getLevelError()
  129 + {
  130 + static $level;
  131 + if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_ERROR_INT, 'ERROR', 3);
  132 + return $level;
  133 + }
  134 +
  135 + /**
  136 + * Returns a Warn Level
  137 + * @static
  138 + * @return LoggerLevel
  139 + */
  140 + public static function getLevelWarn()
  141 + {
  142 + static $level;
  143 + if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_WARN_INT, 'WARN', 4);
  144 + return $level;
  145 + }
  146 +
  147 + /**
  148 + * Returns an Info Level
  149 + * @static
  150 + * @return LoggerLevel
  151 + */
  152 + public static function getLevelInfo()
  153 + {
  154 + static $level;
  155 + if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_INFO_INT, 'INFO', 6);
  156 + return $level;
  157 + }
  158 +
  159 + /**
  160 + * Returns a Debug Level
  161 + * @static
  162 + * @return LoggerLevel
  163 + */
  164 + public static function getLevelDebug()
  165 + {
  166 + static $level;
  167 + if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_DEBUG_INT, 'DEBUG', 7);
  168 + return $level;
  169 + }
  170 +
  171 + /**
  172 + * Returns an All Level
  173 + * @static
  174 + * @return LoggerLevel
  175 + */
  176 + public static function getLevelAll()
  177 + {
  178 + static $level;
  179 + if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_ALL_INT, 'ALL', 7);
  180 + return $level;
  181 + }
  182 +
  183 + /**
  184 + * Return the syslog equivalent of this priority as an integer.
  185 + * @final
  186 + * @return integer
  187 + */
  188 + public function getSyslogEquivalent()
  189 + {
  190 + return $this->syslogEquivalent;
  191 + }
  192 +
  193 + /**
  194 + * Returns <i>true</i> if this level has a higher or equal
  195 + * level than the level passed as argument, <i>false</i>
  196 + * otherwise.
  197 + *
  198 + * <p>You should think twice before overriding the default
  199 + * implementation of <i>isGreaterOrEqual</i> method.
  200 + *
  201 + * @param LoggerLevel $r
  202 + * @return boolean
  203 + */
  204 + public function isGreaterOrEqual($r)
  205 + {
  206 + return $this->level >= $r->level;
  207 + }
  208 +
  209 + /**
  210 + * Returns the string representation of this priority.
  211 + * @return string
  212 + * @final
  213 + */
  214 + public function toString()
  215 + {
  216 + return $this->levelStr;
  217 + }
  218 +
  219 + /**
  220 + * Returns the integer representation of this level.
  221 + * @return integer
  222 + */
  223 + public function toInt()
  224 + {
  225 + return $this->level;
  226 + }
  227 +
  228 + /**
  229 + * Convert the string passed as argument to a level. If the
  230 + * conversion fails, then this method returns a DEBUG Level.
  231 + *
  232 + * @param mixed $arg
  233 + * @param LoggerLevel $default
  234 + * @static
  235 + */
  236 + public static function toLevel($arg, $defaultLevel = null)
  237 + {
  238 + if ($defaultLevel === null) {
  239 + return self::toLevel($arg, self::getLevelDebug());
  240 + } else {
  241 + if (is_int($arg)) {
  242 + switch($arg) {
  243 + case LOG4PHP_LEVEL_ALL_INT: return self::getLevelAll();
  244 + case LOG4PHP_LEVEL_DEBUG_INT: return self::getLevelDebug();
  245 + case LOG4PHP_LEVEL_INFO_INT: return self::getLevelInfo();
  246 + case LOG4PHP_LEVEL_WARN_INT: return self::getLevelWarn();
  247 + case LOG4PHP_LEVEL_ERROR_INT: return self::getLevelError();
  248 + case LOG4PHP_LEVEL_FATAL_INT: return self::getLevelFatal();
  249 + case LOG4PHP_LEVEL_OFF_INT: return self::getLevelOff();
  250 + default: return $defaultLevel;
  251 + }
  252 + } else {
  253 + switch(strtoupper($arg)) {
  254 + case 'ALL': return self::getLevelAll();
  255 + case 'DEBUG': return self::getLevelDebug();
  256 + case 'INFO': return self::getLevelInfo();
  257 + case 'WARN': return self::getLevelWarn();
  258 + case 'ERROR': return self::getLevelError();
  259 + case 'FATAL': return self::getLevelFatal();
  260 + case 'OFF': return self::getLevelOff();
  261 + default: return $defaultLevel;
  262 + }
  263 + }
  264 + }
  265 + }
  266 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerLog.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +/**
  28 + * Helper class for internal logging
  29 + *
  30 + * <p>It uses php {@link PHP_MANUAL#trigger_error trigger_error()} function
  31 + * to output messages.</p>
  32 + * <p>You need to recode methods to output messages in a different way.</p>
  33 + *
  34 + * @author Marco Vassura
  35 + * @version $Revision: 635069 $
  36 + * @package log4php
  37 + */
  38 +class LoggerLog {
  39 +
  40 + protected static $debug = false;
  41 +
  42 + /**
  43 + * Log if debug is enabled.
  44 + *
  45 + * Log using php {@link PHP_MANUAL#trigger_error trigger_error()} function
  46 + * with E_USER_NOTICE level by default.
  47 + *
  48 + * @param string $message log message
  49 + * @param integer $errLevel level to log
  50 + * @static
  51 + */
  52 + public static function log($message, $errLevel = E_USER_NOTICE)
  53 + {
  54 + if (LoggerLog::internalDebugging())
  55 + trigger_error($message, $errLevel);
  56 + }
  57 +
  58 + public static function internalDebugging($value = null)
  59 + {
  60 + if (is_bool($value))
  61 + self::$debug = $value;
  62 + return self::$debug;
  63 + }
  64 +
  65 + /**
  66 + * Report a debug message.
  67 + *
  68 + * @param string $message log message
  69 + * @static
  70 + * @since 0.3
  71 + */
  72 + public static function debug($message)
  73 + {
  74 + LoggerLog::log($message, E_USER_NOTICE);
  75 + }
  76 +
  77 + /**
  78 + * Report an error message.
  79 + *
  80 + * @param string $message log message
  81 + * @static
  82 + * @since 0.3
  83 + */
  84 + public static function error($message)
  85 + {
  86 + trigger_error($message, E_USER_ERROR);
  87 + }
  88 +
  89 + /**
  90 + * Report a warning message.
  91 + *
  92 + * @param string $message log message
  93 + * @static
  94 + * @since 0.3
  95 + */
  96 + public static function warn($message)
  97 + {
  98 + trigger_error($message, E_USER_WARNING);
  99 + }
  100 +
  101 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerMDC.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +/**
  28 + */
  29 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  30 +
  31 +
  32 +define('LOGGER_MDC_HT_SIZE', 7);
  33 +
  34 +/**
  35 + * This is the global repository of user mappings
  36 + */
  37 +$GLOBALS['log4php.LoggerMDC.ht'] = array();
  38 +
  39 +/**
  40 + * The LoggerMDC class is similar to the {@link LoggerNDC} class except that it is
  41 + * based on a map instead of a stack. It provides <i>mapped diagnostic contexts</i>.
  42 + *
  43 + * A <i>Mapped Diagnostic Context</i>, or
  44 + * MDC in short, is an instrument for distinguishing interleaved log
  45 + * output from different sources. Log output is typically interleaved
  46 + * when a server handles multiple clients near-simultaneously.
  47 + *
  48 + * <p><b><i>The MDC is managed on a per thread basis</i></b>.
  49 + *
  50 + * @author Marco Vassura
  51 + * @version $Revision: 635069 $
  52 + * @since 0.3
  53 + * @package log4php
  54 + */
  55 +class LoggerMDC {
  56 +
  57 + /**
  58 + * Put a context value as identified with the key parameter into the current thread's
  59 + * context map.
  60 + *
  61 + * <p>If the current thread does not have a context map it is
  62 + * created as a side effect.</p>
  63 + *
  64 + * <p>Note that you cannot put more than {@link LOGGER_MDC_HT_SIZE} keys.</p>
  65 + *
  66 + * @param string $key the key
  67 + * @param string $value the value
  68 + * @static
  69 + */
  70 + public static function put($key, $value)
  71 + {
  72 + if ( sizeof($GLOBALS['log4php.LoggerMDC.ht']) < LOGGER_MDC_HT_SIZE )
  73 + $GLOBALS['log4php.LoggerMDC.ht'][$key] = $value;
  74 + }
  75 +
  76 + /**
  77 + * Get the context identified by the key parameter.
  78 + *
  79 + * <p>You can use special key identifiers to map values in
  80 + * PHP $_SERVER and $_ENV vars. Just put a 'server.' or 'env.'
  81 + * followed by the var name you want to refer.</p>
  82 + *
  83 + * <p>This method has no side effects.</p>
  84 + *
  85 + * @param string $key
  86 + * @return string
  87 + * @static
  88 + */
  89 + public static function get($key)
  90 + {
  91 + LoggerLog::debug("LoggerMDC::get() key='$key'");
  92 +
  93 + if (!empty($key)) {
  94 + if (strpos($key, 'server.') === 0) {
  95 + $varName = substr($key, 7);
  96 +
  97 + LoggerLog::debug("LoggerMDC::get() a _SERVER[$varName] is requested.");
  98 +
  99 + return @$_SERVER[$varName];
  100 + } elseif (strpos($key, 'env.') === 0) {
  101 +
  102 + $varName = substr($key, 4);
  103 +
  104 + LoggerLog::debug("LoggerMDC::get() a _ENV[$varName] is requested.");
  105 +
  106 + return @$_ENV[$varName];
  107 + } elseif (isset($GLOBALS['log4php.LoggerMDC.ht'][$key])) {
  108 +
  109 + LoggerLog::debug("LoggerMDC::get() a user key is requested.");
  110 +
  111 + return $GLOBALS['log4php.LoggerMDC.ht'][$key];
  112 + }
  113 + }
  114 + return '';
  115 + }
  116 +
  117 + /**
  118 + * Remove the the context identified by the key parameter.
  119 + *
  120 + * It only affects user mappings.
  121 + *
  122 + * @param string $key
  123 + * @return string
  124 + * @static
  125 + */
  126 + public static function remove($key)
  127 + {
  128 + unset($GLOBALS['log4php.LoggerMDC.ht'][$key]);
  129 + }
  130 +
  131 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerManager.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * LOG4PHP_DIR points to the log4php root directory.
  24 + *
  25 + * If not defined it will be set automatically when the first package classfile
  26 + * is included
  27 + *
  28 + * @var string
  29 + */
  30 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  31 +
  32 +require_once(LOG4PHP_DIR . '/LoggerHierarchy.php');
  33 +
  34 +/**
  35 + * Use the LoggerManager to get Logger instances.
  36 + *
  37 + * @author Marco Vassura
  38 + * @version $Revision: 635069 $
  39 + * @package log4php
  40 + * @see Logger
  41 + * @todo create a configurator selector
  42 + */
  43 +class LoggerManager {
  44 +
  45 + /**
  46 + * check if a given logger exists.
  47 + *
  48 + * @param string $name logger name
  49 + * @static
  50 + * @return boolean
  51 + */
  52 + public static function exists($name)
  53 + {
  54 + return self::getLoggerRepository()->exists($name);
  55 + }
  56 +
  57 + /**
  58 + * Returns an array this whole Logger instances.
  59 + *
  60 + * @static
  61 + * @see Logger
  62 + * @return array
  63 + */
  64 + public static function getCurrentLoggers()
  65 + {
  66 + return self::getLoggerRepository()->getCurrentLoggers();
  67 + }
  68 +
  69 + /**
  70 + * Returns the root logger.
  71 + *
  72 + * @static
  73 + * @return object
  74 + * @see LoggerRoot
  75 + */
  76 + public static function getRootLogger()
  77 + {
  78 + return self::getLoggerRepository()->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 + public static function getLogger($name, $factory = null)
  90 + {
  91 + return self::getLoggerRepository()->getLogger($name, $factory);
  92 + }
  93 +
  94 + /**
  95 + * Returns the LoggerHierarchy.
  96 + *
  97 + * @static
  98 + * @return LoggerHierarchy
  99 + */
  100 + public static function getLoggerRepository()
  101 + {
  102 + return LoggerHierarchy::singleton();
  103 + }
  104 +
  105 +
  106 + /**
  107 + * Destroy loggers object tree.
  108 + *
  109 + * @static
  110 + * @return boolean
  111 + */
  112 + public static function resetConfiguration()
  113 + {
  114 + return self::getLoggerRepository()->resetConfiguration();
  115 + }
  116 +
  117 + /**
  118 + * Does nothing.
  119 + * @static
  120 + */
  121 + public static function setRepositorySelector($selector, $guard)
  122 + {
  123 + return;
  124 + }
  125 +
  126 + /**
  127 + * Safely close all appenders.
  128 + * @static
  129 + */
  130 + public static function shutdown()
  131 + {
  132 + return self::getLoggerRepository()->shutdown();
  133 + }
  134 +}
  135 +
  136 +// ---------------------------------------------------------------------------
  137 +// ---------------------------------------------------------------------------
  138 +// ---------------------------------------------------------------------------
  139 +
  140 +if (!defined('LOG4PHP_DEFAULT_INIT_OVERRIDE')) {
  141 + if (isset($_ENV['log4php.defaultInitOverride'])) {
  142 + /**
  143 + * @ignore
  144 + */
  145 + define('LOG4PHP_DEFAULT_INIT_OVERRIDE',
  146 + LoggerOptionConverter::toBoolean($_ENV['log4php.defaultInitOverride'], false)
  147 + );
  148 + } elseif (isset($GLOBALS['log4php.defaultInitOverride'])) {
  149 + /**
  150 + * @ignore
  151 + */
  152 + define('LOG4PHP_DEFAULT_INIT_OVERRIDE',
  153 + LoggerOptionConverter::toBoolean($GLOBALS['log4php.defaultInitOverride'], false)
  154 + );
  155 + } else {
  156 + /**
  157 + * Controls init execution
  158 + *
  159 + * With this constant users can skip the default init procedure that is
  160 + * called when this file is included.
  161 + *
  162 + * <p>If it is not user defined, log4php tries to autoconfigure using (in order):</p>
  163 + *
  164 + * - the <code>$_ENV['log4php.defaultInitOverride']</code> variable.
  165 + * - the <code>$GLOBALS['log4php.defaultInitOverride']</code> global variable.
  166 + * - defaults to <i>false</i>
  167 + *
  168 + * @var boolean
  169 + */
  170 + define('LOG4PHP_DEFAULT_INIT_OVERRIDE', false);
  171 + }
  172 +}
  173 +
  174 +if (!defined('LOG4PHP_CONFIGURATION')) {
  175 + if (isset($_ENV['log4php.configuration'])) {
  176 + /**
  177 + * @ignore
  178 + */
  179 + define('LOG4PHP_CONFIGURATION', trim($_ENV['log4php.configuration']));
  180 + } else {
  181 + /**
  182 + * Configuration file.
  183 + *
  184 + * <p>This constant tells configurator classes where the configuration
  185 + * file is located.</p>
  186 + * <p>If not set by user, log4php tries to set it automatically using
  187 + * (in order):</p>
  188 + *
  189 + * - the <code>$_ENV['log4php.configuration']</code> enviroment variable.
  190 + * - defaults to 'log4php.properties'.
  191 + *
  192 + * @var string
  193 + */
  194 + define('LOG4PHP_CONFIGURATION', 'log4php.properties');
  195 + }
  196 +}
  197 +
  198 +if (!defined('LOG4PHP_CONFIGURATOR_CLASS')) {
  199 + if ( strtolower(substr( LOG4PHP_CONFIGURATION, -4 )) == '.xml') {
  200 + /**
  201 + * @ignore
  202 + */
  203 + define('LOG4PHP_CONFIGURATOR_CLASS', LOG4PHP_DIR . '/xml/LoggerDOMConfigurator');
  204 + } else {
  205 + /**
  206 + * Holds the configurator class name.
  207 + *
  208 + * <p>This constant is set with the fullname (path included but non the
  209 + * .php extension) of the configurator class that init procedure will use.</p>
  210 + * <p>If not set by user, log4php tries to set it automatically.</p>
  211 + * <p>If {@link LOG4PHP_CONFIGURATION} has '.xml' extension set the
  212 + * constants to '{@link LOG4PHP_DIR}/xml/{@link LoggerDOMConfigurator}'.</p>
  213 + * <p>Otherwise set the constants to
  214 + * '{@link LOG4PHP_DIR}/{@link LoggerPropertyConfigurator}'.</p>
  215 + *
  216 + * <p><b>Security Note</b>: classfile pointed by this constant will be brutally
  217 + * included with a:
  218 + * <code>@include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php");</code></p>
  219 + *
  220 + * @var string
  221 + */
  222 + define('LOG4PHP_CONFIGURATOR_CLASS', LOG4PHP_DIR . '/LoggerPropertyConfigurator');
  223 + }
  224 +}
  225 +
  226 +if (!LOG4PHP_DEFAULT_INIT_OVERRIDE) {
  227 + if (!LoggerManagerDefaultInit())
  228 + LoggerLog::warn("LOG4PHP main() Default Init failed.");
  229 +}
  230 +
  231 +/**
  232 + * Default init procedure.
  233 + *
  234 + * <p>This procedure tries to configure the {@link LoggerHierarchy} using the
  235 + * configurator class defined via {@link LOG4PHP_CONFIGURATOR_CLASS} that tries
  236 + * to load the configurator file defined in {@link LOG4PHP_CONFIGURATION}.
  237 + * If something goes wrong a warn is raised.</p>
  238 + * <p>Users can skip this procedure using {@link LOG4PHP_DEFAULT_INIT_OVERRIDE}
  239 + * constant.</p>
  240 + *
  241 + * @return boolean
  242 + */
  243 +function LoggerManagerDefaultInit()
  244 +{
  245 + $configuratorClass = basename(LOG4PHP_CONFIGURATOR_CLASS);
  246 + if (!class_exists($configuratorClass)) {
  247 + include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php");
  248 + }
  249 + if (class_exists($configuratorClass)) {
  250 +
  251 + return call_user_func(array($configuratorClass, 'configure'), LOG4PHP_CONFIGURATION);
  252 +
  253 + } else {
  254 + LoggerLog::warn("LoggerManagerDefaultInit() Configurator '{$configuratorClass}' doesnt exists");
  255 + return false;
  256 + }
  257 +}
  258 +
... ...
thirdparty/apache-log4php/src/main/php/LoggerNDC.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +/**
  28 + */
  29 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  30 +
  31 +define('LOGGER_NDC_HT_SIZE', 7);
  32 +
  33 +/**
  34 + * This is the global repository of NDC stack
  35 + */
  36 +$GLOBALS['log4php.LoggerNDC.ht'] = array();
  37 +
  38 +/**
  39 + * This is the max depth of NDC stack
  40 + */
  41 +$GLOBALS['log4php.LoggerNDC.maxDepth'] = LOGGER_NDC_HT_SIZE;
  42 +
  43 +
  44 +/**
  45 + * The NDC class implements <i>nested diagnostic contexts</i> as
  46 + * defined by Neil Harrison in the article "Patterns for Logging
  47 + * Diagnostic Messages" part of the book "<i>Pattern Languages of
  48 + * Program Design 3</i>" edited by Martin et al.
  49 + *
  50 + * <p>A Nested Diagnostic Context, or NDC in short, is an instrument
  51 + * to distinguish interleaved log output from different sources. Log
  52 + * output is typically interleaved when a server handles multiple
  53 + * clients near-simultaneously.
  54 + *
  55 + * <p>Interleaved log output can still be meaningful if each log entry
  56 + * from different contexts had a distinctive stamp. This is where NDCs
  57 + * come into play.
  58 + *
  59 + * <p><i><b>Note that NDCs are managed on a per thread
  60 + * basis</b></i>. NDC operations such as {@link push()}, {@link pop()},
  61 + * {@link clear()}, {@link getDepth()} and {@link setMaxDepth()}
  62 + * affect the NDC of the <i>current</i> thread only. NDCs of other
  63 + * threads remain unaffected.
  64 + *
  65 + * <p>For example, a servlet can build a per client request NDC
  66 + * consisting the clients host name and other information contained in
  67 + * the the request. <i>Cookies</i> are another source of distinctive
  68 + * information. To build an NDC one uses the {@link push()}
  69 + * operation.</p>
  70 + *
  71 + * Simply put,
  72 + *
  73 + * - Contexts can be nested.
  74 + * - When entering a context, call
  75 + * <code>LoggerNDC::push()</code>
  76 + * As a side effect, if there is no nested diagnostic context for the
  77 + * current thread, this method will create it.
  78 + * - When leaving a context, call
  79 + * <code>LoggerNDC::pop()</code>
  80 + * - <b>When exiting a thread make sure to call {@link remove()}</b>
  81 + *
  82 + * <p>There is no penalty for forgetting to match each
  83 + * <code>push</code> operation with a corresponding <code>pop</code>,
  84 + * except the obvious mismatch between the real application context
  85 + * and the context set in the NDC.</p>
  86 + *
  87 + * <p>If configured to do so, {@link LoggerPatternLayout} and {@link LoggerLayoutTTCC}
  88 + * instances automatically retrieve the nested diagnostic
  89 + * context for the current thread without any user intervention.
  90 + * Hence, even if a servlet is serving multiple clients
  91 + * simultaneously, the logs emanating from the same code (belonging to
  92 + * the same category) can still be distinguished because each client
  93 + * request will have a different NDC tag.</p>
  94 + *
  95 + *
  96 + * @author Marco Vassura
  97 + * @version $Revision: 635069 $
  98 + * @package log4php
  99 + * @since 0.3
  100 + */
  101 +class LoggerNDC {
  102 +
  103 + /**
  104 + * Clear any nested diagnostic information if any. This method is
  105 + * useful in cases where the same thread can be potentially used
  106 + * over and over in different unrelated contexts.
  107 + *
  108 + * <p>This method is equivalent to calling the {@link setMaxDepth()}
  109 + * method with a zero <var>maxDepth</var> argument.
  110 + *
  111 + * @static
  112 + */
  113 + public static function clear()
  114 + {
  115 + LoggerLog::debug("LoggerNDC::clear()");
  116 +
  117 + $GLOBALS['log4php.LoggerNDC.ht'] = array();
  118 + }
  119 +
  120 + /**
  121 + * Never use this method directly, use the {@link LoggerLoggingEvent::getNDC()} method instead.
  122 + * @static
  123 + * @return array
  124 + */
  125 + public static function get()
  126 + {
  127 + LoggerLog::debug("LoggerNDC::get()");
  128 +
  129 + return $GLOBALS['log4php.LoggerNDC.ht'];
  130 + }
  131 +
  132 + /**
  133 + * Get the current nesting depth of this diagnostic context.
  134 + *
  135 + * @see setMaxDepth()
  136 + * @return integer
  137 + * @static
  138 + */
  139 + public static function getDepth()
  140 + {
  141 + LoggerLog::debug("LoggerNDC::getDepth()");
  142 +
  143 + return sizeof($GLOBALS['log4php.LoggerNDC.ht']);
  144 + }
  145 +
  146 + /**
  147 + * Clients should call this method before leaving a diagnostic
  148 + * context.
  149 + *
  150 + * <p>The returned value is the value that was pushed last. If no
  151 + * context is available, then the empty string "" is returned.</p>
  152 + *
  153 + * @return string The innermost diagnostic context.
  154 + * @static
  155 + */
  156 + public static function pop()
  157 + {
  158 + LoggerLog::debug("LoggerNDC::pop()");
  159 +
  160 + if (sizeof($GLOBALS['log4php.LoggerNDC.ht']) > 0) {
  161 + return array_pop($GLOBALS['log4php.LoggerNDC.ht']);
  162 + } else {
  163 + return '';
  164 + }
  165 + }
  166 +
  167 + /**
  168 + * Looks at the last diagnostic context at the top of this NDC
  169 + * without removing it.
  170 + *
  171 + * <p>The returned value is the value that was pushed last. If no
  172 + * context is available, then the empty string "" is returned.</p>
  173 + * @return string The innermost diagnostic context.
  174 + * @static
  175 + */
  176 + public static function peek()
  177 + {
  178 + LoggerLog::debug("LoggerNDC::peek()");
  179 +
  180 + if (sizeof($GLOBALS['log4php.LoggerNDC.ht']) > 0) {
  181 + return end($GLOBALS['log4php.LoggerNDC.ht']);
  182 + } else {
  183 + return '';
  184 + }
  185 + }
  186 +
  187 + /**
  188 + * Push new diagnostic context information for the current thread.
  189 + *
  190 + * <p>The contents of the <var>message</var> parameter is
  191 + * determined solely by the client.
  192 + *
  193 + * @param string $message The new diagnostic context information.
  194 + * @static
  195 + */
  196 + public static function push($message)
  197 + {
  198 + LoggerLog::debug("LoggerNDC::push()");
  199 +
  200 + array_push($GLOBALS['log4php.LoggerNDC.ht'], (string)$message);
  201 + }
  202 +
  203 + /**
  204 + * Remove the diagnostic context for this thread.
  205 + * @static
  206 + */
  207 + public static function remove()
  208 + {
  209 + LoggerLog::debug("LoggerNDC::remove()");
  210 +
  211 + LoggerNDC::clear();
  212 + }
  213 +
  214 + /**
  215 + * Set maximum depth of this diagnostic context. If the current
  216 + * depth is smaller or equal to <var>maxDepth</var>, then no
  217 + * action is taken.
  218 + *
  219 + * <p>This method is a convenient alternative to multiple
  220 + * {@link pop()} calls. Moreover, it is often the case that at
  221 + * the end of complex call sequences, the depth of the NDC is
  222 + * unpredictable. The {@link setMaxDepth()} method circumvents
  223 + * this problem.
  224 + *
  225 + * @param integer $maxDepth
  226 + * @see getDepth()
  227 + * @static
  228 + */
  229 + public static function setMaxDepth($maxDepth)
  230 + {
  231 + LoggerLog::debug("LoggerNDC::setMaxDepth() maxDepth='$maxDepth'");
  232 +
  233 + $maxDepth = (int)$maxDepth;
  234 + if ($maxDepth <= LOGGER_NDC_HT_SIZE) {
  235 + if (LoggerNDC::getDepth() > $maxDepth) {
  236 + $GLOBALS['log4php.LoggerNDC.ht'] = array_slice($GLOBALS['log4php.LoggerNDC.ht'], $maxDepth);
  237 + }
  238 + $GLOBALS['log4php.LoggerNDC.maxDepth'] = $maxDepth;
  239 + }
  240 + }
  241 +
  242 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerPropertyConfigurator.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +require_once(LOG4PHP_DIR . '/config/LoggerPropertySetter.php');
  28 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  29 +require_once(LOG4PHP_DIR . '/or/LoggerObjectRenderer.php');
  30 +require_once(LOG4PHP_DIR . '/or/LoggerRendererMap.php');
  31 +require_once(LOG4PHP_DIR . '/spi/LoggerConfigurator.php');
  32 +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php');
  33 +require_once(LOG4PHP_DIR . '/LoggerAppender.php');
  34 +require_once(LOG4PHP_DIR . '/LoggerDefaultCategoryFactory.php');
  35 +require_once(LOG4PHP_DIR . '/LoggerLayout.php');
  36 +require_once(LOG4PHP_DIR . '/LoggerLevel.php');
  37 +require_once(LOG4PHP_DIR . '/LoggerManager.php');
  38 +
  39 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX', "log4php.category.");
  40 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX', "log4php.logger.");
  41 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_FACTORY_PREFIX', "log4php.factory");
  42 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX', "log4php.additivity.");
  43 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX', "log4php.rootCategory");
  44 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX', "log4php.rootLogger");
  45 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_APPENDER_PREFIX', "log4php.appender.");
  46 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX', "log4php.renderer.");
  47 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_THRESHOLD_PREFIX', "log4php.threshold");
  48 +
  49 +/**
  50 + * Key for specifying the {@link LoggerFactory}.
  51 + */
  52 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY', "log4php.loggerFactory");
  53 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_DEBUG_KEY', "log4php.debug");
  54 +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME', "root");
  55 +
  56 +
  57 +
  58 +/**
  59 + * Allows the configuration of log4php from an external file.
  60 + *
  61 + * See {@link doConfigure()} for the expected format.
  62 + *
  63 + * <p>It is sometimes useful to see how log4php is reading configuration
  64 + * files. You can enable log4php internal logging by defining the
  65 + * <b>log4php.debug</b> variable.</p>
  66 + *
  67 + * <p>The <i>LoggerPropertyConfigurator</i> does not handle the
  68 + * advanced configuration features supported by the {@link LoggerDOMConfigurator}
  69 + * such as support for {@link LoggerFilter},
  70 + custom {@link LoggerErrorHandlers}, nested appenders such as the
  71 + {@link Logger AsyncAppender},
  72 + * etc.
  73 + *
  74 + * <p>All option <i>values</i> admit variable substitution. The
  75 + * syntax of variable substitution is similar to that of Unix
  76 + * shells. The string between an opening <b>&quot;${&quot;</b> and
  77 + * closing <b>&quot;}&quot;</b> is interpreted as a key. The value of
  78 + * the substituted variable can be defined as a system property or in
  79 + * the configuration file itself. The value of the key is first
  80 + * searched in the defined constants, in the enviroments variables
  81 + * and if not found there, it is
  82 + * then searched in the configuration file being parsed. The
  83 + * corresponding value replaces the ${variableName} sequence.</p>
  84 + * <p>For example, if <b>$_ENV['home']</b> env var is set to
  85 + * <b>/home/xyz</b>, then every occurrence of the sequence
  86 + * <b>${home}</b> will be interpreted as
  87 + * <b>/home/xyz</b>. See {@link LoggerOptionConverter::getSystemProperty()}
  88 + * for details.</p>
  89 + *
  90 + * <p>Please note that boolean values should be quoted otherwise the default
  91 + * value will be chosen. E.g.:
  92 + * <code>
  93 + * // Does *not* work. Will always result in default value
  94 + * // (which is currently 'true' for this attribute).
  95 + * log4php.appender.A2.append=false
  96 + * // Does work.
  97 + * log4php.appender.A2.append="false"
  98 + * </code>
  99 + * </p>
  100 + *
  101 + * @author Marco Vassura
  102 + * @version $Revision: 635069 $
  103 + * @package log4php
  104 + * @since 0.5
  105 + */
  106 +class LoggerPropertyConfigurator implements LoggerConfigurator {
  107 +
  108 + /**
  109 + * @var LoggerFactory
  110 + */
  111 + var $loggerFactory = null;
  112 +
  113 + /**
  114 + * Constructor
  115 + */
  116 + public function LoggerPropertyConfigurator() {
  117 + $this->loggerFactory = new LoggerDefaultCategoryFactory();
  118 + }
  119 +
  120 + /**
  121 + * Configure the default repository using the resource pointed by <b>url</b>.
  122 + * <b>Url</b> is any valid resurce as defined in {@link PHP_MANUAL#file} function.
  123 + * Note that the resource will be search with <i>use_include_path</i> parameter
  124 + * set to "1".
  125 + *
  126 + * @param string $url
  127 + * @return boolean configuration result
  128 + * @static
  129 + */
  130 + public static function configure($url = '') {
  131 + $configurator = new LoggerPropertyConfigurator();
  132 + $repository =& LoggerManager::getLoggerRepository();
  133 + return $configurator->doConfigure($url, $repository);
  134 + }
  135 +
  136 + /**
  137 + * Read configuration from a file.
  138 + *
  139 + * <p>The function {@link PHP_MANUAL#parse_ini_file} is used to read the
  140 + * file.</p>
  141 + *
  142 + * <b>The existing configuration is not cleared nor reset.</b>
  143 + * If you require a different behavior, then call
  144 + * {@link LoggerManager::resetConfiguration()}
  145 + * method before calling {@link doConfigure()}.
  146 + *
  147 + * <p>The configuration file consists of statements in the format
  148 + * <b>key=value</b>. The syntax of different configuration
  149 + * elements are discussed below.
  150 + *
  151 + * <p><b>Repository-wide threshold</b></p>
  152 + *
  153 + * <p>The repository-wide threshold filters logging requests by level
  154 + * regardless of logger. The syntax is:
  155 + *
  156 + * <pre>
  157 + * log4php.threshold=[level]
  158 + * </pre>
  159 + *
  160 + * <p>The level value can consist of the string values OFF, FATAL,
  161 + * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A
  162 + * custom level value can be specified in the form
  163 + * <samp>level#classname</samp>. By default the repository-wide threshold is set
  164 + * to the lowest possible value, namely the level <b>ALL</b>.
  165 + * </p>
  166 + *
  167 + *
  168 + * <p><b>Appender configuration</b></p>
  169 + *
  170 + * <p>Appender configuration syntax is:</p>
  171 + * <pre>
  172 + * ; For appender named <i>appenderName</i>, set its class.
  173 + * ; Note: The appender name can contain dots.
  174 + * log4php.appender.appenderName=name_of_appender_class
  175 + *
  176 + * ; Set appender specific options.
  177 + *
  178 + * log4php.appender.appenderName.option1=value1
  179 + * log4php.appender.appenderName.optionN=valueN
  180 + * </pre>
  181 + *
  182 + * For each named appender you can configure its {@link LoggerLayout}. The
  183 + * syntax for configuring an appender's layout is:
  184 + * <pre>
  185 + * log4php.appender.appenderName.layout=name_of_layout_class
  186 + * log4php.appender.appenderName.layout.option1=value1
  187 + * ....
  188 + * log4php.appender.appenderName.layout.optionN=valueN
  189 + * </pre>
  190 + *
  191 + * <p><b>Configuring loggers</b></p>
  192 + *
  193 + * <p>The syntax for configuring the root logger is:
  194 + * <pre>
  195 + * log4php.rootLogger=[level], appenderName, appenderName, ...
  196 + * </pre>
  197 + *
  198 + * <p>This syntax means that an optional <i>level</i> can be
  199 + * supplied followed by appender names separated by commas.
  200 + *
  201 + * <p>The level value can consist of the string values OFF, FATAL,
  202 + * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A
  203 + * custom level value can be specified in the form</p>
  204 + *
  205 + * <pre>level#classname</pre>
  206 + *
  207 + * <p>If a level value is specified, then the root level is set
  208 + * to the corresponding level. If no level value is specified,
  209 + * then the root level remains untouched.
  210 + *
  211 + * <p>The root logger can be assigned multiple appenders.
  212 + *
  213 + * <p>Each <i>appenderName</i> (separated by commas) will be added to
  214 + * the root logger. The named appender is defined using the
  215 + * appender syntax defined above.
  216 + *
  217 + * <p>For non-root categories the syntax is almost the same:
  218 + * <pre>
  219 + * log4php.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ...
  220 + * </pre>
  221 + *
  222 + * <p>The meaning of the optional level value is discussed above
  223 + * in relation to the root logger. In addition however, the value
  224 + * INHERITED can be specified meaning that the named logger should
  225 + * inherit its level from the logger hierarchy.</p>
  226 + *
  227 + * <p>If no level value is supplied, then the level of the
  228 + * named logger remains untouched.</p>
  229 + *
  230 + * <p>By default categories inherit their level from the
  231 + * hierarchy. However, if you set the level of a logger and later
  232 + * decide that that logger should inherit its level, then you should
  233 + * specify INHERITED as the value for the level value. NULL is a
  234 + * synonym for INHERITED.</p>
  235 + *
  236 + * <p>Similar to the root logger syntax, each <i>appenderName</i>
  237 + * (separated by commas) will be attached to the named logger.</p>
  238 + *
  239 + * <p>See the <i>appender additivity rule</i> in the user manual for
  240 + * the meaning of the <b>additivity</b> flag.
  241 + *
  242 + * <p><b>ObjectRenderers</b></p>
  243 + *
  244 + * <p>You can customize the way message objects of a given type are
  245 + * converted to String before being logged. This is done by
  246 + * specifying a {@link LoggerObjectRenderer}
  247 + * for the object type would like to customize.</p>
  248 + *
  249 + * <p>The syntax is:
  250 + *
  251 + * <pre>
  252 + * log4php.renderer.name_of_rendered_class=name_of_rendering.class
  253 + * </pre>
  254 + *
  255 + * As in,
  256 + * <pre>
  257 + * log4php.renderer.myFruit=myFruitRenderer
  258 + * </pre>
  259 + *
  260 + * <p><b>Logger Factories</b></p>
  261 + *
  262 + * The usage of custom logger factories is discouraged and no longer
  263 + * documented.
  264 + *
  265 + * <p><b>Example</b></p>
  266 + *
  267 + * <p>An example configuration is given below. Other configuration
  268 + * file examples are given in the <b>tests</b> folder.
  269 + *
  270 + * <pre>
  271 + * ; Set options for appender named "A1".
  272 + * ; Appender "A1" will be a LoggerAppenderSyslog
  273 + * log4php.appender.A1=LoggerAppenderSyslog
  274 + *
  275 + * ; The syslog daemon resides on www.abc.net
  276 + * log4php.appender.A1.ident=log4php-test
  277 + *
  278 + * ; A1's layout is a LoggerPatternLayout, using the conversion pattern
  279 + * ; <b>%r %-5p %c{2} %M.%L %x - %m%n</b>. Thus, the log output will
  280 + * ; include the relative time since the start of the application in
  281 + * ; milliseconds, followed by the level of the log request,
  282 + * ; followed by the two rightmost components of the logger name,
  283 + * ; followed by the callers method name, followed by the line number,
  284 + * ; the nested disgnostic context and finally the message itself.
  285 + * ; Refer to the documentation of LoggerPatternLayout} for further information
  286 + * ; on the syntax of the ConversionPattern key.
  287 + * log4php.appender.A1.layout=LoggerPatternLayout
  288 + * log4php.appender.A1.layout.ConversionPattern="%-4r %-5p %c{2} %M.%L %x - %m%n"
  289 + *
  290 + * ; Set options for appender named "A2"
  291 + * ; A2 should be a LoggerAppenderRollingFile, with maximum file size of 10 MB
  292 + * ; using at most one backup file. A2's layout is TTCC, using the
  293 + * ; ISO8061 date format with context printing enabled.
  294 + * log4php.appender.A2=LoggerAppenderRollingFile
  295 + * log4php.appender.A2.MaxFileSize=10MB
  296 + * log4php.appender.A2.MaxBackupIndex=1
  297 + * log4php.appender.A2.layout=LoggerLayoutTTCC
  298 + * log4php.appender.A2.layout.ContextPrinting="true"
  299 + * log4php.appender.A2.layout.DateFormat="%c"
  300 + *
  301 + * ; Root logger set to DEBUG using the A2 appender defined above.
  302 + * log4php.rootLogger=DEBUG, A2
  303 + *
  304 + * ; Logger definitions:
  305 + * ; The SECURITY logger inherits is level from root. However, it's output
  306 + * ; will go to A1 appender defined above. It's additivity is non-cumulative.
  307 + * log4php.logger.SECURITY=INHERIT, A1
  308 + * log4php.additivity.SECURITY=false
  309 + *
  310 + * ; Only warnings or above will be logged for the logger "SECURITY.access".
  311 + * ; Output will go to A1.
  312 + * log4php.logger.SECURITY.access=WARN
  313 + *
  314 + *
  315 + * ; The logger "class.of.the.day" inherits its level from the
  316 + * ; logger hierarchy. Output will go to the appender's of the root
  317 + * ; logger, A2 in this case.
  318 + * log4php.logger.class.of.the.day=INHERIT
  319 + * </pre>
  320 + *
  321 + * <p>Refer to the <b>setOption</b> method in each Appender and
  322 + * Layout for class specific options.</p>
  323 + *
  324 + * <p>Use the <b>&quot;;&quot;</b> character at the
  325 + * beginning of a line for comments.</p>
  326 + *
  327 + * @param string $url The name of the configuration file where the
  328 + * configuration information is stored.
  329 + * @param LoggerHierarchy &$repository the repository to apply the configuration
  330 + */
  331 + function doConfigure($url, &$repository)
  332 + {
  333 + $properties = @parse_ini_file($url);
  334 + if ($properties === false) {
  335 + LoggerLog::warn("LoggerPropertyConfigurator::doConfigure() cannot load '$url' configuration.");
  336 + return false;
  337 + }
  338 + return $this->doConfigureProperties($properties, $repository);
  339 + }
  340 +
  341 +
  342 + /**
  343 + * Read configuration options from <b>properties</b>.
  344 + *
  345 + * @see doConfigure().
  346 + * @param array $properties
  347 + * @param LoggerHierarchy &$hierarchy
  348 + */
  349 + function doConfigureProperties($properties, &$hierarchy)
  350 + {
  351 + $value = null;
  352 +
  353 + if (isset($properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_DEBUG_KEY]))
  354 + {
  355 + $value = @$properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_DEBUG_KEY];
  356 + }
  357 +
  358 + if (!empty($value)) {
  359 + LoggerLog::internalDebugging(LoggerOptionConverter::toBoolean($value, LoggerLog::internalDebugging()));
  360 + }
  361 +
  362 + $thresholdStr = '';
  363 + if (isset($properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_THRESHOLD_PREFIX]))
  364 + {
  365 + $thresholdStr = @$properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_THRESHOLD_PREFIX];
  366 + }
  367 + $hierarchy->setThreshold(LoggerOptionConverter::toLevel($thresholdStr, LoggerLevel::getLevelAll()));
  368 +
  369 + $this->configureRootCategory($properties, $hierarchy);
  370 + $this->configureLoggerFactory($properties);
  371 + $this->parseCatsAndRenderers($properties, $hierarchy);
  372 +
  373 + LoggerLog::debug("LoggerPropertyConfigurator::doConfigureProperties() Finished configuring.");
  374 +
  375 + return true;
  376 + }
  377 +
  378 + // --------------------------------------------------------------------------
  379 + // Internal stuff
  380 + // --------------------------------------------------------------------------
  381 +
  382 + /**
  383 + * Check the provided <b>Properties</b> object for a
  384 + * {@link LoggerFactory} entry specified by
  385 + * {@link LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY}.
  386 + *
  387 + * If such an entry exists, an attempt is made to create an instance using
  388 + * the default constructor.
  389 + * This instance is used for subsequent Category creations
  390 + * within this configurator.
  391 + *
  392 + * @see parseCatsAndRenderers()
  393 + * @param array $props array of properties
  394 + */
  395 + function configureLoggerFactory($props)
  396 + {
  397 + $factoryFqcn = null;
  398 + if (isset($props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY]))
  399 + {
  400 + $factoryFqcn = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY];
  401 + }
  402 + if(!empty($factoryFqcn)) {
  403 + $factoryClassName = basename($factoryFqcn);
  404 + LoggerLog::debug(
  405 + "LoggerPropertyConfigurator::configureLoggerFactory() Trying to load factory [" .
  406 + $factoryClassName .
  407 + "]."
  408 + );
  409 +
  410 + if (!class_exists($factoryClassName))
  411 + @include_once("{$factoryFqcn}.php");
  412 + if (class_exists($factoryClassName)) {
  413 + $loggerFactory = new $factoryClassName();
  414 + } else {
  415 + LoggerLog::debug(
  416 + "LoggerPropertyConfigurator::configureLoggerFactory() Unable to load factory [" .
  417 + $factoryClassName .
  418 + "]. Using default."
  419 + );
  420 + $loggerFactory = $this->loggerFactory;
  421 + }
  422 +
  423 + LoggerLog::debug(
  424 + "LoggerPropertyConfigurator::configureLoggerFactory() ".
  425 + "Setting properties for category factory [" . get_class($loggerFactory) . "]."
  426 + );
  427 +
  428 + LoggerPropertySetter::setPropertiesByObject($loggerFactory, $props, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_FACTORY_PREFIX . ".");
  429 + }
  430 + }
  431 +
  432 + /**
  433 + * @param array $props array of properties
  434 + * @param LoggerHierarchy &$hierarchy
  435 + */
  436 + function configureRootCategory($props, &$hierarchy)
  437 + {
  438 + $effectivePrefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX;
  439 + $value = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX];
  440 +
  441 + if(empty($value)) {
  442 + $value = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX];
  443 + $effectivePrefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX;
  444 + }
  445 +
  446 + if (empty($value)) {
  447 + LoggerLog::debug(
  448 + "LoggerPropertyConfigurator::configureRootCategory() ".
  449 + "Could not find root logger information. Is this OK?"
  450 + );
  451 + } else {
  452 + $root = $hierarchy->getRootLogger();
  453 + // synchronized(root) {
  454 + $this->parseCategory(
  455 + $props,
  456 + $root,
  457 + $effectivePrefix,
  458 + LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME,
  459 + $value
  460 + );
  461 + // }
  462 + }
  463 + }
  464 +
  465 + /**
  466 + * Parse non-root elements, such non-root categories and renderers.
  467 + *
  468 + * @param array $props array of properties
  469 + * @param LoggerHierarchy &$hierarchy
  470 + */
  471 + function parseCatsAndRenderers($props, &$hierarchy)
  472 + {
  473 + while(list($key,$value) = each($props)) {
  474 + if( strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX) === 0 or
  475 + strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX) === 0) {
  476 + if(strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX) === 0) {
  477 + $loggerName = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX));
  478 + } elseif (strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX) === 0) {
  479 + $loggerName = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX));
  480 + }
  481 + $logger =& $hierarchy->getLogger($loggerName, $this->loggerFactory);
  482 + // synchronized(logger) {
  483 + $this->parseCategory($props, $logger, $key, $loggerName, $value);
  484 + $this->parseAdditivityForLogger($props, $logger, $loggerName);
  485 + // }
  486 + } elseif (strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX) === 0) {
  487 + $renderedClass = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX));
  488 + $renderingClass = $value;
  489 + if (method_exists($hierarchy, 'addrenderer')) { // ?
  490 + LoggerRendererMap::addRenderer($hierarchy, $renderedClass, $renderingClass);
  491 + }
  492 + }
  493 + }
  494 + }
  495 +
  496 + /**
  497 + * Parse the additivity option for a non-root category.
  498 + *
  499 + * @param array $props array of properties
  500 + * @param Logger &$cat
  501 + * @param string $loggerName
  502 + */
  503 + function parseAdditivityForLogger($props, &$cat, $loggerName)
  504 + {
  505 + $value = LoggerOptionConverter::findAndSubst(
  506 + LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX . $loggerName,
  507 + $props
  508 + );
  509 + LoggerLog::debug(
  510 + "LoggerPropertyConfigurator::parseAdditivityForLogger() ".
  511 + "Handling " . LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX . $loggerName . "=[{$value}]"
  512 + );
  513 + // touch additivity only if necessary
  514 + if(!empty($value)) {
  515 + $additivity = LoggerOptionConverter::toBoolean($value, true);
  516 + LoggerLog::debug(
  517 + "LoggerPropertyConfigurator::parseAdditivityForLogger() ".
  518 + "Setting additivity for [{$loggerName}] to [{$additivity}]"
  519 + );
  520 + $cat->setAdditivity($additivity);
  521 + }
  522 + }
  523 +
  524 + /**
  525 + * This method must work for the root category as well.
  526 + *
  527 + * @param array $props array of properties
  528 + * @param Logger &$logger
  529 + * @param string $optionKey
  530 + * @param string $loggerName
  531 + * @param string $value
  532 + * @return Logger
  533 + */
  534 + public function parseCategory($props, &$logger, $optionKey, $loggerName, $value) {
  535 + LoggerLog::debug(
  536 + "LoggerPropertyConfigurator::parseCategory() ".
  537 + "Parsing for [{$loggerName}] with value=[{$value}]."
  538 + );
  539 +
  540 + // We must skip over ',' but not white space
  541 + $st = explode(',', $value);
  542 +
  543 + // If value is not in the form ", appender.." or "", then we should set
  544 + // the level of the loggeregory.
  545 +
  546 + if(!(empty($value) || @$value[0] == ',')) {
  547 + // just to be on the safe side...
  548 + if(sizeof($st) == 0)
  549 + return;
  550 +
  551 + $levelStr = current($st);
  552 + LoggerLog::debug(
  553 + "LoggerPropertyConfigurator::parseCategory() ".
  554 + "Level token is [$levelStr]."
  555 + );
  556 +
  557 + // If the level value is inherited, set category level value to
  558 + // null. We also check that the user has not specified inherited for the
  559 + // root category.
  560 + if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) {
  561 + if ($loggerName == LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME) {
  562 + LoggerLog::warn(
  563 + "LoggerPropertyConfigurator::parseCategory() ".
  564 + "The root logger cannot be set to null."
  565 + );
  566 + } else {
  567 + $logger->setLevel(null);
  568 + }
  569 + } else {
  570 + $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug()));
  571 + }
  572 + }
  573 +
  574 + // Begin by removing all existing appenders.
  575 + $logger->removeAllAppenders();
  576 + while($appenderName = next($st)) {
  577 + $appenderName = trim($appenderName);
  578 + if(empty($appenderName))
  579 + continue;
  580 + LoggerLog::debug(
  581 + "LoggerPropertyConfigurator::parseCategory() ".
  582 + "Parsing appender named [{$appenderName}]."
  583 + );
  584 + $appender = $this->parseAppender($props, $appenderName);
  585 + if($appender !== null) {
  586 + $logger->addAppender($appender);
  587 + }
  588 + }
  589 + }
  590 +
  591 + /**
  592 + * @param array $props array of properties
  593 + * @param string $appenderName
  594 + * @return LoggerAppender
  595 + */
  596 + function parseAppender($props, $appenderName)
  597 + {
  598 + $appender = LoggerAppender::singleton($appenderName);
  599 + if($appender !== null) {
  600 + LoggerLog::debug(
  601 + "LoggerPropertyConfigurator::parseAppender() ".
  602 + "Appender [{$appenderName}] was already parsed."
  603 + );
  604 + return $appender;
  605 + }
  606 + // Appender was not previously initialized.
  607 + $prefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_APPENDER_PREFIX . $appenderName;
  608 + $layoutPrefix = $prefix . ".layout";
  609 + $appenderClass = @$props[$prefix];
  610 + if (!empty($appenderClass)) {
  611 + $appender = LoggerAppender::singleton($appenderName, $appenderClass);
  612 + if($appender === null) {
  613 + LoggerLog::warn(
  614 + "LoggerPropertyConfigurator::parseAppender() ".
  615 + "Could not instantiate appender named [$appenderName]."
  616 + );
  617 + return null;
  618 + }
  619 + } else {
  620 + LoggerLog::warn(
  621 + "LoggerPropertyConfigurator::parseAppender() ".
  622 + "Could not instantiate appender named [$appenderName] with null className."
  623 + );
  624 + return null;
  625 + }
  626 +
  627 + $appender->setName($appenderName);
  628 + if( $appender->requiresLayout() ) {
  629 + LoggerLog::debug(
  630 + "LoggerPropertyConfigurator::parseAppender() ".
  631 + "Parsing layout section for [$appenderName]."
  632 + );
  633 + $layoutClass = @$props[$layoutPrefix];
  634 + $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props);
  635 + if (empty($layoutClass)) {
  636 + LoggerLog::warn(
  637 + "LoggerPropertyConfigurator::parseAppender() ".
  638 + "layout class is empty in '$layoutPrefix'. Using Simple layout"
  639 + );
  640 + $layout = LoggerLayout::factory('LoggerLayoutSimple');
  641 + } else {
  642 + $layout = LoggerLayout::factory($layoutClass);
  643 +
  644 + if($layout === null) {
  645 + LoggerLog::warn(
  646 + "LoggerPropertyConfigurator::parseAppender() ".
  647 + "cannot create layout '$layoutClass'. Using Simple layout"
  648 + );
  649 + $layout = LoggerLayout::factory('LoggerLayoutSimple');
  650 + }
  651 + }
  652 +
  653 + LoggerLog::debug(
  654 + "LoggerPropertyConfigurator::parseAppender() ".
  655 + "Parsing layout options for [$appenderName]."
  656 + );
  657 + LoggerPropertySetter::setPropertiesByObject($layout, $props, $layoutPrefix . ".");
  658 + LoggerLog::debug(
  659 + "LoggerPropertyConfigurator::parseAppender() ".
  660 + "End Parsing layout options for [$appenderName]."
  661 + );
  662 + $appender->setLayout($layout);
  663 +
  664 + }
  665 + LoggerPropertySetter::setPropertiesByObject($appender, $props, $prefix . ".");
  666 + LoggerLog::debug(
  667 + "LoggerPropertyConfigurator::parseAppender() ".
  668 + "Parsed [{$appenderName}] options."
  669 + );
  670 + return $appender;
  671 + }
  672 +
  673 +}
... ...
thirdparty/apache-log4php/src/main/php/LoggerRoot.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + */
  21 +
  22 +/**
  23 + * @ignore
  24 + */
  25 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  26 +
  27 +/**
  28 + */
  29 +require_once(LOG4PHP_DIR . '/Logger.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerLevel.php');
  31 +
  32 +/**
  33 + * The root logger.
  34 + *
  35 + * @author Marco Vassura
  36 + * @version $Revision: 635069 $
  37 + * @package log4php
  38 + * @see Logger
  39 + */
  40 +class LoggerRoot extends Logger {
  41 +
  42 + /**
  43 + * @var string name of logger
  44 + */
  45 + protected $name = 'root';
  46 +
  47 + /**
  48 + * @var object must be null for LoggerRoot
  49 + */
  50 + protected $parent = null;
  51 +
  52 +
  53 + /**
  54 + * Constructor
  55 + *
  56 + * @param integer $level initial log level
  57 + */
  58 + public function __construct($level = null)
  59 + {
  60 + parent::__construct($this->name);
  61 + if ($level == null)
  62 + $level = LoggerLevel::getLevelAll();
  63 + $this->setLevel($level);
  64 + }
  65 +
  66 + /**
  67 + * @return LoggerLevel the level
  68 + */
  69 + public function getChainedLevel()
  70 + {
  71 + return $this->level;
  72 + }
  73 +
  74 + /**
  75 + * Setting a null value to the level of the root category may have catastrophic results.
  76 + * @param LoggerLevel $level
  77 + */
  78 + public function setLevel($level)
  79 + {
  80 + if ($level != null) {
  81 + $this->level = $level;
  82 + }
  83 + }
  84 +
  85 + /**
  86 + * Please use setLevel() instead.
  87 + * @param LoggerLevel $level
  88 + * @deprecated
  89 + */
  90 + public function setPriority($level)
  91 + {
  92 + $this->setLevel($level);
  93 + }
  94 +
  95 + /**
  96 + * Always returns false.
  97 + * Because LoggerRoot has no parents, it returns false.
  98 + * @param Logger $parent
  99 + * @return boolean
  100 + */
  101 + public function setParent($parent)
  102 + {
  103 + return false;
  104 + }
  105 +}
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderAdodb.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  29 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  31 +
  32 +require_once(ADODB_DIR . '/adodb.inc.php');
  33 +
  34 +/**
  35 + * Appends log events to a db table using adodb class.
  36 + *
  37 + * <p>This appender uses a table in a database to log events.</p>
  38 + * <p>Parameters are {@link $host}, {@link $user}, {@link $password},
  39 + * {@link $database}, {@link $createTable}, {@link $table} and {@link $sql}.</p>
  40 + * <p>See examples in test directory.</p>
  41 + *
  42 + * @author sbw <sbw@ibiblio.org>
  43 + * @package log4php
  44 + * @subpackage appenders
  45 + * @since 0.9
  46 + */
  47 +class LoggerAppenderAdodb extends LoggerAppenderSkeleton {
  48 +
  49 + /**
  50 + * Create the log table if it does not exists (optional).
  51 + * @var boolean
  52 + */
  53 + var $createTable = true;
  54 +
  55 + /**
  56 + * The type of database to connect to
  57 + * @var string
  58 + */
  59 + var $type;
  60 +
  61 + /**
  62 + * Database user name
  63 + * @var string
  64 + */
  65 + var $user;
  66 +
  67 + /**
  68 + * Database password
  69 + * @var string
  70 + */
  71 + var $password;
  72 +
  73 + /**
  74 + * Database host to connect to
  75 + * @var string
  76 + */
  77 + var $host;
  78 +
  79 + /**
  80 + * Name of the database to connect to
  81 + * @var string
  82 + */
  83 + var $database;
  84 +
  85 + /**
  86 + * A {@link LoggerPatternLayout} string used to format a valid insert query (mandatory).
  87 + * @var string
  88 + */
  89 + var $sql;
  90 +
  91 + /**
  92 + * Table name to write events. Used only if {@link $createTable} is true.
  93 + * @var string
  94 + */
  95 + var $table;
  96 +
  97 + /**
  98 + * @var object Adodb instance
  99 + * @access private
  100 + */
  101 + var $db = null;
  102 +
  103 + /**
  104 + * @var boolean used to check if all conditions to append are true
  105 + * @access private
  106 + */
  107 + var $canAppend = true;
  108 +
  109 + /**
  110 + * @access private
  111 + */
  112 + var $requiresLayout = false;
  113 +
  114 + /**
  115 + * Constructor.
  116 + *
  117 + * @param string $name appender name
  118 + */
  119 + function LoggerAppenderDb($name)
  120 + {
  121 + $this->LoggerAppenderSkeleton($name);
  122 + }
  123 +
  124 + /**
  125 + * Setup db connection.
  126 + * Based on defined options, this method connects to db defined in {@link $dsn}
  127 + * and creates a {@link $table} table if {@link $createTable} is true.
  128 + * @return boolean true if all ok.
  129 + */
  130 + function activateOptions()
  131 + {
  132 + $this->db = &ADONewConnection($this->type);
  133 + if (! $this->db->PConnect($this->host, $this->user, $this->password, $this->database)) {
  134 + LoggerLog::debug("LoggerAppenderAdodb::activateOptions() DB Connect Error [".$this->db->ErrorMsg()."]");
  135 + $this->db = null;
  136 + $this->closed = true;
  137 + $this->canAppend = false;
  138 + return;
  139 + }
  140 +
  141 + $this->layout = LoggerLayout::factory('LoggerPatternLayout');
  142 + $this->layout->setConversionPattern($this->getSql());
  143 +
  144 + // test if log table exists
  145 + $sql = 'select * from ' . $this->table . ' where 1 = 0';
  146 + $dbrs = $this->db->Execute($sql);
  147 + if ($dbrs == false and $this->getCreateTable()) {
  148 + $query = "CREATE TABLE {$this->table} (timestamp varchar(32),logger varchar(32),level varchar(32),message varchar(64),thread varchar(32),file varchar(64),line varchar(4) );";
  149 +
  150 + LoggerLog::debug("LoggerAppenderAdodb::activateOptions() creating table '{$this->table}'... using sql='$query'");
  151 +
  152 + $result = $this->db->Execute($query);
  153 + if (! $result) {
  154 + LoggerLog::debug("LoggerAppenderAdodb::activateOptions() error while creating '{$this->table}'. Error is ".$this->db->ErrorMsg());
  155 + $this->canAppend = false;
  156 + return;
  157 + }
  158 + }
  159 + $this->canAppend = true;
  160 + }
  161 +
  162 + function append($event)
  163 + {
  164 + if ($this->canAppend) {
  165 +
  166 + $query = $this->layout->format($event);
  167 +
  168 + LoggerLog::debug("LoggerAppenderAdodb::append() query='$query'");
  169 +
  170 + $this->db->Execute($query);
  171 + }
  172 + }
  173 +
  174 + function close()
  175 + {
  176 + if ($this->db !== null)
  177 + $this->db->Close();
  178 + $this->closed = true;
  179 + }
  180 +
  181 + /**
  182 + * @return boolean
  183 + */
  184 + function getCreateTable()
  185 + {
  186 + return $this->createTable;
  187 + }
  188 +
  189 + /**
  190 + * @return string the sql pattern string
  191 + */
  192 + function getSql()
  193 + {
  194 + return $this->sql;
  195 + }
  196 +
  197 + /**
  198 + * @return string the table name to create
  199 + */
  200 + function getTable()
  201 + {
  202 + return $this->table;
  203 + }
  204 +
  205 + /**
  206 + * @return string the database to connect to
  207 + */
  208 + function getDatabase() {
  209 + return $this->database;
  210 + }
  211 +
  212 + /**
  213 + * @return string the database to connect to
  214 + */
  215 + function getHost() {
  216 + return $this->host;
  217 + }
  218 +
  219 + /**
  220 + * @return string the user to connect with
  221 + */
  222 + function getUser() {
  223 + return $this->user;
  224 + }
  225 +
  226 + /**
  227 + * @return string the password to connect with
  228 + */
  229 + function getPassword() {
  230 + return $this->password;
  231 + }
  232 +
  233 + /**
  234 + * @return string the type of database to connect to
  235 + */
  236 + function getType() {
  237 + return $this->type;
  238 + }
  239 +
  240 + function setCreateTable($flag)
  241 + {
  242 + $this->createTable = LoggerOptionConverter::toBoolean($flag, true);
  243 + }
  244 +
  245 + function setType($newType)
  246 + {
  247 + $this->type = $newType;
  248 + }
  249 +
  250 + function setDatabase($newDatabase)
  251 + {
  252 + $this->database = $newDatabase;
  253 + }
  254 +
  255 + function setHost($newHost)
  256 + {
  257 + $this->host = $newHost;
  258 + }
  259 +
  260 + function setUser($newUser)
  261 + {
  262 + $this->user = $newUser;
  263 + }
  264 +
  265 + function setPassword($newPassword)
  266 + {
  267 + $this->password = $newPassword;
  268 + }
  269 +
  270 + function setSql($sql)
  271 + {
  272 + $this->sql = $sql;
  273 + }
  274 +
  275 + function setTable($table)
  276 + {
  277 + $this->table = $table;
  278 + }
  279 +
  280 +}
  281 +
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderConsole.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/** @ignore */
  24 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  25 +
  26 +/**
  27 + */
  28 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  29 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  30 +
  31 +
  32 +/**
  33 + * ConsoleAppender appends log events to STDOUT or STDERR using a layout specified by the user.
  34 + *
  35 + * <p>Optional parameter is {@link $target}. The default target is Stdout.</p>
  36 + * <p><b>Note</b>: Use this Appender with command-line php scripts.
  37 + * On web scripts this appender has no effects.</p>
  38 + * <p>This appender requires a layout.</p>
  39 + *
  40 + * @author Marco Vassura
  41 + * @author Knut Urdalen <knut.urdalen@gmail.com>
  42 + * @version $Revision: 635069 $
  43 + * @package log4php
  44 + * @subpackage appender
  45 + */
  46 +class LoggerAppenderConsole extends LoggerAppenderSkeleton {
  47 +
  48 + const STDOUT = 'php://stdout';
  49 + const STDERR = 'php://stderr';
  50 +
  51 + /**
  52 + * Can be 'php://stdout' or 'php://stderr'. But it's better to use keywords <b>STDOUT</b> and <b>STDERR</b> (case insensitive).
  53 + * Default is STDOUT
  54 + * @var string
  55 + */
  56 + protected $target = 'php://stdout';
  57 +
  58 + /**
  59 + * @var boolean
  60 + * @access private
  61 + */
  62 + protected $requiresLayout = true;
  63 +
  64 + /**
  65 + * @var mixed the resource used to open stdout/stderr
  66 + * @access private
  67 + */
  68 + protected $fp = false;
  69 +
  70 + /**
  71 + * Set console target.
  72 + * @param mixed $value a constant or a string
  73 + */
  74 + public function setTarget($value) {
  75 + $v = trim($value);
  76 + if ($v == self::STDOUT || strtoupper($v) == 'STDOUT') {
  77 + $this->target = self::STDOUT;
  78 + } elseif ($v == self::STDERR || strtoupper($v) == 'STDERR') {
  79 + $target = self::STDERR;
  80 + } else {
  81 + LoggerLog::debug("Invalid target. Using '".self::STDOUT."' by default.");
  82 + }
  83 + }
  84 +
  85 + public function getTarget() {
  86 + return $this->target;
  87 + }
  88 +
  89 + public function activateOptions() {
  90 + $this->fp = fopen($this->getTarget(), 'w');
  91 + if($this->fp !== false && $this->layout !== null) {
  92 + fwrite($this->fp, $this->layout->getHeader());
  93 + }
  94 + $this->closed = (bool)($this->fp === false);
  95 + }
  96 +
  97 + /**
  98 + * @see LoggerAppender::close()
  99 + */
  100 + public function close() {
  101 + if ($this->fp && $this->layout !== null) {
  102 + fwrite($this->fp, $this->layout->getFooter());
  103 + fclose($this->fp);
  104 + }
  105 + $this->closed = true;
  106 + }
  107 +
  108 + protected function append($event) {
  109 + if ($this->fp && $this->layout !== null) {
  110 + fwrite($this->fp, $this->layout->format($event));
  111 + }
  112 + }
  113 +}
  114 +
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderDailyFile.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/appenders/LoggerAppenderFile.php');
  29 +
  30 +/**
  31 + * LoggerAppenderDailyFile appends log events to a file ne.
  32 + *
  33 + * A formatted version of the date pattern is used as to create the file name
  34 + * using the {@link PHP_MANUAL#sprintf} function.
  35 + * <p>Parameters are {@link $datePattern}, {@link $file}. Note that file
  36 + * parameter should include a '%s' identifier and should always be set
  37 + * before {@link $file} param.</p>
  38 + *
  39 + * @author Abel Gonzalez <agonzalez@lpsz.org>
  40 + * @author Knut Urdalen <knut.urdalen@gmail.com>
  41 + * @version $Revision: 635069 $
  42 + * @package log4php
  43 + * @subpackage appenders
  44 + */
  45 +class LoggerAppenderDailyFile extends LoggerAppenderFile {
  46 +
  47 + /**
  48 + * Format date.
  49 + * It follows the {@link PHP_MANUAL#date()} formatting rules and <b>should always be set before {@link $file} param</b>.
  50 + * @var string
  51 + */
  52 + public $datePattern = "Ymd";
  53 +
  54 + /**
  55 + * Sets date format for the file name.
  56 + * @param string $format a regular date() string format
  57 + */
  58 + public function setDatePattern($format) {
  59 + $this->datePattern = $format;
  60 + }
  61 +
  62 + /**
  63 + * @return string returns date format for the filename
  64 + */
  65 + public function getDatePattern() {
  66 + return $this->datePattern;
  67 + }
  68 +
  69 + /**
  70 + * The File property takes a string value which should be the name of the file to append to.
  71 + * Sets and opens the file where the log output will go.
  72 + *
  73 + * @see LoggerAppenderFile::setFile()
  74 + */
  75 + public function setFile() {
  76 + $numargs = func_num_args();
  77 + $args = func_get_args();
  78 +
  79 + if ($numargs == 1 and is_string($args[0])) {
  80 + parent::setFile( sprintf((string)$args[0], date($this->getDatePattern())) );
  81 + } elseif ($numargs == 2 and is_string($args[0]) and is_bool($args[1])) {
  82 + parent::setFile( sprintf((string)$args[0], date($this->getDatePattern())), $args[1] );
  83 + }
  84 + }
  85 +
  86 +}
  87 +
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderDb.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  29 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  31 +require_once('DB.php');
  32 +
  33 +/**
  34 + * Appends log events to a db table using PEAR::DB class.
  35 + *
  36 + * <p>This appender uses a table in a database to log events.</p>
  37 + * <p>Parameters are {@link $dsn}, {@link $createTable}, {@link table} and {@link $sql}.</p>
  38 + * <p>See examples in test directory.</p>
  39 + *
  40 + * @author Marco Vassura
  41 + * @version $Revision: 635069 $
  42 + * @package log4php
  43 + * @subpackage appenders
  44 + * @since 0.3
  45 + */
  46 +class LoggerAppenderDb extends LoggerAppenderSkeleton {
  47 +
  48 + /**
  49 + * Create the log table if it does not exists (optional).
  50 + * @var boolean
  51 + */
  52 + var $createTable = true;
  53 +
  54 + /**
  55 + * PEAR::Db Data source name. Read PEAR::Db for dsn syntax (mandatory).
  56 + * @var string
  57 + */
  58 + var $dsn;
  59 +
  60 + /**
  61 + * A {@link LoggerPatternLayout} string used to format a valid insert query (mandatory).
  62 + * @var string
  63 + */
  64 + var $sql;
  65 +
  66 + /**
  67 + * Table name to write events. Used only if {@link $createTable} is true.
  68 + * @var string
  69 + */
  70 + var $table;
  71 +
  72 + /**
  73 + * @var object PEAR::Db instance
  74 + * @access private
  75 + */
  76 + var $db = null;
  77 +
  78 + /**
  79 + * @var boolean used to check if all conditions to append are true
  80 + * @access private
  81 + */
  82 + var $canAppend = true;
  83 +
  84 + /**
  85 + * @access private
  86 + */
  87 + var $requiresLayout = false;
  88 +
  89 + /**
  90 + * Constructor.
  91 + *
  92 + * @param string $name appender name
  93 + */
  94 + function LoggerAppenderDb($name)
  95 + {
  96 + $this->LoggerAppenderSkeleton($name);
  97 + }
  98 +
  99 + /**
  100 + * Setup db connection.
  101 + * Based on defined options, this method connects to db defined in {@link $dsn}
  102 + * and creates a {@link $table} table if {@link $createTable} is true.
  103 + * @return boolean true if all ok.
  104 + */
  105 + function activateOptions()
  106 + {
  107 + $this->db = DB::connect($this->dsn);
  108 +
  109 + if (DB::isError($this->db)) {
  110 + LoggerLog::debug("LoggerAppenderDb::activateOptions() DB Connect Error [".$this->db->getMessage()."]");
  111 + $this->db = null;
  112 + $this->closed = true;
  113 + $this->canAppend = false;
  114 +
  115 + } else {
  116 +
  117 + $this->layout = LoggerLayout::factory('LoggerPatternLayout');
  118 + $this->layout->setConversionPattern($this->getSql());
  119 +
  120 + // test if log table exists
  121 + $tableInfo = $this->db->tableInfo($this->table, $mode = null);
  122 + if (DB::isError($tableInfo) and $this->getCreateTable()) {
  123 + $query = "CREATE TABLE {$this->table} (timestamp varchar(32),logger varchar(32),level varchar(32),message varchar(64),thread varchar(32),file varchar(64),line varchar(4) );";
  124 +
  125 + LoggerLog::debug("LoggerAppenderDb::activateOptions() creating table '{$this->table}'... using sql='$query'");
  126 +
  127 + $result = $this->db->query($query);
  128 + if (DB::isError($result)) {
  129 + LoggerLog::debug("LoggerAppenderDb::activateOptions() error while creating '{$this->table}'. Error is ".$result->getMessage());
  130 + $this->closed = true;
  131 + $this->canAppend = false;
  132 + return;
  133 + }
  134 + }
  135 + $this->canAppend = true;
  136 + $this->closed = false;
  137 + }
  138 +
  139 + }
  140 +
  141 + function append($event)
  142 + {
  143 + if ($this->canAppend) {
  144 +
  145 + $query = $this->layout->format($event);
  146 +
  147 + LoggerLog::debug("LoggerAppenderDb::append() query='$query'");
  148 +
  149 + $this->db->query($query);
  150 + }
  151 + }
  152 +
  153 + function close()
  154 + {
  155 + if ($this->db !== null)
  156 + $this->db->disconnect();
  157 + $this->closed = true;
  158 + }
  159 +
  160 + /**
  161 + * @return boolean
  162 + */
  163 + function getCreateTable()
  164 + {
  165 + return $this->createTable;
  166 + }
  167 +
  168 + /**
  169 + * @return string the defined dsn
  170 + */
  171 + function getDsn()
  172 + {
  173 + return $this->dsn;
  174 + }
  175 +
  176 + /**
  177 + * @return string the sql pattern string
  178 + */
  179 + function getSql()
  180 + {
  181 + return $this->sql;
  182 + }
  183 +
  184 + /**
  185 + * @return string the table name to create
  186 + */
  187 + function getTable()
  188 + {
  189 + return $this->table;
  190 + }
  191 +
  192 + function setCreateTable($flag)
  193 + {
  194 + $this->createTable = LoggerOptionConverter::toBoolean($flag, true);
  195 + }
  196 +
  197 + function setDsn($newDsn)
  198 + {
  199 + $this->dsn = $newDsn;
  200 + }
  201 +
  202 + function setSql($sql)
  203 + {
  204 + $this->sql = $sql;
  205 + }
  206 +
  207 + function setTable($table)
  208 + {
  209 + $this->table = $table;
  210 + }
  211 +
  212 +}
  213 +
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderEcho.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  31 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  32 +
  33 +/**
  34 + * LoggerAppenderEcho uses {@link PHP_MANUAL#echo echo} function to output events.
  35 + *
  36 + * <p>This appender requires a layout.</p>
  37 + *
  38 + * @author Marco Vassura
  39 + * @version $Revision: 635069 $
  40 + * @package log4php
  41 + * @subpackage appenders
  42 + */
  43 +class LoggerAppenderEcho extends LoggerAppenderSkeleton {
  44 +
  45 + /**
  46 + * @access private
  47 + */
  48 + var $requiresLayout = true;
  49 +
  50 + /**
  51 + * @var boolean used internally to mark first append
  52 + * @access private
  53 + */
  54 + var $firstAppend = true;
  55 +
  56 + function activateOptions()
  57 + {
  58 + $this->closed = false;
  59 + return;
  60 + }
  61 +
  62 + function close()
  63 + {
  64 + if (!$this->firstAppend)
  65 + echo $this->layout->getFooter();
  66 + $this->closed = true;
  67 + }
  68 +
  69 + function append($event)
  70 + {
  71 + LoggerLog::debug("LoggerAppenderEcho::append()");
  72 +
  73 + if ($this->layout !== null) {
  74 + if ($this->firstAppend) {
  75 + echo $this->layout->getHeader();
  76 + $this->firstAppend = false;
  77 + }
  78 + echo $this->layout->format($event);
  79 + }
  80 + }
  81 +}
  82 +
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderFile.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  29 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  31 +
  32 +/**
  33 + * FileAppender appends log events to a file.
  34 + *
  35 + * Parameters are ({@link $fileName} but option name is <b>file</b>),
  36 + * {@link $append}.
  37 + *
  38 + * @author Marco Vassura
  39 + * @author Knut Urdalen <knut.urdalen@gmail.com>
  40 + * @version $Revision: 640255 $
  41 + * @package log4php
  42 + * @subpackage appenders
  43 + */
  44 +class LoggerAppenderFile extends LoggerAppenderSkeleton {
  45 +
  46 + /**
  47 + * @var boolean if {@link $file} exists, appends events.
  48 + */
  49 + private $append = true;
  50 + /**
  51 + * @var string the file name used to append events
  52 + */
  53 + protected $fileName;
  54 + /**
  55 + * @var mixed file resource
  56 + */
  57 + protected $fp = false;
  58 +
  59 + public function __construct($name) {
  60 + parent::__construct($name);
  61 + $this->requiresLayout = true;
  62 + }
  63 +
  64 + public function activateOptions() {
  65 + $fileName = $this->getFile();
  66 + LoggerLog::debug("LoggerAppenderFile::activateOptions() opening file '{$fileName}'");
  67 + $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w'));
  68 + if ($this->fp) {
  69 + if ($this->getAppend())
  70 + fseek($this->fp, 0, SEEK_END);
  71 + fwrite($this->fp, $this->layout->getHeader());
  72 + $this->closed = false;
  73 + } else {
  74 + $this->closed = true;
  75 + }
  76 + }
  77 +
  78 + public function close() {
  79 + if($this->fp and $this->layout !== null) {
  80 + fwrite($this->fp, $this->layout->getFooter());
  81 + }
  82 +
  83 + $this->closeFile();
  84 + $this->closed = true;
  85 + }
  86 +
  87 + /**
  88 + * Closes the previously opened file.
  89 + */
  90 + public function closeFile() {
  91 + if ($this->fp)
  92 + fclose($this->fp);
  93 + }
  94 +
  95 + /**
  96 + * @return boolean
  97 + */
  98 + public function getAppend() {
  99 + return $this->append;
  100 + }
  101 +
  102 + /**
  103 + * @return string
  104 + */
  105 + public function getFile() {
  106 + return $this->getFileName();
  107 + }
  108 +
  109 + /**
  110 + * @return string
  111 + */
  112 + public function getFileName() {
  113 + return $this->fileName;
  114 + }
  115 +
  116 + /**
  117 + * Close any previously opened file and call the parent's reset.
  118 + */
  119 + public function reset() {
  120 + $this->closeFile();
  121 + $this->fileName = null;
  122 + parent::reset();
  123 + }
  124 +
  125 + public function setAppend($flag) {
  126 + $this->append = LoggerOptionConverter::toBoolean($flag, true);
  127 + }
  128 +
  129 + /**
  130 + * Sets and opens the file where the log output will go.
  131 + *
  132 + * This is an overloaded method. It can be called with:
  133 + * - setFile(string $fileName) to set filename.
  134 + * - setFile(string $fileName, boolean $append) to set filename and append.
  135 + */
  136 + public function setFile() {
  137 + $numargs = func_num_args();
  138 + $args = func_get_args();
  139 +
  140 + if ($numargs == 1 and is_string($args[0])) {
  141 + $this->setFileName($args[0]);
  142 + } elseif ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) {
  143 + $this->setFile($args[0]);
  144 + $this->setAppend($args[1]);
  145 + }
  146 + }
  147 +
  148 + public function setFileName($fileName) {
  149 + $this->fileName = $fileName;
  150 + }
  151 +
  152 + public function append($event) {
  153 + if ($this->fp and $this->layout !== null) {
  154 + LoggerLog::debug("LoggerAppenderFile::append()");
  155 + fwrite($this->fp, $this->layout->format($event));
  156 + }
  157 + }
  158 +}
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderMail.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  29 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  30 +
  31 +/**
  32 + * Appends log events to mail using php function {@link PHP_MANUAL#mail}.
  33 + *
  34 + * <p>Parameters are {@link $from}, {@link $to}, {@link $subject}.</p>
  35 + * <p>This appender requires a layout.</p>
  36 + *
  37 + * @author Marco Vassura
  38 + * @version $Revision: 635069 $
  39 + * @package log4php
  40 + * @subpackage appenders
  41 + */
  42 +class LoggerAppenderMail extends LoggerAppenderSkeleton {
  43 +
  44 + /**
  45 + * @var string 'from' field
  46 + */
  47 + var $from = null;
  48 +
  49 + /**
  50 + * @var string 'subject' field
  51 + */
  52 + var $subject = 'Log4php Report';
  53 +
  54 + /**
  55 + * @var string 'to' field
  56 + */
  57 + var $to = null;
  58 +
  59 + /**
  60 + * @var string used to create mail body
  61 + * @access private
  62 + */
  63 + var $body = '';
  64 +
  65 + /**
  66 + * Constructor.
  67 + *
  68 + * @param string $name appender name
  69 + */
  70 + public function __construct($name) {
  71 + parent::__construct($name);
  72 + $this->requiresLayout = true;
  73 + }
  74 +
  75 + public function activateOptions() {
  76 + $this->closed = false;
  77 + }
  78 +
  79 + public function close() {
  80 + $from = $this->from;
  81 + $to = $this->to;
  82 +
  83 + if (!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) {
  84 + $subject = $this->subject;
  85 + LoggerLog::debug("LoggerAppenderMail::close() sending mail from=[{$from}] to=[{$to}] subject=[{$subject}]");
  86 + mail(
  87 + $to, $subject,
  88 + $this->layout->getHeader() . $this->body . $this->layout->getFooter(),
  89 + "From: {$from}\r\n"
  90 + );
  91 + }
  92 + $this->closed = true;
  93 + }
  94 +
  95 + /**
  96 + * @return string
  97 + */
  98 + function getFrom()
  99 + {
  100 + return $this->from;
  101 + }
  102 +
  103 + /**
  104 + * @return string
  105 + */
  106 + function getSubject()
  107 + {
  108 + return $this->subject;
  109 + }
  110 +
  111 + /**
  112 + * @return string
  113 + */
  114 + function getTo()
  115 + {
  116 + return $this->to;
  117 + }
  118 +
  119 + function setSubject($subject)
  120 + {
  121 + $this->subject = $subject;
  122 + }
  123 +
  124 + function setTo($to)
  125 + {
  126 + $this->to = $to;
  127 + }
  128 +
  129 + function setFrom($from)
  130 + {
  131 + $this->from = $from;
  132 + }
  133 +
  134 + function append($event)
  135 + {
  136 + if ($this->layout !== null)
  137 + $this->body .= $this->layout->format($event);
  138 + }
  139 +}
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderMailEvent.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  31 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  32 +
  33 +/**
  34 + * Log events to an email address. It will be created an email for each event.
  35 + *
  36 + * <p>Parameters are
  37 + * {@link $smtpHost} (optional),
  38 + * {@link $port} (optional),
  39 + * {@link $from} (optional),
  40 + * {@link $to},
  41 + * {@link $subject} (optional).</p>
  42 + * <p>A layout is required.</p>
  43 + *
  44 + * @author Domenico Lordi <lordi@interfree.it>
  45 + * @author Marco Vassura
  46 + * @version $Revision: 635069 $
  47 + * @package log4php
  48 + * @subpackage appenders
  49 + */
  50 +class LoggerAppenderMailEvent extends LoggerAppenderSkeleton {
  51 +
  52 + /**
  53 + * @var string 'from' field
  54 + */
  55 + var $from = null;
  56 +
  57 + /**
  58 + * @var integer 'from' field
  59 + */
  60 + var $port = 25;
  61 +
  62 + /**
  63 + * @var string hostname.
  64 + */
  65 + var $smtpHost = null;
  66 +
  67 + /**
  68 + * @var string 'subject' field
  69 + */
  70 + var $subject = '';
  71 +
  72 + /**
  73 + * @var string 'to' field
  74 + */
  75 + var $to = null;
  76 +
  77 + /**
  78 + * @access private
  79 + */
  80 + var $requiresLayout = true;
  81 +
  82 + /**
  83 + * Constructor.
  84 + *
  85 + * @param string $name appender name
  86 + */
  87 + function LoggerAppenderMailEvent($name)
  88 + {
  89 + $this->LoggerAppenderSkeleton($name);
  90 + }
  91 +
  92 + function activateOptions()
  93 + {
  94 + $this->closed = false;
  95 + }
  96 +
  97 + function close()
  98 + {
  99 + $this->closed = true;
  100 + }
  101 +
  102 + /**
  103 + * @return string
  104 + */
  105 + function getFrom() { return $this->from; }
  106 +
  107 + /**
  108 + * @return integer
  109 + */
  110 + function getPort() { return $this->port; }
  111 +
  112 + /**
  113 + * @return string
  114 + */
  115 + function getSmtpHost() { return $this->smtpHost; }
  116 +
  117 + /**
  118 + * @return string
  119 + */
  120 + function getSubject() { return $this->subject; }
  121 +
  122 + /**
  123 + * @return string
  124 + */
  125 + function getTo() { return $this->to; }
  126 +
  127 + function setFrom($from) { $this->from = $from; }
  128 + function setPort($port) { $this->port = (int)$port; }
  129 + function setSmtpHost($smtpHost) { $this->smtpHost = $smtpHost; }
  130 + function setSubject($subject) { $this->subject = $subject; }
  131 + function setTo($to) { $this->to = $to; }
  132 +
  133 + function append($event)
  134 + {
  135 + $from = $this->getFrom();
  136 + $to = $this->getTo();
  137 + if (empty($from) or empty($to))
  138 + return;
  139 +
  140 + $smtpHost = $this->getSmtpHost();
  141 + $prevSmtpHost = ini_get('SMTP');
  142 + if (!empty($smtpHost)) {
  143 + ini_set('SMTP', $smtpHost);
  144 + } else {
  145 + $smtpHost = $prevSmtpHost;
  146 + }
  147 +
  148 + $smtpPort = $this->getPort();
  149 + $prevSmtpPort= ini_get('smtp_port');
  150 + if ($smtpPort > 0 and $smtpPort < 65535) {
  151 + ini_set('smtp_port', $smtpPort);
  152 + } else {
  153 + $smtpPort = $prevSmtpPort;
  154 + }
  155 +
  156 + LoggerLog::debug(
  157 + "LoggerAppenderMailEvent::append()" .
  158 + ":from=[{$from}]:to=[{$to}]:smtpHost=[{$smtpHost}]:smtpPort=[{$smtpPort}]"
  159 + );
  160 +
  161 + if (!@mail( $to, $this->getSubject(),
  162 + $this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event),
  163 + "From: {$from}\r\n"
  164 + )) {
  165 + LoggerLog::debug("LoggerAppenderMailEvent::append() mail error");
  166 + }
  167 +
  168 + ini_set('SMTP', $prevSmtpHost);
  169 + ini_set('smtp_port', $prevSmtpPort);
  170 + }
  171 +}
  172 +
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderNull.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/** @ignore */
  24 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  25 +
  26 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  27 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  28 +
  29 +/**
  30 + * A NullAppender merely exists, it never outputs a message to any device.
  31 + *
  32 + * @author Marco Vassura
  33 + * @version $Revision: 635069 $
  34 + * @package log4php
  35 + * @subpackage appenders
  36 + */
  37 +class LoggerAppenderNull extends LoggerAppenderSkeleton {
  38 +
  39 + /**
  40 + * @access private
  41 + */
  42 + protected $requiresLayout = false;
  43 +
  44 + public function activateOptions()
  45 + {
  46 + $this->closed = false;
  47 + }
  48 +
  49 + public function close()
  50 + {
  51 + $this->closed = true;
  52 + }
  53 +
  54 + /**
  55 + * Do nothing.
  56 + * How I Love it !! :)
  57 + *
  58 + * @param LoggerLoggingEvent $event
  59 + */
  60 + protected function append($event)
  61 + {
  62 + LoggerLog::debug("LoggerAppenderNull::append()");
  63 + }
  64 +}
  65 +
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderPhp.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  29 +require_once(LOG4PHP_DIR . '/LoggerLevel.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  31 +
  32 +/**
  33 + * Log events using php {@link PHP_MANUAL#trigger_error} function and a {@link LoggerLayoutTTCC} default layout.
  34 + *
  35 + * <p>Levels are mapped as follows:</p>
  36 + * - <b>level &lt; WARN</b> mapped to E_USER_NOTICE
  37 + * - <b>WARN &lt;= level &lt; ERROR</b> mapped to E_USER_WARNING
  38 + * - <b>level &gt;= ERROR</b> mapped to E_USER_ERROR
  39 + *
  40 + * @author Marco Vassura
  41 + * @version $Revision: 635069 $
  42 + * @package log4php
  43 + * @subpackage appenders
  44 + */
  45 +class LoggerAppenderPhp extends LoggerAppenderSkeleton {
  46 +
  47 +
  48 + public function activateOptions() {
  49 + $this->layout = LoggerLayout::factory('LoggerLayoutTTCC');
  50 + $this->closed = false;
  51 + }
  52 +
  53 + public function close() {
  54 + $this->closed = true;
  55 + }
  56 +
  57 + public function append($event) {
  58 + if ($this->layout !== null) {
  59 + LoggerLog::debug("LoggerAppenderPhp::append()");
  60 + $level = $event->getLevel();
  61 + if ($level->isGreaterOrEqual(LoggerLevel::getLevelError())) {
  62 + trigger_error($this->layout->format($event), E_USER_ERROR);
  63 + } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) {
  64 + trigger_error($this->layout->format($event), E_USER_WARNING);
  65 + } else {
  66 + trigger_error($this->layout->format($event), E_USER_NOTICE);
  67 + }
  68 + }
  69 + }
  70 +}
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderRollingFile.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/appenders/LoggerAppenderFile.php');
  29 +
  30 +/**
  31 + * LoggerAppenderRollingFile extends LoggerAppenderFile to backup the log files
  32 + * when they reach a certain size.
  33 + *
  34 + * <p>Parameters are {@link $maxFileSize}, {@link $maxBackupIndex}.</p>
  35 + *
  36 + * <p>Contributors: Sergio Strampelli.</p>
  37 + *
  38 + * @author Marco Vassura
  39 + * @version $Revision: 640254 $
  40 + * @package log4php
  41 + * @subpackage appenders
  42 + */
  43 +class LoggerAppenderRollingFile extends LoggerAppenderFile {
  44 +
  45 + /**
  46 + * Set the maximum size that the output file is allowed to reach
  47 + * before being rolled over to backup files.
  48 + *
  49 + * <p>In configuration files, the <var>MaxFileSize</var> option takes a
  50 + * long integer in the range 0 - 2^63. You can specify the value
  51 + * with the suffixes "KB", "MB" or "GB" so that the integer is
  52 + * interpreted being expressed respectively in kilobytes, megabytes
  53 + * or gigabytes. For example, the value "10KB" will be interpreted
  54 + * as 10240.</p>
  55 + * <p>The default maximum file size is 10MB.</p>
  56 + *
  57 + * <p>Note that MaxFileSize cannot exceed <b>2 GB</b>.</p>
  58 + *
  59 + * @var integer
  60 + */
  61 + var $maxFileSize = 10485760;
  62 +
  63 + /**
  64 + * Set the maximum number of backup files to keep around.
  65 + *
  66 + * <p>The <var>MaxBackupIndex</var> option determines how many backup
  67 + * files are kept before the oldest is erased. This option takes
  68 + * a positive integer value. If set to zero, then there will be no
  69 + * backup files and the log file will be truncated when it reaches
  70 + * MaxFileSize.</p>
  71 + * <p>There is one backup file by default.</p>
  72 + *
  73 + * @var integer
  74 + */
  75 + var $maxBackupIndex = 1;
  76 +
  77 + /**
  78 + * @var string the filename expanded
  79 + * @access private
  80 + */
  81 + var $expandedFileName = null;
  82 +
  83 + /**
  84 + * Constructor.
  85 + *
  86 + * @param string $name appender name
  87 + */
  88 + public function __construct($name) {
  89 + parent::__construct($name);
  90 + }
  91 +
  92 + /**
  93 + * Returns the value of the MaxBackupIndex option.
  94 + * @return integer
  95 + */
  96 + function getExpandedFileName() {
  97 + return $this->expandedFileName;
  98 + }
  99 +
  100 + /**
  101 + * Returns the value of the MaxBackupIndex option.
  102 + * @return integer
  103 + */
  104 + function getMaxBackupIndex() {
  105 + return $this->maxBackupIndex;
  106 + }
  107 +
  108 + /**
  109 + * Get the maximum size that the output file is allowed to reach
  110 + * before being rolled over to backup files.
  111 + * @return integer
  112 + */
  113 + function getMaximumFileSize() {
  114 + return $this->maxFileSize;
  115 + }
  116 +
  117 + /**
  118 + * Implements the usual roll over behaviour.
  119 + *
  120 + * <p>If MaxBackupIndex is positive, then files File.1, ..., File.MaxBackupIndex -1 are renamed to File.2, ..., File.MaxBackupIndex.
  121 + * Moreover, File is renamed File.1 and closed. A new File is created to receive further log output.
  122 + *
  123 + * <p>If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created.
  124 + */
  125 + function rollOver()
  126 + {
  127 + // If maxBackups <= 0, then there is no file renaming to be done.
  128 + if($this->maxBackupIndex > 0) {
  129 + $fileName = $this->getExpandedFileName();
  130 + // Delete the oldest file, to keep Windows happy.
  131 + $file = $fileName . '.' . $this->maxBackupIndex;
  132 + if (is_writable($file))
  133 + unlink($file);
  134 + // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
  135 + for ($i = $this->maxBackupIndex - 1; $i >= 1; $i--) {
  136 + $file = $fileName . "." . $i;
  137 + if (is_readable($file)) {
  138 + $target = $fileName . '.' . ($i + 1);
  139 + rename($file, $target);
  140 + }
  141 + }
  142 +
  143 + // Rename fileName to fileName.1
  144 + $target = $fileName . ".1";
  145 +
  146 + $this->closeFile(); // keep windows happy.
  147 +
  148 + $file = $fileName;
  149 + rename($file, $target);
  150 + }
  151 +
  152 + $this->setFile($fileName, false);
  153 + unset($this->fp);
  154 + $this->activateOptions();
  155 + }
  156 +
  157 + function setFileName($fileName)
  158 + {
  159 + $this->fileName = $fileName;
  160 + $this->expandedFileName = realpath($fileName);
  161 + LoggerLog::debug("LoggerAppenderRollingFile::setFileName():filename=[{$fileName}]:expandedFileName=[{$this->expandedFileName}]");
  162 + }
  163 +
  164 +
  165 + /**
  166 + * Set the maximum number of backup files to keep around.
  167 + *
  168 + * <p>The <b>MaxBackupIndex</b> option determines how many backup
  169 + * files are kept before the oldest is erased. This option takes
  170 + * a positive integer value. If set to zero, then there will be no
  171 + * backup files and the log file will be truncated when it reaches
  172 + * MaxFileSize.
  173 + *
  174 + * @param mixed $maxBackups
  175 + */
  176 + function setMaxBackupIndex($maxBackups)
  177 + {
  178 + if (is_numeric($maxBackups))
  179 + $this->maxBackupIndex = abs((int)$maxBackups);
  180 + }
  181 +
  182 + /**
  183 + * Set the maximum size that the output file is allowed to reach
  184 + * before being rolled over to backup files.
  185 + *
  186 + * @param mixed $maxFileSize
  187 + * @see setMaxFileSize()
  188 + */
  189 + function setMaximumFileSize($maxFileSize)
  190 + {
  191 + $this->setMaxFileSize($maxFileSize);
  192 + }
  193 +
  194 + /**
  195 + * Set the maximum size that the output file is allowed to reach
  196 + * before being rolled over to backup files.
  197 + * <p>In configuration files, the <b>MaxFileSize</b> option takes an
  198 + * long integer in the range 0 - 2^63. You can specify the value
  199 + * with the suffixes "KB", "MB" or "GB" so that the integer is
  200 + * interpreted being expressed respectively in kilobytes, megabytes
  201 + * or gigabytes. For example, the value "10KB" will be interpreted
  202 + * as 10240.
  203 + *
  204 + * @param mixed $value
  205 + */
  206 + function setMaxFileSize($value)
  207 + {
  208 + $maxFileSize = null;
  209 + $numpart = substr($value,0, strlen($value) -2);
  210 + $suffix = strtoupper(substr($value, -2));
  211 +
  212 + switch ($suffix) {
  213 + case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break;
  214 + case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break;
  215 + case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break;
  216 + default:
  217 + if (is_numeric($value)) {
  218 + $maxFileSize = (int)$value;
  219 + }
  220 + }
  221 +
  222 + if ($maxFileSize === null) {
  223 + LoggerLog::debug("LoggerAppenderRollingFile::setMaxFileSize():value=[$value] wrong declaration");
  224 + } else {
  225 + $this->maxFileSize = abs($maxFileSize);
  226 + }
  227 + }
  228 +
  229 + /**
  230 + * @param LoggerLoggingEvent $event
  231 + */
  232 + function append($event)
  233 + {
  234 + if ($this->fp) {
  235 + parent::append($event);
  236 + if (ftell($this->fp) > $this->getMaximumFileSize())
  237 + $this->rollOver();
  238 + }
  239 + }
  240 +}
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderSocket.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +define('LOG4PHP_LOGGER_APPENDER_SOCKET_DEFAULT_PORT', 4446);
  29 +define('LOG4PHP_LOGGER_APPENDER_SOCKET_DEFAULT_TIMEOUT', 30);
  30 +
  31 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  32 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  33 +require_once(LOG4PHP_DIR . '/LoggerLayout.php');
  34 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  35 +
  36 +/**
  37 + * Serialize events and send them to a network socket.
  38 + *
  39 + * Parameters are {@link $remoteHost}, {@link $port}, {@link $timeout},
  40 + * {@link $locationInfo}, {@link $useXml} and {@link $log4jNamespace}.
  41 + *
  42 + * @author Marco Vassura
  43 + * @version $Revision: 635069 $
  44 + * @package log4php
  45 + * @subpackage appenders
  46 + */
  47 +class LoggerAppenderSocket extends LoggerAppenderSkeleton {
  48 +
  49 + /**
  50 + * @var mixed socket connection resource
  51 + * @access private
  52 + */
  53 + var $sp = false;
  54 +
  55 + /**
  56 + * Target host. On how to define remote hostaname see
  57 + * {@link PHP_MANUAL#fsockopen}
  58 + * @var string
  59 + */
  60 + var $remoteHost = '';
  61 +
  62 + /**
  63 + * @var integer the network port.
  64 + */
  65 + var $port = LOG4PHP_LOGGER_APPENDER_SOCKET_DEFAULT_PORT;
  66 +
  67 + /**
  68 + * @var boolean get event's location info.
  69 + */
  70 + var $locationInfo = false;
  71 +
  72 + /**
  73 + * @var integer connection timeout
  74 + */
  75 + var $timeout = LOG4PHP_LOGGER_APPENDER_SOCKET_DEFAULT_TIMEOUT;
  76 +
  77 + /**
  78 + * @var boolean output events via {@link LoggerXmlLayout}
  79 + */
  80 + var $useXml = false;
  81 +
  82 + /**
  83 + * @var boolean forward this option to {@link LoggerXmlLayout}.
  84 + * Ignored if {@link $useXml} is <i>false</i>.
  85 + */
  86 + var $log4jNamespace = false;
  87 +
  88 + /**
  89 + * @var LoggerXmlLayout
  90 + * @access private
  91 + */
  92 + var $xmlLayout = null;
  93 +
  94 + /**
  95 + * Create a socket connection using defined parameters
  96 + */
  97 + public function activateOptions() {
  98 + LoggerLog::debug("LoggerAppenderSocket::activateOptions() creating a socket...");
  99 + $errno = 0;
  100 + $errstr = '';
  101 + $this->sp = @fsockopen($this->getRemoteHost(), $this->getPort(), $errno, $errstr, $this->getTimeout());
  102 + if ($errno) {
  103 + LoggerLog::debug("LoggerAppenderSocket::activateOptions() socket error [$errno] $errstr");
  104 + $this->closed = true;
  105 + } else {
  106 + LoggerLog::debug("LoggerAppenderSocket::activateOptions() socket created [".$this->sp."]");
  107 + if ($this->getUseXml()) {
  108 + $this->xmlLayout = LoggerLayout::factory('LoggerXmlLayout');
  109 + if ($this->xmlLayout === null) {
  110 + LoggerLog::debug("LoggerAppenderSocket::activateOptions() useXml is true but layout is null");
  111 + $this->setUseXml(false);
  112 + } else {
  113 + $this->xmlLayout->setLocationInfo($this->getLocationInfo());
  114 + $this->xmlLayout->setLog4jNamespace($this->getLog4jNamespace());
  115 + $this->xmlLayout->activateOptions();
  116 + }
  117 + }
  118 + $this->closed = false;
  119 + }
  120 + }
  121 +
  122 + public function close() {
  123 + fclose($this->sp);
  124 + $this->closed = true;
  125 + }
  126 +
  127 + /**
  128 + * @return string
  129 + */
  130 + public function getHostname() {
  131 + return $this->getRemoteHost();
  132 + }
  133 +
  134 + /**
  135 + * @return boolean
  136 + */
  137 + public function getLocationInfo() {
  138 + return $this->locationInfo;
  139 + }
  140 +
  141 + /**
  142 + * @return boolean
  143 + */
  144 + public function getLog4jNamespace() {
  145 + return $this->log4jNamespace;
  146 + }
  147 +
  148 + /**
  149 + * @return integer
  150 + */
  151 + public function getPort() {
  152 + return $this->port;
  153 + }
  154 +
  155 + public function getRemoteHost() {
  156 + return $this->remoteHost;
  157 + }
  158 +
  159 + /**
  160 + * @return integer
  161 + */
  162 + public function getTimeout() {
  163 + return $this->timeout;
  164 + }
  165 +
  166 + /**
  167 + * @var boolean
  168 + */
  169 + public function getUseXml() {
  170 + return $this->useXml;
  171 + }
  172 +
  173 + public function reset() {
  174 + $this->close();
  175 + parent::reset();
  176 + }
  177 +
  178 + /**
  179 + * @param mixed
  180 + */
  181 + public function setLocationInfo($flag) {
  182 + $this->locationInfo = LoggerOptionConverter::toBoolean($flag, $this->getLocationInfo());
  183 + }
  184 +
  185 + /**
  186 + * @param mixed
  187 + */
  188 + public function setLog4jNamespace($flag) {
  189 + $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, $this->getLog4jNamespace());
  190 + }
  191 +
  192 + /**
  193 + * @param integer
  194 + */
  195 + public function setPort($port) {
  196 + $port = LoggerOptionConverter::toInt($port, 0);
  197 + if ($port > 0 and $port < 65535)
  198 + $this->port = $port;
  199 + }
  200 +
  201 + /**
  202 + * @param string
  203 + */
  204 + public function setRemoteHost($hostname) {
  205 + $this->remoteHost = $hostname;
  206 + }
  207 +
  208 + /**
  209 + * @param integer
  210 + */
  211 + public function setTimeout($timeout) {
  212 + $this->timeout = LoggerOptionConverter::toInt($timeout, $this->getTimeout());
  213 + }
  214 +
  215 + /**
  216 + * @param mixed
  217 + */
  218 + public function setUseXml($flag) {
  219 + $this->useXml = LoggerOptionConverter::toBoolean($flag, $this->getUseXml());
  220 + }
  221 +
  222 + /**
  223 + * @param LoggerLoggingEvent
  224 + */
  225 + public function append($event) {
  226 + if ($this->sp) {
  227 +
  228 + LoggerLog::debug("LoggerAppenderSocket::append()");
  229 +
  230 + if ($this->getLocationInfo())
  231 + $event->getLocationInformation();
  232 +
  233 + if (!$this->getUseXml()) {
  234 + $sEvent = serialize($event);
  235 + fwrite($this->sp, $sEvent, strlen($sEvent));
  236 + } else {
  237 + fwrite($this->sp, $this->xmlLayout->format($event));
  238 + }
  239 +
  240 + // not sure about it...
  241 + fflush($this->sp);
  242 + }
  243 + }
  244 +}
  245 +
... ...
thirdparty/apache-log4php/src/main/php/appenders/LoggerAppenderSyslog.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage appenders
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  29 +require_once(LOG4PHP_DIR . '/LoggerLevel.php');
  30 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  31 +
  32 +/**
  33 + * Log events using php {@link PHP_MANUAL#syslog} function.
  34 + *
  35 + * Levels are mapped as follows:
  36 + * - <b>level &gt;= FATAL</b> to LOG_ALERT
  37 + * - <b>FATAL &gt; level &gt;= ERROR</b> to LOG_ERR
  38 + * - <b>ERROR &gt; level &gt;= WARN</b> to LOG_WARNING
  39 + * - <b>WARN &gt; level &gt;= INFO</b> to LOG_INFO
  40 + * - <b>INFO &gt; level &gt;= DEBUG</b> to LOG_DEBUG
  41 + *
  42 + * @author VxR <vxr@vxr.it>
  43 + * @version $Revision: 635069 $
  44 + * @package log4php
  45 + * @subpackage appenders
  46 + */
  47 +class LoggerAppenderSyslog extends LoggerAppenderSkeleton {
  48 +
  49 + /**
  50 + * The ident string is added to each message. Typically the name of your application.
  51 + *
  52 + * @var string Ident for your application
  53 + */
  54 + private $_ident = "Log4PHP Syslog-Event";
  55 +
  56 + /**
  57 + * The priority parameter value indicates the level of importance of the message.
  58 + * It is passed on to the Syslog daemon.
  59 + *
  60 + * @var int Syslog priority
  61 + */
  62 + private $_priority;
  63 +
  64 + /**
  65 + * The option used when generating a log message.
  66 + * It is passed on to the Syslog daemon.
  67 + *
  68 + * @var int Syslog priority
  69 + */
  70 + private $_option;
  71 +
  72 + /**
  73 + * The facility value indicates the source of the message.
  74 + * It is passed on to the Syslog daemon.
  75 + *
  76 + * @var const int Syslog facility
  77 + */
  78 + private $_facility;
  79 +
  80 + /**
  81 + * If it is necessary to define logging priority in the .properties-file,
  82 + * set this variable to "true".
  83 + *
  84 + * @var const int value indicating whether the priority of the message is defined in the .properties-file
  85 + * (or properties-array)
  86 + */
  87 + private $_overridePriority;
  88 +
  89 + /**
  90 + * Set the ident of the syslog message.
  91 + *
  92 + * @param string Ident
  93 + */
  94 + public function setIdent($ident) {
  95 + $this->_ident = $ident;
  96 + }
  97 +
  98 + /**
  99 + * Set the priority value for the syslog message.
  100 + *
  101 + * @param const int Priority
  102 + */
  103 + public function setPriority($priority) {
  104 + $this->_priority = $priority;
  105 + }
  106 +
  107 +
  108 + /**
  109 + * Set the facility value for the syslog message.
  110 + *
  111 + * @param const int Facility
  112 + */
  113 + public function setFacility($facility) {
  114 + $this->_facility = $facility;
  115 + }
  116 +
  117 + /**
  118 + * If the priority of the message to be sent can be defined by a value in the properties-file,
  119 + * set parameter value to "true".
  120 + *
  121 + * @param bool Override priority
  122 + */
  123 + public function setOverridePriority($overridePriority) {
  124 + $this->_overridePriority = $overridePriority;
  125 + }
  126 +
  127 + /**
  128 + * Set the option value for the syslog message.
  129 + * This value is used as a parameter for php openlog()
  130 + * and passed on to the syslog daemon.
  131 + *
  132 + * @param string $option
  133 + */
  134 + public function setOption($option) {
  135 + $this->_option = $option;
  136 + }
  137 +
  138 +
  139 + public function activateOptions() {
  140 + define_syslog_variables();
  141 + $this->closed = false;
  142 + }
  143 +
  144 + public function close() {
  145 + closelog();
  146 + $this->closed = true;
  147 + }
  148 +
  149 + public function append($event) {
  150 +
  151 + if($this->_option == NULL){
  152 + $this->_option = LOG_PID | LOG_CONS;
  153 + }
  154 +
  155 + // Attach the process ID to the message, use the facility defined in the .properties-file
  156 + openlog($this->_ident, $this->_option, $this->_facility);
  157 +
  158 + $level = $event->getLevel();
  159 + $message = $event->getRenderedMessage();
  160 +
  161 + // If the priority of a syslog message can be overridden by a value defined in the properties-file,
  162 + // use that value, else use the one that is defined in the code.
  163 + if($this->_overridePriority){
  164 + syslog($this->_priority, $message);
  165 + } else {
  166 + if ($level->isGreaterOrEqual(LoggerLevel::getLevelFatal())) {
  167 + syslog(LOG_ALERT, $message);
  168 + } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelError())) {
  169 + syslog(LOG_ERR, $message);
  170 + } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) {
  171 + syslog(LOG_WARNING, $message);
  172 + } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelInfo())) {
  173 + syslog(LOG_INFO, $message);
  174 + } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelDebug())) {
  175 + syslog(LOG_DEBUG, $message);
  176 + }
  177 + }
  178 + closelog();
  179 + }
  180 +}
... ...
thirdparty/apache-log4php/src/main/php/config/LoggerPropertyGetter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage config
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + * @author Marco Vassura
  30 + * @version $Revision: 635069 $
  31 + * @package log4php
  32 + * @subpackage config
  33 + * @since 0.5
  34 + * @todo Ehm... try to guess...
  35 + */
  36 +class LoggerPropertyGetter {
  37 +
  38 +}
  39 +
... ...
thirdparty/apache-log4php/src/main/php/config/LoggerPropertySetter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage config
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  29 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  30 +
  31 +/**
  32 + * General purpose Object property setter. Clients repeatedly invokes
  33 + * {@link setProperty()} in order to invoke setters
  34 + * on the Object specified in the constructor.
  35 + *
  36 + * Usage:
  37 + * <code>
  38 + * $ps = new LoggerPropertySetter($anObject);
  39 + * $ps->set("name", "Joe");
  40 + * $ps->set("age", 32);
  41 + * $ps->set("isMale", true);
  42 + * </code>
  43 + * will cause the invocations
  44 + * <code>
  45 + * $anObject->setName("Joe");
  46 + * $anObject->setAge(32);
  47 + * $anObject->setMale(true)
  48 + * </code>
  49 + * if such methods exist.
  50 + *
  51 + * @author Marco Vassura
  52 + * @version $Revision: 635069 $
  53 + * @package log4php
  54 + * @subpackage config
  55 + * @since 0.5
  56 + */
  57 +class LoggerPropertySetter {
  58 +
  59 + /**
  60 + * @var object the target object
  61 + * @access private
  62 + */
  63 + var $obj;
  64 +
  65 + /**
  66 + * Create a new LoggerPropertySetter for the specified Object.
  67 + * This is done in prepartion for invoking {@link setProperty()}
  68 + * one or more times.
  69 + * @param object &$obj the object for which to set properties
  70 + */
  71 + function LoggerPropertySetter(&$obj)
  72 + {
  73 + $this->obj =& $obj;
  74 + }
  75 +
  76 + /**
  77 + * Set the properties of an object passed as a parameter in one
  78 + * go. The <code>properties</code> are parsed relative to a
  79 + * <code>prefix</code>.
  80 + *
  81 + * @param object &$obj The object to configure.
  82 + * @param array $properties An array containing keys and values.
  83 + * @param string $prefix Only keys having the specified prefix will be set.
  84 + * @static
  85 + */
  86 + public static
  87 + function setPropertiesByObject(&$obj, $properties, $prefix)
  88 + {
  89 + $pSetter = new LoggerPropertySetter($obj);
  90 + return $pSetter->setProperties($properties, $prefix);
  91 + }
  92 +
  93 +
  94 + /**
  95 + * Set the properites for the object that match the
  96 + * <code>prefix</code> passed as parameter.
  97 + *
  98 + * @param array $properties An array containing keys and values.
  99 + * @param string $prefix Only keys having the specified prefix will be set.
  100 + */
  101 + function setProperties($properties, $prefix)
  102 + {
  103 + LoggerLog::debug("LoggerOptionConverter::setProperties():prefix=[{$prefix}]");
  104 +
  105 + $len = strlen($prefix);
  106 + while (list($key,) = each($properties)) {
  107 + if (strpos($key, $prefix) === 0) {
  108 + if (strpos($key, '.', ($len + 1)) > 0)
  109 + continue;
  110 + $value = LoggerOptionConverter::findAndSubst($key, $properties);
  111 + $key = substr($key, $len);
  112 + if ($key == 'layout' and $this->obj instanceof loggerappender) {
  113 + continue;
  114 + }
  115 + $this->setProperty($key, $value);
  116 + }
  117 + }
  118 + $this->activate();
  119 + }
  120 +
  121 + /**
  122 + * Set a property on this PropertySetter's Object. If successful, this
  123 + * method will invoke a setter method on the underlying Object. The
  124 + * setter is the one for the specified property name and the value is
  125 + * determined partly from the setter argument type and partly from the
  126 + * value specified in the call to this method.
  127 + *
  128 + * <p>If the setter expects a String no conversion is necessary.
  129 + * If it expects an int, then an attempt is made to convert 'value'
  130 + * to an int using new Integer(value). If the setter expects a boolean,
  131 + * the conversion is by new Boolean(value).
  132 + *
  133 + * @param string $name name of the property
  134 + * @param string $value String value of the property
  135 + */
  136 + function setProperty($name, $value)
  137 + {
  138 + LoggerLog::debug("LoggerOptionConverter::setProperty():name=[{$name}]:value=[{$value}]");
  139 +
  140 + if ($value === null) return;
  141 +
  142 + $method = "set" . ucfirst($name);
  143 +
  144 + if (!method_exists($this->obj, $method)) {
  145 + LoggerLog::warn(
  146 + "LoggerOptionConverter::setProperty() No such setter method for [{$name}] property in " .
  147 + get_class($this->obj) . "."
  148 + );
  149 + } else {
  150 + return call_user_func(array(&$this->obj, $method), $value);
  151 + }
  152 + }
  153 +
  154 + function activate()
  155 + {
  156 + LoggerLog::debug("LoggerOptionConverter::activate()");
  157 +
  158 + if (method_exists($this->obj, 'activateoptions')) {
  159 + return call_user_func(array(&$this->obj, 'activateoptions'));
  160 + } else {
  161 + LoggerLog::debug("LoggerOptionConverter::activate() Nothing to activate.");
  162 + }
  163 + }
  164 +}
... ...
thirdparty/apache-log4php/src/main/php/helpers/LoggerFormattingInfo.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage helpers
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  31 +
  32 +/**
  33 + * This class encapsulates the information obtained when parsing
  34 + * formatting modifiers in conversion modifiers.
  35 + *
  36 + * @author Marco Vassura
  37 + * @package log4php
  38 + * @subpackage spi
  39 + * @since 0.3
  40 + */
  41 +class LoggerFormattingInfo {
  42 +
  43 + var $min = -1;
  44 + var $max = 0x7FFFFFFF;
  45 + var $leftAlign = false;
  46 +
  47 + /**
  48 + * Constructor
  49 + */
  50 + function LoggerFormattingInfo() {}
  51 +
  52 + function reset()
  53 + {
  54 + $this->min = -1;
  55 + $this->max = 0x7FFFFFFF;
  56 + $this->leftAlign = false;
  57 + }
  58 +
  59 + function dump()
  60 + {
  61 + LoggerLog::debug("LoggerFormattingInfo::dump() min={$this->min}, max={$this->max}, leftAlign={$this->leftAlign}");
  62 + }
  63 +}
... ...
thirdparty/apache-log4php/src/main/php/helpers/LoggerOptionConverter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage helpers
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerLevel.php');
  29 +
  30 +define('LOG4PHP_OPTION_CONVERTER_DELIM_START', '${');
  31 +define('LOG4PHP_OPTION_CONVERTER_DELIM_STOP', '}');
  32 +define('LOG4PHP_OPTION_CONVERTER_DELIM_START_LEN', 2);
  33 +define('LOG4PHP_OPTION_CONVERTER_DELIM_STOP_LEN', 1);
  34 +
  35 +/**
  36 + * A convenience class to convert property values to specific types.
  37 + *
  38 + * @author Marco Vassura
  39 + * @version $Revision: 635069 $
  40 + * @package log4php
  41 + * @subpackage helpers
  42 + * @static
  43 + * @since 0.5
  44 + */
  45 +class LoggerOptionConverter {
  46 +
  47 + /**
  48 + * @param array $l
  49 + * @param array $r
  50 + * @return array
  51 + *
  52 + * @static
  53 + */
  54 + public static function concatanateArrays($l, $r)
  55 + {
  56 + return array_merge($l, $r);
  57 + }
  58 +
  59 + /**
  60 + * Read a predefined var.
  61 + *
  62 + * It returns a value referenced by <var>$key</var> using this search criteria:
  63 + * - if <var>$key</var> is a constant then return it. Else
  64 + * - if <var>$key</var> is set in <var>$_ENV</var> then return it. Else
  65 + * - return <var>$def</var>.
  66 + *
  67 + * @param string $key The key to search for.
  68 + * @param string $def The default value to return.
  69 + * @return string the string value of the system property, or the default
  70 + * value if there is no property with that key.
  71 + *
  72 + * @static
  73 + */
  74 + public static function getSystemProperty($key, $def)
  75 + {
  76 + LoggerLog::debug("LoggerOptionConverter::getSystemProperty():key=[{$key}]:def=[{$def}].");
  77 +
  78 + if (defined($key)) {
  79 + return (string)constant($key);
  80 + } elseif (isset($_ENV[$key])) {
  81 + return (string)$_ENV[$key];
  82 + } else {
  83 + return $def;
  84 + }
  85 + }
  86 +
  87 + /**
  88 + * If <var>$value</var> is <i>true</i>, then <i>true</i> is
  89 + * returned. If <var>$value</var> is <i>false</i>, then
  90 + * <i>true</i> is returned. Otherwise, <var>$default</var> is
  91 + * returned.
  92 + *
  93 + * <p>Case of value is unimportant.</p>
  94 + *
  95 + * @param string $value
  96 + * @param boolean $default
  97 + * @return boolean
  98 + *
  99 + * @static
  100 + */
  101 + public static function toBoolean($value, $default)
  102 + {
  103 + if($value === null)
  104 + return $default;
  105 + if ($value == 1)
  106 + return true;
  107 + $trimmedVal = strtolower(trim($value));
  108 + if ("true" == $trimmedVal or "yes" == $trimmedVal)
  109 + return true;
  110 + if ("false" == $trimmedVal)
  111 + return false;
  112 + return $default;
  113 + }
  114 +
  115 + /**
  116 + * @param string $value
  117 + * @param integer $default
  118 + * @return integer
  119 + * @static
  120 + */
  121 + public static function toInt($value, $default)
  122 + {
  123 + $value = trim($value);
  124 + if (is_numeric($value)) {
  125 + return (int)$value;
  126 + } else {
  127 + return $default;
  128 + }
  129 + }
  130 +
  131 + /**
  132 + * Converts a standard or custom priority level to a Level
  133 + * object.
  134 + *
  135 + * <p> If <var>$value</var> is of form "<b>level#full_file_classname</b>",
  136 + * where <i>full_file_classname</i> means the class filename with path
  137 + * but without php extension, then the specified class' <i>toLevel()</i> method
  138 + * is called to process the specified level string; if no '#'
  139 + * character is present, then the default {@link LoggerLevel}
  140 + * class is used to process the level value.</p>
  141 + *
  142 + * <p>As a special case, if the <var>$value</var> parameter is
  143 + * equal to the string "NULL", then the value <i>null</i> will
  144 + * be returned.</p>
  145 + *
  146 + * <p>If any error occurs while converting the value to a level,
  147 + * the <var>$defaultValue</var> parameter, which may be
  148 + * <i>null</i>, is returned.</p>
  149 + *
  150 + * <p>Case of <var>$value</var> is insignificant for the level level, but is
  151 + * significant for the class name part, if present.</p>
  152 + *
  153 + * @param string $value
  154 + * @param LoggerLevel $defaultValue
  155 + * @return LoggerLevel a {@link LoggerLevel} or null
  156 + * @static
  157 + */
  158 + public static function toLevel($value, $defaultValue)
  159 + {
  160 + if($value === null)
  161 + return $defaultValue;
  162 +
  163 + $hashIndex = strpos($value, '#');
  164 + if ($hashIndex === false) {
  165 + if("NULL" == strtoupper($value)) {
  166 + return null;
  167 + } else {
  168 + // no class name specified : use standard Level class
  169 + return LoggerLevel::toLevel($value, $defaultValue);
  170 + }
  171 + }
  172 +
  173 + $result = $defaultValue;
  174 +
  175 + $clazz = substr($value, ($hashIndex + 1));
  176 + $levelName = substr($value, 0, $hashIndex);
  177 +
  178 + // This is degenerate case but you never know.
  179 + if("NULL" == strtoupper($levelName)) {
  180 + return null;
  181 + }
  182 +
  183 + LoggerLog::debug("LoggerOptionConverter::toLevel():class=[{$clazz}]:pri=[{$levelName}]");
  184 +
  185 + if (!class_exists($clazz))
  186 + @include_once("{$clazz}.php");
  187 +
  188 + $clazz = basename($clazz);
  189 +
  190 + if (class_exists($clazz)) {
  191 + $result = @call_user_func(array($clazz, 'toLevel'), $levelName, $defaultValue);
  192 + if (!is_a($result, 'loggerlevel')) {
  193 + LoggerLog::debug("LoggerOptionConverter::toLevel():class=[{$clazz}] cannot call toLevel(). Returning default.");
  194 + $result = $defaultValue;
  195 + }
  196 + } else {
  197 + LoggerLog::warn("LoggerOptionConverter::toLevel() class '{$clazz}' doesnt exists.");
  198 + }
  199 + return $result;
  200 + }
  201 +
  202 + /**
  203 + * @param string $value
  204 + * @param float $default
  205 + * @return float
  206 + *
  207 + * @static
  208 + */
  209 + public static function toFileSize($value, $default)
  210 + {
  211 + if ($value === null)
  212 + return $default;
  213 +
  214 + $s = strtoupper(trim($value));
  215 + $multiplier = (float)1;
  216 + if(($index = strpos($s, 'KB')) !== false) {
  217 + $multiplier = 1024;
  218 + $s = substr($s, 0, $index);
  219 + } elseif(($index = strpos($s, 'MB')) !== false) {
  220 + $multiplier = 1024 * 1024;
  221 + $s = substr($s, 0, $index);
  222 + } elseif(($index = strpos($s, 'GB')) !== false) {
  223 + $multiplier = 1024 * 1024 * 1024;
  224 + $s = substr($s, 0, $index);
  225 + }
  226 + if(is_numeric($s)) {
  227 + return (float)$s * $multiplier;
  228 + } else {
  229 + LoggerLog::warn("LoggerOptionConverter::toFileSize() [{$s}] is not in proper form.");
  230 + }
  231 + return $default;
  232 + }
  233 +
  234 + /**
  235 + * Find the value corresponding to <var>$key</var> in
  236 + * <var>$props</var>. Then perform variable substitution on the
  237 + * found value.
  238 + *
  239 + * @param string $key
  240 + * @param array $props
  241 + * @return string
  242 + *
  243 + * @static
  244 + */
  245 + public static function findAndSubst($key, $props)
  246 + {
  247 + $value = @$props[$key];
  248 + if(empty($value)) {
  249 + return null;
  250 + }
  251 + return LoggerOptionConverter::substVars($value, $props);
  252 + }
  253 +
  254 + /**
  255 + * Perform variable substitution in string <var>$val</var> from the
  256 + * values of keys found with the {@link getSystemProperty()} method.
  257 + *
  258 + * <p>The variable substitution delimeters are <b>${</b> and <b>}</b>.
  259 + *
  260 + * <p>For example, if the "MY_CONSTANT" contains "value", then
  261 + * the call
  262 + * <code>
  263 + * $s = LoggerOptionConverter::substituteVars("Value of key is ${MY_CONSTANT}.");
  264 + * </code>
  265 + * will set the variable <i>$s</i> to "Value of key is value.".</p>
  266 + *
  267 + * <p>If no value could be found for the specified key, then the
  268 + * <var>$props</var> parameter is searched, if the value could not
  269 + * be found there, then substitution defaults to the empty string.</p>
  270 + *
  271 + * <p>For example, if {@link getSystemProperty()} cannot find any value for the key
  272 + * "inexistentKey", then the call
  273 + * <code>
  274 + * $s = LoggerOptionConverter::substVars("Value of inexistentKey is [${inexistentKey}]");
  275 + * </code>
  276 + * will set <var>$s</var> to "Value of inexistentKey is []".</p>
  277 + *
  278 + * <p>A warn is thrown if <var>$val</var> contains a start delimeter "${"
  279 + * which is not balanced by a stop delimeter "}" and an empty string is returned.</p>
  280 + *
  281 + * @log4j-author Avy Sharell
  282 + *
  283 + * @param string $val The string on which variable substitution is performed.
  284 + * @param array $props
  285 + * @return string
  286 + *
  287 + * @static
  288 + */
  289 + public static function substVars($val, $props = null)
  290 + {
  291 + LoggerLog::debug("LoggerOptionConverter::substVars():val=[{$val}]");
  292 +
  293 + $sbuf = '';
  294 + $i = 0;
  295 + while(true) {
  296 + $j = strpos($val, LOG4PHP_OPTION_CONVERTER_DELIM_START, $i);
  297 + if ($j === false) {
  298 + LoggerLog::debug("LoggerOptionConverter::substVars() no more variables");
  299 + // no more variables
  300 + if ($i == 0) { // this is a simple string
  301 + LoggerLog::debug("LoggerOptionConverter::substVars() simple string");
  302 + return $val;
  303 + } else { // add the tail string which contails no variables and return the result.
  304 + $sbuf .= substr($val, $i);
  305 + LoggerLog::debug("LoggerOptionConverter::substVars():sbuf=[{$sbuf}]. Returning sbuf");
  306 + return $sbuf;
  307 + }
  308 + } else {
  309 +
  310 + $sbuf .= substr($val, $i, $j-$i);
  311 + LoggerLog::debug("LoggerOptionConverter::substVars():sbuf=[{$sbuf}]:i={$i}:j={$j}.");
  312 + $k = strpos($val, LOG4PHP_OPTION_CONVERTER_DELIM_STOP, $j);
  313 + if ($k === false) {
  314 + LoggerLog::warn(
  315 + "LoggerOptionConverter::substVars() " .
  316 + "'{$val}' has no closing brace. Opening brace at position {$j}."
  317 + );
  318 + return '';
  319 + } else {
  320 + $j += LOG4PHP_OPTION_CONVERTER_DELIM_START_LEN;
  321 + $key = substr($val, $j, $k - $j);
  322 + // first try in System properties
  323 + $replacement = LoggerOptionConverter::getSystemProperty($key, null);
  324 + // then try props parameter
  325 + if($replacement == null and $props !== null) {
  326 + $replacement = @$props[$key];
  327 + }
  328 +
  329 + if(!empty($replacement)) {
  330 + // Do variable substitution on the replacement string
  331 + // such that we can solve "Hello ${x2}" as "Hello p1"
  332 + // the where the properties are
  333 + // x1=p1
  334 + // x2=${x1}
  335 + $recursiveReplacement = LoggerOptionConverter::substVars($replacement, $props);
  336 + $sbuf .= $recursiveReplacement;
  337 + }
  338 + $i = $k + LOG4PHP_OPTION_CONVERTER_DELIM_STOP_LEN;
  339 + }
  340 + }
  341 + }
  342 + }
  343 +
  344 +}
... ...
thirdparty/apache-log4php/src/main/php/helpers/LoggerPatternConverter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage helpers
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  31 +
  32 +/**
  33 + * Array for fast space padding
  34 + * Used by {@link LoggerPatternConverter::spacePad()}.
  35 + */
  36 +$GLOBALS['log4php.LoggerPatternConverter.spaces'] = array(" ", " ", " ", " ", //1,2,4,8 spaces
  37 + " ", // 16 spaces
  38 + " " ); // 32 spaces
  39 +
  40 +/**
  41 + * LoggerPatternConverter is an abstract class that provides the formatting
  42 + * functionality that derived classes need.
  43 + *
  44 + * <p>Conversion specifiers in a conversion patterns are parsed to
  45 + * individual PatternConverters. Each of which is responsible for
  46 + * converting a logging event in a converter specific manner.</p>
  47 + *
  48 + * @author Marco Vassura
  49 + * @version $Revision: 635069 $
  50 + * @package log4php
  51 + * @subpackage helpers
  52 + * @abstract
  53 + * @since 0.3
  54 + */
  55 +class LoggerPatternConverter {
  56 +
  57 + /**
  58 + * @var LoggerPatternConverter next converter in converter chain
  59 + */
  60 + var $next = null;
  61 +
  62 + var $min = -1;
  63 + var $max = 0x7FFFFFFF;
  64 + var $leftAlign = false;
  65 +
  66 + /**
  67 + * Constructor
  68 + *
  69 + * @param LoggerFormattingInfo $fi
  70 + */
  71 + function LoggerPatternConverter($fi = null)
  72 + {
  73 + if ($fi !== null) {
  74 + $this->min = $fi->min;
  75 + $this->max = $fi->max;
  76 + $this->leftAlign = $fi->leftAlign;
  77 + }
  78 + }
  79 +
  80 + /**
  81 + * Derived pattern converters must override this method in order to
  82 + * convert conversion specifiers in the correct way.
  83 + *
  84 + * @param LoggerLoggingEvent $event
  85 + */
  86 + function convert($event) {}
  87 +
  88 + /**
  89 + * A template method for formatting in a converter specific way.
  90 + *
  91 + * @param string &$sbuf string buffer
  92 + * @param LoggerLoggingEvent $e
  93 + */
  94 + function format(&$sbuf, $e)
  95 + {
  96 + LoggerLog::debug("LoggerPatternConverter::format() sbuf='$sbuf'");
  97 +
  98 + $s = $this->convert($e);
  99 +
  100 + LoggerLog::debug("LoggerPatternConverter::format() converted event is '$s'");
  101 +
  102 +
  103 + if($s == null or empty($s)) {
  104 + if(0 < $this->min)
  105 + $this->spacePad($sbuf, $this->min);
  106 + return;
  107 + }
  108 +
  109 + $len = strlen($s);
  110 +
  111 + if($len > $this->max) {
  112 + $sbuf .= substr($s , 0, ($len - $this->max));
  113 + } elseif($len < $this->min) {
  114 + if($this->leftAlign) {
  115 + $sbuf .= $s;
  116 + $this->spacePad($sbuf, ($this->min - $len));
  117 + } else {
  118 + $this->spacePad($sbuf, ($this->min - $len));
  119 + $sbuf .= $s;
  120 + }
  121 + } else {
  122 + $sbuf .= $s;
  123 + }
  124 + }
  125 +
  126 +
  127 + /**
  128 + * Fast space padding method.
  129 + *
  130 + * @param string &$sbuf string buffer
  131 + * @param integer $length pad length
  132 + *
  133 + * @todo reimplement using PHP string functions
  134 + */
  135 + function spacePad(&$sbuf, $length)
  136 + {
  137 + LoggerLog::debug("LoggerPatternConverter::spacePad() sbuf='$sbuf' len='$length'");
  138 +
  139 + while($length >= 32) {
  140 + $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][5];
  141 + $length -= 32;
  142 + }
  143 +
  144 + for($i = 4; $i >= 0; $i--) {
  145 + if(($length & (1<<$i)) != 0) {
  146 + $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][$i];
  147 + }
  148 + }
  149 +
  150 + // $sbuf = str_pad($sbuf, $length);
  151 + }
  152 +}
  153 +
  154 +// ---------------------------------------------------------------------
  155 +// PatternConverters
  156 +// ---------------------------------------------------------------------
  157 +
  158 +/**
  159 + * @author Marco Vassura
  160 + * @package log4php
  161 + * @subpackage helpers
  162 + */
  163 +class LoggerBasicPatternConverter extends LoggerPatternConverter {
  164 +
  165 + /**
  166 + * @var integer
  167 + */
  168 + var $type;
  169 +
  170 + /**
  171 + * Constructor
  172 + *
  173 + * @param string $formattingInfo
  174 + * @param integer $type
  175 + */
  176 + function LoggerBasicPatternConverter($formattingInfo, $type)
  177 + {
  178 + LoggerLog::debug("LoggerBasicPatternConverter::LoggerBasicPatternConverter() type='$type'");
  179 +
  180 + $this->LoggerPatternConverter($formattingInfo);
  181 + $this->type = $type;
  182 + }
  183 +
  184 + /**
  185 + * @param LoggerLoggingEvent $event
  186 + * @return string
  187 + */
  188 + function convert($event)
  189 + {
  190 + switch($this->type) {
  191 + case LOG4PHP_LOGGER_PATTERN_PARSER_RELATIVE_TIME_CONVERTER:
  192 + $timeStamp = $event->getTimeStamp();
  193 + $startTime = LoggerLoggingEvent::getStartTime();
  194 + return (string)(int)($timeStamp * 1000 - $startTime * 1000);
  195 +
  196 + case LOG4PHP_LOGGER_PATTERN_PARSER_THREAD_CONVERTER:
  197 + return $event->getThreadName();
  198 +
  199 + case LOG4PHP_LOGGER_PATTERN_PARSER_LEVEL_CONVERTER:
  200 + $level = $event->getLevel();
  201 + return $level->toString();
  202 +
  203 + case LOG4PHP_LOGGER_PATTERN_PARSER_NDC_CONVERTER:
  204 + return $event->getNDC();
  205 +
  206 + case LOG4PHP_LOGGER_PATTERN_PARSER_MESSAGE_CONVERTER:
  207 + return $event->getRenderedMessage();
  208 +
  209 + default:
  210 + return '';
  211 + }
  212 + }
  213 +}
  214 +
  215 +/**
  216 + * @author Marco Vassura
  217 + * @package log4php
  218 + * @subpackage helpers
  219 + */
  220 +class LoggerLiteralPatternConverter extends LoggerPatternConverter {
  221 +
  222 + /**
  223 + * @var string
  224 + */
  225 + var $literal;
  226 +
  227 + /**
  228 + * Constructor
  229 + *
  230 + * @param string $value
  231 + */
  232 + function LoggerLiteralPatternConverter($value)
  233 + {
  234 + LoggerLog::debug("LoggerLiteralPatternConverter::LoggerLiteralPatternConverter() value='$value'");
  235 +
  236 + $this->literal = $value;
  237 + }
  238 +
  239 + /**
  240 + * @param string &$sbuf
  241 + * @param LoggerLoggingEvent $event
  242 + */
  243 + function format(&$sbuf, $event)
  244 + {
  245 + $sbuf .= $this->literal;
  246 + }
  247 +
  248 + /**
  249 + * @param LoggerLoggingEvent $event
  250 + * @return string
  251 + */
  252 + function convert($event)
  253 + {
  254 + return $this->literal;
  255 + }
  256 +}
  257 +
  258 +/**
  259 + * @author Marco Vassura
  260 + * @package log4php
  261 + * @subpackage helpers
  262 + */
  263 +class LoggerDatePatternConverter extends LoggerPatternConverter {
  264 +
  265 + /**
  266 + * @var string
  267 + */
  268 + var $df;
  269 +
  270 + /**
  271 + * Constructor
  272 + *
  273 + * @param string $formattingInfo
  274 + * @param string $df
  275 + */
  276 + function LoggerDatePatternConverter($formattingInfo, $df)
  277 + {
  278 + LoggerLog::debug("LoggerDatePatternConverter::LoggerDatePatternConverter() dateFormat='$df'");
  279 +
  280 + $this->LoggerPatternConverter($formattingInfo);
  281 + $this->df = $df;
  282 + }
  283 +
  284 + /**
  285 + * @param LoggerLoggingEvent $event
  286 + * @return string
  287 + */
  288 + function convert($event)
  289 + {
  290 + $timeStamp = $event->getTimeStamp();
  291 + $usecs = round(($timeStamp - (int)$timeStamp) * 1000);
  292 + $this->df = str_replace("\u", "u", ereg_replace("[^\\]u", sprintf(',%03d', $usecs), $this->df));
  293 +
  294 + return date($this->df, $event->getTimeStamp());
  295 +
  296 + }
  297 +}
  298 +
  299 +/**
  300 + * @author Marco Vassura
  301 + * @package log4php
  302 + * @subpackage helpers
  303 + */
  304 +class LoggerMDCPatternConverter extends LoggerPatternConverter {
  305 +
  306 + /**
  307 + * @var string
  308 + */
  309 + var $key;
  310 +
  311 + /**
  312 + * Constructor
  313 + *
  314 + * @param string $formattingInfo
  315 + * @param string $key
  316 + */
  317 + function LoggerMDCPatternConverter($formattingInfo, $key)
  318 + {
  319 + LoggerLog::debug("LoggerMDCPatternConverter::LoggerMDCPatternConverter() key='$key'");
  320 +
  321 + $this->LoggerPatternConverter($formattingInfo);
  322 + $this->key = $key;
  323 + }
  324 +
  325 + /**
  326 + * @param LoggerLoggingEvent $event
  327 + * @return string
  328 + */
  329 + function convert($event)
  330 + {
  331 + return $event->getMDC($this->key);
  332 + }
  333 +}
  334 +
  335 +/**
  336 + * @author Marco Vassura
  337 + * @package log4php
  338 + * @subpackage helpers
  339 + */
  340 +class LoggerLocationPatternConverter extends LoggerPatternConverter {
  341 +
  342 + /**
  343 + * @var integer
  344 + */
  345 + var $type;
  346 +
  347 + /**
  348 + * Constructor
  349 + *
  350 + * @param string $formattingInfo
  351 + * @param integer $type
  352 + */
  353 + function LoggerLocationPatternConverter($formattingInfo, $type)
  354 + {
  355 + LoggerLog::debug("LoggerLocationPatternConverter::LoggerLocationPatternConverter() type='$type'");
  356 +
  357 + $this->LoggerPatternConverter($formattingInfo);
  358 + $this->type = $type;
  359 + }
  360 +
  361 + /**
  362 + * @param LoggerLoggingEvent $event
  363 + * @return string
  364 + */
  365 + function convert($event)
  366 + {
  367 + $locationInfo = $event->getLocationInformation();
  368 + switch($this->type) {
  369 + case LOG4PHP_LOGGER_PATTERN_PARSER_FULL_LOCATION_CONVERTER:
  370 + return $locationInfo->fullInfo;
  371 + case LOG4PHP_LOGGER_PATTERN_PARSER_METHOD_LOCATION_CONVERTER:
  372 + return $locationInfo->getMethodName();
  373 + case LOG4PHP_LOGGER_PATTERN_PARSER_LINE_LOCATION_CONVERTER:
  374 + return $locationInfo->getLineNumber();
  375 + case LOG4PHP_LOGGER_PATTERN_PARSER_FILE_LOCATION_CONVERTER:
  376 + return $locationInfo->getFileName();
  377 + default:
  378 + return '';
  379 + }
  380 + }
  381 +}
  382 +
  383 +/**
  384 + * @author Marco Vassura
  385 + * @package log4php
  386 + * @subpackage helpers
  387 + * @abstract
  388 + */
  389 +class LoggerNamedPatternConverter extends LoggerPatternConverter {
  390 +
  391 + /**
  392 + * @var integer
  393 + */
  394 + var $precision;
  395 +
  396 + /**
  397 + * Constructor
  398 + *
  399 + * @param string $formattingInfo
  400 + * @param integer $precision
  401 + */
  402 + function LoggerNamedPatternConverter($formattingInfo, $precision)
  403 + {
  404 + LoggerLog::debug("LoggerNamedPatternConverter::LoggerNamedPatternConverter() precision='$precision'");
  405 +
  406 + $this->LoggerPatternConverter($formattingInfo);
  407 + $this->precision = $precision;
  408 + }
  409 +
  410 + /**
  411 + * @param LoggerLoggingEvent $event
  412 + * @return string
  413 + * @abstract
  414 + */
  415 + function getFullyQualifiedName($event)
  416 + {
  417 + // abstract
  418 + return;
  419 + }
  420 +
  421 + /**
  422 + * @param LoggerLoggingEvent $event
  423 + * @return string
  424 + */
  425 + function convert($event)
  426 + {
  427 + $n = $this->getFullyQualifiedName($event);
  428 + if ($this->precision <= 0) {
  429 + return $n;
  430 + } else {
  431 + $len = strlen($n);
  432 +
  433 + // We substract 1 from 'len' when assigning to 'end' to avoid out of
  434 + // bounds exception in return r.substring(end+1, len). This can happen if
  435 + // precision is 1 and the category name ends with a dot.
  436 + $end = $len -1 ;
  437 + for($i = $this->precision; $i > 0; $i--) {
  438 + $end = strrpos(substr($n, 0, ($end - 1)), '.');
  439 + if ($end == false)
  440 + return $n;
  441 + }
  442 + return substr($n, ($end + 1), $len);
  443 + }
  444 + }
  445 +}
  446 +
  447 +/**
  448 + * @author Marco Vassura
  449 + * @package log4php
  450 + * @subpackage helpers
  451 + */
  452 +class LoggerClassNamePatternConverter extends LoggerNamedPatternConverter {
  453 +
  454 + /**
  455 + * Constructor
  456 + *
  457 + * @param string $formattingInfo
  458 + * @param integer $precision
  459 + */
  460 + function LoggerClassNamePatternConverter($formattingInfo, $precision)
  461 + {
  462 + LoggerLog::debug("LoggerClassNamePatternConverter::LoggerClassNamePatternConverter() precision='$precision'");
  463 +
  464 + $this->LoggerNamedPatternConverter($formattingInfo, $precision);
  465 + }
  466 +
  467 + /**
  468 + * @param LoggerLoggingEvent $event
  469 + * @return string
  470 + */
  471 + function getFullyQualifiedName($event)
  472 + {
  473 + return $event->fqcn;
  474 + }
  475 +}
  476 +
  477 +/**
  478 + * @author Marco Vassura
  479 + * @package log4php
  480 + * @subpackage helpers
  481 + */
  482 +class LoggerCategoryPatternConverter extends LoggerNamedPatternConverter {
  483 +
  484 + /**
  485 + * Constructor
  486 + *
  487 + * @param string $formattingInfo
  488 + * @param integer $precision
  489 + */
  490 + function LoggerCategoryPatternConverter($formattingInfo, $precision)
  491 + {
  492 + LoggerLog::debug("LoggerCategoryPatternConverter::LoggerCategoryPatternConverter() precision='$precision'");
  493 +
  494 + $this->LoggerNamedPatternConverter($formattingInfo, $precision);
  495 + }
  496 +
  497 + /**
  498 + * @param LoggerLoggingEvent $event
  499 + * @return string
  500 + */
  501 + function getFullyQualifiedName($event)
  502 + {
  503 + return $event->getLoggerName();
  504 + }
  505 +}
  506 +
... ...
thirdparty/apache-log4php/src/main/php/helpers/LoggerPatternParser.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage helpers
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +if (!defined('LOG4PHP_LINE_SEP')) {
  29 + if (substr(php_uname(), 0, 7) == "Windows") {
  30 + /**
  31 + * @ignore
  32 + */
  33 + define('LOG4PHP_LINE_SEP', "\r\n");
  34 + } else {
  35 + /**
  36 + * @ignore
  37 + */
  38 + define('LOG4PHP_LINE_SEP', "\n");
  39 + }
  40 +}
  41 +
  42 +/**
  43 + */
  44 +require_once(LOG4PHP_DIR . '/helpers/LoggerFormattingInfo.php');
  45 +require_once(LOG4PHP_DIR . '/helpers/LoggerPatternConverter.php');
  46 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  47 +
  48 +define('LOG4PHP_LOGGER_PATTERN_PARSER_ESCAPE_CHAR', '%');
  49 +
  50 +define('LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE', 0);
  51 +define('LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE', 1);
  52 +define('LOG4PHP_LOGGER_PATTERN_PARSER_MINUS_STATE', 2);
  53 +define('LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE', 3);
  54 +define('LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE', 4);
  55 +define('LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE', 5);
  56 +
  57 +define('LOG4PHP_LOGGER_PATTERN_PARSER_FULL_LOCATION_CONVERTER', 1000);
  58 +define('LOG4PHP_LOGGER_PATTERN_PARSER_METHOD_LOCATION_CONVERTER', 1001);
  59 +define('LOG4PHP_LOGGER_PATTERN_PARSER_CLASS_LOCATION_CONVERTER', 1002);
  60 +define('LOG4PHP_LOGGER_PATTERN_PARSER_FILE_LOCATION_CONVERTER', 1003);
  61 +define('LOG4PHP_LOGGER_PATTERN_PARSER_LINE_LOCATION_CONVERTER', 1004);
  62 +
  63 +define('LOG4PHP_LOGGER_PATTERN_PARSER_RELATIVE_TIME_CONVERTER', 2000);
  64 +define('LOG4PHP_LOGGER_PATTERN_PARSER_THREAD_CONVERTER', 2001);
  65 +define('LOG4PHP_LOGGER_PATTERN_PARSER_LEVEL_CONVERTER', 2002);
  66 +define('LOG4PHP_LOGGER_PATTERN_PARSER_NDC_CONVERTER', 2003);
  67 +define('LOG4PHP_LOGGER_PATTERN_PARSER_MESSAGE_CONVERTER', 2004);
  68 +
  69 +define('LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601', 'Y-m-d H:i:s,u');
  70 +define('LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ABSOLUTE', 'H:i:s');
  71 +define('LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_DATE', 'd M Y H:i:s,u');
  72 +
  73 +/**
  74 + * Most of the work of the {@link LoggerPatternLayout} class
  75 + * is delegated to the {@link LoggerPatternParser} class.
  76 + *
  77 + * <p>It is this class that parses conversion patterns and creates
  78 + * a chained list of {@link LoggerPatternConverter} converters.</p>
  79 + *
  80 + * @author Marco Vassura
  81 + * @version $Revision: 635069 $
  82 + * @package log4php
  83 + * @subpackage helpers
  84 + *
  85 + * @since 0.3
  86 + */
  87 +class LoggerPatternParser {
  88 +
  89 + var $state;
  90 + var $currentLiteral;
  91 + var $patternLength;
  92 + var $i;
  93 +
  94 + /**
  95 + * @var LoggerPatternConverter
  96 + */
  97 + var $head = null;
  98 +
  99 + /**
  100 + * @var LoggerPatternConverter
  101 + */
  102 + var $tail = null;
  103 +
  104 + /**
  105 + * @var LoggerFormattingInfo
  106 + */
  107 + var $formattingInfo;
  108 +
  109 + /**
  110 + * @var string pattern to parse
  111 + */
  112 + var $pattern;
  113 +
  114 + /**
  115 + * Constructor
  116 + *
  117 + * @param string $pattern
  118 + */
  119 + function LoggerPatternParser($pattern)
  120 + {
  121 + LoggerLog::debug("LoggerPatternParser::LoggerPatternParser() pattern='$pattern'");
  122 +
  123 + $this->pattern = $pattern;
  124 + $this->patternLength = strlen($pattern);
  125 + $this->formattingInfo = new LoggerFormattingInfo();
  126 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE;
  127 + }
  128 +
  129 + /**
  130 + * @param LoggerPatternConverter $pc
  131 + */
  132 + function addToList($pc)
  133 + {
  134 + // LoggerLog::debug("LoggerPatternParser::addToList()");
  135 +
  136 + if($this->head == null) {
  137 + $this->head = $pc;
  138 + $this->tail =& $this->head;
  139 + } else {
  140 + $this->tail->next = $pc;
  141 + $this->tail =& $this->tail->next;
  142 + }
  143 + }
  144 +
  145 + /**
  146 + * @return string
  147 + */
  148 + function extractOption()
  149 + {
  150 + if(($this->i < $this->patternLength) and ($this->pattern{$this->i} == '{')) {
  151 + $end = strpos($this->pattern, '}' , $this->i);
  152 + if ($end !== false) {
  153 + $r = substr($this->pattern, ($this->i + 1), ($end - $this->i - 1));
  154 + $this->i= $end + 1;
  155 + return $r;
  156 + }
  157 + }
  158 + return null;
  159 + }
  160 +
  161 + /**
  162 + * The option is expected to be in decimal and positive. In case of
  163 + * error, zero is returned.
  164 + */
  165 + function extractPrecisionOption()
  166 + {
  167 + $opt = $this->extractOption();
  168 + $r = 0;
  169 + if ($opt !== null) {
  170 + if (is_numeric($opt)) {
  171 + $r = (int)$opt;
  172 + if($r <= 0) {
  173 + LoggerLog::warn("Precision option ({$opt}) isn't a positive integer.");
  174 + $r = 0;
  175 + }
  176 + } else {
  177 + LoggerLog::warn("Category option \"{$opt}\" not a decimal integer.");
  178 + }
  179 + }
  180 + return $r;
  181 + }
  182 +
  183 + function parse()
  184 + {
  185 + LoggerLog::debug("LoggerPatternParser::parse()");
  186 +
  187 + $c = '';
  188 + $this->i = 0;
  189 + $this->currentLiteral = '';
  190 + while ($this->i < $this->patternLength) {
  191 + $c = $this->pattern{$this->i++};
  192 +// LoggerLog::debug("LoggerPatternParser::parse() char is now '$c' and currentLiteral is '{$this->currentLiteral}'");
  193 + switch($this->state) {
  194 + case LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE:
  195 + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE'");
  196 + // In literal state, the last char is always a literal.
  197 + if($this->i == $this->patternLength) {
  198 + $this->currentLiteral .= $c;
  199 + continue;
  200 + }
  201 + if($c == LOG4PHP_LOGGER_PATTERN_PARSER_ESCAPE_CHAR) {
  202 + // LoggerLog::debug("LoggerPatternParser::parse() char is an escape char");
  203 + // peek at the next char.
  204 + switch($this->pattern{$this->i}) {
  205 + case LOG4PHP_LOGGER_PATTERN_PARSER_ESCAPE_CHAR:
  206 + // LoggerLog::debug("LoggerPatternParser::parse() next char is an escape char");
  207 + $this->currentLiteral .= $c;
  208 + $this->i++; // move pointer
  209 + break;
  210 + case 'n':
  211 + // LoggerLog::debug("LoggerPatternParser::parse() next char is 'n'");
  212 + $this->currentLiteral .= LOG4PHP_LINE_SEP;
  213 + $this->i++; // move pointer
  214 + break;
  215 + default:
  216 + if(strlen($this->currentLiteral) != 0) {
  217 + $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral));
  218 + LoggerLog::debug("LoggerPatternParser::parse() Parsed LITERAL converter: \"{$this->currentLiteral}\".");
  219 + }
  220 + $this->currentLiteral = $c;
  221 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE;
  222 + $this->formattingInfo->reset();
  223 + }
  224 + } else {
  225 + $this->currentLiteral .= $c;
  226 + }
  227 + break;
  228 + case LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE:
  229 + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE'");
  230 + $this->currentLiteral .= $c;
  231 + switch($c) {
  232 + case '-':
  233 + $this->formattingInfo->leftAlign = true;
  234 + break;
  235 + case '.':
  236 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE;
  237 + break;
  238 + default:
  239 + if(ord($c) >= ord('0') and ord($c) <= ord('9')) {
  240 + $this->formattingInfo->min = ord($c) - ord('0');
  241 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE;
  242 + } else {
  243 + $this->finalizeConverter($c);
  244 + }
  245 + } // switch
  246 + break;
  247 + case LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE:
  248 + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE'");
  249 + $this->currentLiteral .= $c;
  250 + if(ord($c) >= ord('0') and ord($c) <= ord('9')) {
  251 + $this->formattingInfo->min = ($this->formattingInfo->min * 10) + (ord($c) - ord('0'));
  252 + } elseif ($c == '.') {
  253 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE;
  254 + } else {
  255 + $this->finalizeConverter($c);
  256 + }
  257 + break;
  258 + case LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE:
  259 + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE'");
  260 + $this->currentLiteral .= $c;
  261 + if(ord($c) >= ord('0') and ord($c) <= ord('9')) {
  262 + $this->formattingInfo->max = ord($c) - ord('0');
  263 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE;
  264 + } else {
  265 + LoggerLog::warn("LoggerPatternParser::parse() Error occured in position {$this->i}. Was expecting digit, instead got char \"{$c}\".");
  266 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE;
  267 + }
  268 + break;
  269 + case LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE:
  270 + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE'");
  271 + $this->currentLiteral .= $c;
  272 + if(ord($c) >= ord('0') and ord($c) <= ord('9')) {
  273 + $this->formattingInfo->max = ($this->formattingInfo->max * 10) + (ord($c) - ord('0'));
  274 + } else {
  275 + $this->finalizeConverter($c);
  276 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE;
  277 + }
  278 + break;
  279 + } // switch
  280 + } // while
  281 + if(strlen($this->currentLiteral) != 0) {
  282 + $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral));
  283 + // LoggerLog::debug("LoggerPatternParser::parse() Parsed LITERAL converter: \"{$this->currentLiteral}\".");
  284 + }
  285 + return $this->head;
  286 + }
  287 +
  288 + function finalizeConverter($c)
  289 + {
  290 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() with char '$c'");
  291 +
  292 + $pc = null;
  293 + switch($c) {
  294 + case 'c':
  295 + $pc = new LoggerCategoryPatternConverter($this->formattingInfo, $this->extractPrecisionOption());
  296 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() CATEGORY converter.");
  297 + $this->currentLiteral = '';
  298 + break;
  299 + case 'C':
  300 + $pc = new LoggerClassNamePatternConverter($this->formattingInfo, $this->extractPrecisionOption());
  301 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() CLASSNAME converter.");
  302 + $this->currentLiteral = '';
  303 + break;
  304 + case 'd':
  305 + $dateFormatStr = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT;
  306 + $dOpt = $this->extractOption();
  307 +
  308 + if($dOpt !== null)
  309 + $dateFormatStr = $dOpt;
  310 +
  311 + if ($dateFormatStr == 'ISO8601') {
  312 + $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601;
  313 + } elseif($dateFormatStr == 'ABSOLUTE') {
  314 + $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ABSOLUTE;
  315 + } elseif($dateFormatStr == 'DATE') {
  316 + $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_DATE;
  317 + } else {
  318 + $df = $dateFormatStr;
  319 + if ($df == null) {
  320 + $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601;
  321 + }
  322 + }
  323 + $pc = new LoggerDatePatternConverter($this->formattingInfo, $df);
  324 + $this->currentLiteral = '';
  325 + break;
  326 + case 'F':
  327 + $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_FILE_LOCATION_CONVERTER);
  328 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() File name converter.");
  329 + $this->currentLiteral = '';
  330 + break;
  331 + case 'l':
  332 + $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_FULL_LOCATION_CONVERTER);
  333 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() Location converter.");
  334 + $this->currentLiteral = '';
  335 + break;
  336 + case 'L':
  337 + $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_LINE_LOCATION_CONVERTER);
  338 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() LINE NUMBER converter.");
  339 + $this->currentLiteral = '';
  340 + break;
  341 + case 'm':
  342 + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_MESSAGE_CONVERTER);
  343 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() MESSAGE converter.");
  344 + $this->currentLiteral = '';
  345 + break;
  346 + case 'M':
  347 + $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_METHOD_LOCATION_CONVERTER);
  348 + $this->currentLiteral = '';
  349 + break;
  350 + case 'p':
  351 + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_LEVEL_CONVERTER);
  352 + $this->currentLiteral = '';
  353 + break;
  354 + case 'r':
  355 + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_RELATIVE_TIME_CONVERTER);
  356 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() RELATIVE TIME converter.");
  357 + $this->currentLiteral = '';
  358 + break;
  359 + case 't':
  360 + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_THREAD_CONVERTER);
  361 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() THREAD converter.");
  362 + $this->currentLiteral = '';
  363 + break;
  364 + case 'u':
  365 + if($this->i < $this->patternLength) {
  366 + $cNext = $this->pattern{$this->i};
  367 + if(ord($cNext) >= ord('0') and ord($cNext) <= ord('9')) {
  368 + $pc = new LoggerUserFieldPatternConverter($this->formattingInfo, (string)(ord($cNext) - ord('0')));
  369 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() USER converter [{$cNext}].");
  370 + $this->currentLiteral = '';
  371 + $this->i++;
  372 + } else {
  373 + LoggerLog::warn("LoggerPatternParser::finalizeConverter() Unexpected char '{$cNext}' at position {$this->i}.");
  374 + }
  375 + }
  376 + break;
  377 + case 'x':
  378 + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_NDC_CONVERTER);
  379 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() NDC converter.");
  380 + $this->currentLiteral = '';
  381 + break;
  382 +
  383 + case 'X':
  384 + $xOpt = $this->extractOption();
  385 + $pc = new LoggerMDCPatternConverter($this->formattingInfo, $xOpt);
  386 + LoggerLog::debug("LoggerPatternParser::finalizeConverter() MDC converter.");
  387 + $this->currentLiteral = '';
  388 + break;
  389 + default:
  390 + LoggerLog::warn("LoggerPatternParser::finalizeConverter() Unexpected char [$c] at position {$this->i} in conversion pattern.");
  391 + $pc = new LoggerLiteralPatternConverter($this->currentLiteral);
  392 + $this->currentLiteral = '';
  393 + }
  394 + $this->addConverter($pc);
  395 + }
  396 +
  397 + function addConverter($pc)
  398 + {
  399 + $this->currentLiteral = '';
  400 + // Add the pattern converter to the list.
  401 + $this->addToList($pc);
  402 + // Next pattern is assumed to be a literal.
  403 + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE;
  404 + // Reset formatting info
  405 + $this->formattingInfo->reset();
  406 + }
  407 +}
  408 +
... ...
thirdparty/apache-log4php/src/main/php/helpers/LoggerTransform.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage helpers
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_START', '<![CDATA[');
  29 +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_END', ']]>');
  30 +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END', ']]&gt;');
  31 +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END',
  32 + LOG4PHP_LOGGER_TRANSFORM_CDATA_END .
  33 + LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END .
  34 + LOG4PHP_LOGGER_TRANSFORM_CDATA_START
  35 +);
  36 +
  37 +/**
  38 + * Utility class for transforming strings.
  39 + *
  40 + * @author Marco Vassura
  41 + * @package log4php
  42 + * @subpackage helpers
  43 + * @since 0.7
  44 + */
  45 +class LoggerTransform {
  46 +
  47 + /**
  48 + * This method takes a string which may contain HTML tags (ie,
  49 + * &lt;b&gt;, &lt;table&gt;, etc) and replaces any '&lt;' and '&gt;'
  50 + * characters with respective predefined entity references.
  51 + *
  52 + * @param string $input The text to be converted.
  53 + * @return string The input string with the characters '&lt;' and '&gt;' replaced with
  54 + * &amp;lt; and &amp;gt; respectively.
  55 + * @static
  56 + */
  57 + function escapeTags($input)
  58 + {
  59 + //Check if the string is null or zero length -- if so, return
  60 + //what was sent in.
  61 +
  62 + if(empty($input))
  63 + return $input;
  64 +
  65 + //Use a StringBuffer in lieu of String concatenation -- it is
  66 + //much more efficient this way.
  67 +
  68 + return htmlspecialchars($input, ENT_NOQUOTES);
  69 + }
  70 +
  71 + /**
  72 + * Ensures that embeded CDEnd strings (]]&gt;) are handled properly
  73 + * within message, NDC and throwable tag text.
  74 + *
  75 + * @param string $buf String holding the XML data to this point. The
  76 + * initial CDStart (<![CDATA[) and final CDEnd (]]>)
  77 + * of the CDATA section are the responsibility of
  78 + * the calling method.
  79 + * @param string &str The String that is inserted into an existing
  80 + * CDATA Section within buf.
  81 + * @static
  82 + */
  83 + function appendEscapingCDATA(&$buf, $str)
  84 + {
  85 + if(empty($str))
  86 + return;
  87 +
  88 + $rStr = str_replace(
  89 + LOG4PHP_LOGGER_TRANSFORM_CDATA_END,
  90 + LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END,
  91 + $str
  92 + );
  93 + $buf .= $rStr;
  94 + }
  95 +}
... ...
thirdparty/apache-log4php/src/main/php/layouts/LoggerLayoutHtml.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage layouts
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +if (!defined('LOG4PHP_LINE_SEP')) {
  29 + if (substr(php_uname(), 0, 7) == "Windows") {
  30 + /**
  31 + * @ignore
  32 + */
  33 + define('LOG4PHP_LINE_SEP', "\r\n");
  34 + } else {
  35 + /**
  36 + * @ignore
  37 + */
  38 + define('LOG4PHP_LINE_SEP', "\n");
  39 + }
  40 +}
  41 +
  42 +/**
  43 + */
  44 +require_once(LOG4PHP_DIR . '/LoggerLayout.php');
  45 +require_once(LOG4PHP_DIR . '/spi/LoggerLoggingEvent.php');
  46 +
  47 +/**
  48 + * This layout outputs events in a HTML table.
  49 + *
  50 + * Parameters are: {@link $title}, {@link $locationInfo}.
  51 + *
  52 + * @author Marco Vassura
  53 + * @version $Revision: 635069 $
  54 + * @package log4php
  55 + * @subpackage layouts
  56 + */
  57 +class LoggerLayoutHtml extends LoggerLayout {
  58 +
  59 + /**
  60 + * The <b>LocationInfo</b> option takes a boolean value. By
  61 + * default, it is set to false which means there will be no location
  62 + * information output by this layout. If the the option is set to
  63 + * true, then the file name and line number of the statement
  64 + * at the origin of the log statement will be output.
  65 + *
  66 + * <p>If you are embedding this layout within a {@link LoggerAppenderMail}
  67 + * or a {@link LoggerAppenderMailEvent} then make sure to set the
  68 + * <b>LocationInfo</b> option of that appender as well.
  69 + * @var boolean
  70 + */
  71 + var $locationInfo = false;
  72 +
  73 + /**
  74 + * The <b>Title</b> option takes a String value. This option sets the
  75 + * document title of the generated HTML document.
  76 + * Defaults to 'Log4php Log Messages'.
  77 + * @var string
  78 + */
  79 + var $title = "Log4php Log Messages";
  80 +
  81 + /**
  82 + * Constructor
  83 + */
  84 + function LoggerLayoutHtml()
  85 + {
  86 + return;
  87 + }
  88 +
  89 + /**
  90 + * The <b>LocationInfo</b> option takes a boolean value. By
  91 + * default, it is set to false which means there will be no location
  92 + * information output by this layout. If the the option is set to
  93 + * true, then the file name and line number of the statement
  94 + * at the origin of the log statement will be output.
  95 + *
  96 + * <p>If you are embedding this layout within a {@link LoggerAppenderMail}
  97 + * or a {@link LoggerAppenderMailEvent} then make sure to set the
  98 + * <b>LocationInfo</b> option of that appender as well.
  99 + */
  100 + function setLocationInfo($flag)
  101 + {
  102 + if (is_bool($flag)) {
  103 + $this->locationInfo = $flag;
  104 + } else {
  105 + $this->locationInfo = (bool)(strtolower($flag) == 'true');
  106 + }
  107 + }
  108 +
  109 + /**
  110 + * Returns the current value of the <b>LocationInfo</b> option.
  111 + */
  112 + function getLocationInfo()
  113 + {
  114 + return $this->locationInfo;
  115 + }
  116 +
  117 + /**
  118 + * The <b>Title</b> option takes a String value. This option sets the
  119 + * document title of the generated HTML document.
  120 + * Defaults to 'Log4php Log Messages'.
  121 + */
  122 + function setTitle($title)
  123 + {
  124 + $this->title = $title;
  125 + }
  126 +
  127 + /**
  128 + * @return string Returns the current value of the <b>Title</b> option.
  129 + */
  130 + function getTitle()
  131 + {
  132 + return $this->title;
  133 + }
  134 +
  135 + /**
  136 + * @return string Returns the content type output by this layout, i.e "text/html".
  137 + */
  138 + function getContentType()
  139 + {
  140 + return "text/html";
  141 + }
  142 +
  143 + /**
  144 + * No options to activate.
  145 + */
  146 + function activateOptions()
  147 + {
  148 + return true;
  149 + }
  150 +
  151 + /**
  152 + * @param LoggerLoggingEvent $event
  153 + * @return string
  154 + */
  155 + function format($event)
  156 + {
  157 + $sbuf = LOG4PHP_LINE_SEP . "<tr>" . LOG4PHP_LINE_SEP;
  158 +
  159 + $sbuf .= "<td>";
  160 +
  161 + $eventTime = (float)$event->getTimeStamp();
  162 + $eventStartTime = (float)LoggerLoggingEvent::getStartTime();
  163 + $sbuf .= number_format(($eventTime - $eventStartTime) * 1000, 0, '', '');
  164 + $sbuf .= "</td>" . LOG4PHP_LINE_SEP;
  165 +
  166 + $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">";
  167 + $sbuf .= $event->getThreadName();
  168 + $sbuf .= "</td>" . LOG4PHP_LINE_SEP;
  169 +
  170 + $sbuf .= "<td title=\"Level\">";
  171 +
  172 + $level = $event->getLevel();
  173 +
  174 + if ($level->equals(LoggerLevel::getLevelDebug())) {
  175 + $sbuf .= "<font color=\"#339933\">";
  176 + $sbuf .= $level->toString();
  177 + $sbuf .= "</font>";
  178 + }elseif($level->equals(LoggerLevel::getLevelWarn())) {
  179 + $sbuf .= "<font color=\"#993300\"><strong>";
  180 + $sbuf .= $level->toString();
  181 + $sbuf .= "</strong></font>";
  182 + } else {
  183 + $sbuf .= $level->toString();
  184 + }
  185 + $sbuf .= "</td>" . LOG4PHP_LINE_SEP;
  186 +
  187 + $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">";
  188 + $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES);
  189 + $sbuf .= "</td>" . LOG4PHP_LINE_SEP;
  190 +
  191 + if ($this->locationInfo) {
  192 + $locInfo = $event->getLocationInformation();
  193 + $sbuf .= "<td>";
  194 + $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES). ':' . $locInfo->getLineNumber();
  195 + $sbuf .= "</td>" . LOG4PHP_LINE_SEP;
  196 + }
  197 +
  198 + $sbuf .= "<td title=\"Message\">";
  199 + $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES);
  200 + $sbuf .= "</td>" . LOG4PHP_LINE_SEP;
  201 +
  202 + $sbuf .= "</tr>" . LOG4PHP_LINE_SEP;
  203 +
  204 + if ($event->getNDC() != null) {
  205 + $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">";
  206 + $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES);
  207 + $sbuf .= "</td></tr>" . LOG4PHP_LINE_SEP;
  208 + }
  209 +
  210 + return $sbuf;
  211 + }
  212 +
  213 + /**
  214 + * @return string Returns appropriate HTML headers.
  215 + */
  216 + function getHeader()
  217 + {
  218 + $sbuf = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" . LOG4PHP_LINE_SEP;
  219 + $sbuf .= "<html>" . LOG4PHP_LINE_SEP;
  220 + $sbuf .= "<head>" . LOG4PHP_LINE_SEP;
  221 + $sbuf .= "<title>" . $this->title . "</title>" . LOG4PHP_LINE_SEP;
  222 + $sbuf .= "<style type=\"text/css\">" . LOG4PHP_LINE_SEP;
  223 + $sbuf .= "<!--" . LOG4PHP_LINE_SEP;
  224 + $sbuf .= "body, table {font-family: arial,sans-serif; font-size: x-small;}" . LOG4PHP_LINE_SEP;
  225 + $sbuf .= "th {background: #336699; color: #FFFFFF; text-align: left;}" . LOG4PHP_LINE_SEP;
  226 + $sbuf .= "-->" . LOG4PHP_LINE_SEP;
  227 + $sbuf .= "</style>" . LOG4PHP_LINE_SEP;
  228 + $sbuf .= "</head>" . LOG4PHP_LINE_SEP;
  229 + $sbuf .= "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">" . LOG4PHP_LINE_SEP;
  230 + $sbuf .= "<hr size=\"1\" noshade>" . LOG4PHP_LINE_SEP;
  231 + $sbuf .= "Log session start time " . strftime('%c', time()) . "<br>" . LOG4PHP_LINE_SEP;
  232 + $sbuf .= "<br>" . LOG4PHP_LINE_SEP;
  233 + $sbuf .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">" . LOG4PHP_LINE_SEP;
  234 + $sbuf .= "<tr>" . LOG4PHP_LINE_SEP;
  235 + $sbuf .= "<th>Time</th>" . LOG4PHP_LINE_SEP;
  236 + $sbuf .= "<th>Thread</th>" . LOG4PHP_LINE_SEP;
  237 + $sbuf .= "<th>Level</th>" . LOG4PHP_LINE_SEP;
  238 + $sbuf .= "<th>Category</th>" . LOG4PHP_LINE_SEP;
  239 + if ($this->locationInfo)
  240 + $sbuf .= "<th>File:Line</th>" . LOG4PHP_LINE_SEP;
  241 + $sbuf .= "<th>Message</th>" . LOG4PHP_LINE_SEP;
  242 + $sbuf .= "</tr>" . LOG4PHP_LINE_SEP;
  243 +
  244 + return $sbuf;
  245 + }
  246 +
  247 + /**
  248 + * @return string Returns the appropriate HTML footers.
  249 + */
  250 + function getFooter()
  251 + {
  252 + $sbuf = "</table>" . LOG4PHP_LINE_SEP;
  253 + $sbuf .= "<br>" . LOG4PHP_LINE_SEP;
  254 + $sbuf .= "</body></html>";
  255 +
  256 + return $sbuf;
  257 + }
  258 +}
... ...
thirdparty/apache-log4php/src/main/php/layouts/LoggerLayoutSimple.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage layouts
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +if (!defined('LOG4PHP_LINE_SEP')) {
  29 + if (substr(php_uname(), 0, 7) == "Windows") {
  30 + define('LOG4PHP_LINE_SEP', "\r\n");
  31 + } else {
  32 + /**
  33 + * @ignore
  34 + */
  35 + define('LOG4PHP_LINE_SEP', "\n");
  36 + }
  37 +}
  38 +
  39 +
  40 +/**
  41 + */
  42 +require_once(LOG4PHP_DIR . '/LoggerLayout.php');
  43 +
  44 +/**
  45 + * A simple layout.
  46 + *
  47 + * Returns the log statement in a format consisting of the
  48 + * <b>level</b>, followed by " - " and then the <b>message</b>.
  49 + * For example,
  50 + * <samp> INFO - "A message" </samp>
  51 + *
  52 + * @author Marco Vassura
  53 + * @version $Revision: 635069 $
  54 + * @package log4php
  55 + * @subpackage layouts
  56 + */
  57 +class LoggerLayoutSimple extends LoggerLayout {
  58 +
  59 + /**
  60 + * Constructor
  61 + */
  62 + function LoggerLayoutSimple()
  63 + {
  64 + return;
  65 + }
  66 +
  67 + function activateOptions()
  68 + {
  69 + return;
  70 + }
  71 +
  72 + /**
  73 + * Returns the log statement in a format consisting of the
  74 + * <b>level</b>, followed by " - " and then the
  75 + * <b>message</b>. For example,
  76 + * <samp> INFO - "A message" </samp>
  77 + *
  78 + * @param LoggerLoggingEvent $event
  79 + * @return string
  80 + */
  81 + function format($event)
  82 + {
  83 + $level = $event->getLevel();
  84 + return $level->toString() . ' - ' . $event->getRenderedMessage(). LOG4PHP_LINE_SEP;
  85 + }
  86 +}
... ...
thirdparty/apache-log4php/src/main/php/layouts/LoggerLayoutTTCC.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage layouts
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +if (!defined('LOG4PHP_LINE_SEP')) {
  29 + if (substr(php_uname(), 0, 7) == "Windows") {
  30 + /**
  31 + * @ignore
  32 + */
  33 + define('LOG4PHP_LINE_SEP', "\r\n");
  34 + } else {
  35 + /**
  36 + * @ignore
  37 + */
  38 + define('LOG4PHP_LINE_SEP', "\n");
  39 + }
  40 +}
  41 +
  42 +/**
  43 + */
  44 +require_once(LOG4PHP_DIR . '/LoggerLayout.php');
  45 +
  46 +/**
  47 + * String constant designating no time information. Current value of
  48 + * this constant is <b>NULL</b>.
  49 + */
  50 +define ('LOG4PHP_LOGGER_LAYOUT_NULL_DATE_FORMAT', 'NULL');
  51 +
  52 +/**
  53 + * String constant designating relative time. Current value of
  54 + * this constant is <b>RELATIVE</b>.
  55 + */
  56 +define ('LOG4PHP_LOGGER_LAYOUT_RELATIVE_TIME_DATE_FORMAT', 'RELATIVE');
  57 +
  58 +/**
  59 + * TTCC layout format consists of time, thread, category and nested
  60 + * diagnostic context information, hence the name.
  61 + *
  62 + * <p>Each of the four fields can be individually enabled or
  63 + * disabled. The time format depends on the <b>DateFormat</b> used.</p>
  64 + *
  65 + * <p>If no dateFormat is specified it defaults to '%c'.
  66 + * See php {@link PHP_MANUAL#date} function for details.</p>
  67 + *
  68 + * Params:
  69 + * - {@link $threadPrinting} (true|false) enable/disable pid reporting.
  70 + * - {@link $categoryPrefixing} (true|false) enable/disable logger category reporting.
  71 + * - {@link $contextPrinting} (true|false) enable/disable NDC reporting.
  72 + * - {@link $microSecondsPrinting} (true|false) enable/disable micro seconds reporting in timestamp.
  73 + * - {@link $dateFormat} (string) set date format. See php {@link PHP_MANUAL#date} function for details.
  74 + *
  75 + * @author Marco Vassura
  76 + * @version $Revision: 635069 $
  77 + * @package log4php
  78 + * @subpackage layouts
  79 + */
  80 +class LoggerLayoutTTCC extends LoggerLayout {
  81 +
  82 + // Internal representation of options
  83 + protected $threadPrinting = true;
  84 + protected $categoryPrefixing = true;
  85 + protected $contextPrinting = true;
  86 + protected $microSecondsPrinting = true;
  87 +
  88 + /**
  89 + * @var string date format. See {@link PHP_MANUAL#strftime} for details
  90 + */
  91 + protected $dateFormat = '%c';
  92 +
  93 + /**
  94 + * Constructor
  95 + *
  96 + * @param string date format
  97 + * @see dateFormat
  98 + */
  99 + public function __construct($dateFormat = '')
  100 + {
  101 + if (!empty($dateFormat))
  102 + $this->dateFormat = $dateFormat;
  103 + return;
  104 + }
  105 +
  106 + public function activateOptions() {
  107 + return;
  108 + }
  109 +
  110 + /**
  111 + * The <b>ThreadPrinting</b> option specifies whether the name of the
  112 + * current thread is part of log output or not. This is true by default.
  113 + */
  114 + public function setThreadPrinting($threadPrinting)
  115 + {
  116 +
  117 + $this->threadPrinting = is_bool($threadPrinting) ?
  118 + $threadPrinting :
  119 + (bool)(strtolower($threadPrinting) == 'true');
  120 + }
  121 +
  122 + /**
  123 + * @return boolean Returns value of the <b>ThreadPrinting</b> option.
  124 + */
  125 + public function getThreadPrinting() {
  126 + return $this->threadPrinting;
  127 + }
  128 +
  129 + /**
  130 + * The <b>CategoryPrefixing</b> option specifies whether {@link Category}
  131 + * name is part of log output or not. This is true by default.
  132 + */
  133 + public function setCategoryPrefixing($categoryPrefixing)
  134 + {
  135 + $this->categoryPrefixing = is_bool($categoryPrefixing) ?
  136 + $categoryPrefixing :
  137 + (bool)(strtolower($categoryPrefixing) == 'true');
  138 + }
  139 +
  140 + /**
  141 + * @return boolean Returns value of the <b>CategoryPrefixing</b> option.
  142 + */
  143 + public function getCategoryPrefixing() {
  144 + return $this->categoryPrefixing;
  145 + }
  146 +
  147 + /**
  148 + * The <b>ContextPrinting</b> option specifies log output will include
  149 + * the nested context information belonging to the current thread.
  150 + * This is true by default.
  151 + */
  152 + public function setContextPrinting($contextPrinting) {
  153 + $this->contextPrinting = is_bool($contextPrinting) ?
  154 + $contextPrinting :
  155 + (bool)(strtolower($contextPrinting) == 'true');
  156 + }
  157 +
  158 + /**
  159 + * @return boolean Returns value of the <b>ContextPrinting</b> option.
  160 + */
  161 + public function getContextPrinting()
  162 + {
  163 + return $this->contextPrinting;
  164 + }
  165 +
  166 + /**
  167 + * The <b>MicroSecondsPrinting</b> option specifies if microseconds infos
  168 + * should be printed at the end of timestamp.
  169 + * This is true by default.
  170 + */
  171 + public function setMicroSecondsPrinting($microSecondsPrinting) {
  172 + $this->microSecondsPrinting = is_bool($microSecondsPrinting) ?
  173 + $microSecondsPrinting :
  174 + (bool)(strtolower($microSecondsPrinting) == 'true');
  175 + }
  176 +
  177 + /**
  178 + * @return boolean Returns value of the <b>MicroSecondsPrinting</b> option.
  179 + */
  180 + public function getMicroSecondsPrinting()
  181 + {
  182 + return $this->microSecondsPrinting;
  183 + }
  184 +
  185 +
  186 + public function setDateFormat($dateFormat)
  187 + {
  188 + $this->dateFormat = $dateFormat;
  189 + }
  190 +
  191 + /**
  192 + * @return string
  193 + */
  194 + public function getDateFormat()
  195 + {
  196 + return $this->dateFormat;
  197 + }
  198 +
  199 + /**
  200 + * In addition to the level of the statement and message, the
  201 + * returned string includes time, thread, category.
  202 + * <p>Time, thread, category are printed depending on options.
  203 + *
  204 + * @param LoggerLoggingEvent $event
  205 + * @return string
  206 + */
  207 + public function format($event)
  208 + {
  209 + $timeStamp = (float)$event->getTimeStamp();
  210 + $format = strftime($this->dateFormat, (int)$timeStamp);
  211 +
  212 + if ($this->microSecondsPrinting) {
  213 + $usecs = floor(($timeStamp - (int)$timeStamp) * 1000);
  214 + $format .= sprintf(',%03d', $usecs);
  215 + }
  216 +
  217 + $format .= ' ';
  218 +
  219 + if ($this->threadPrinting)
  220 + $format .= '['.getmypid().'] ';
  221 +
  222 + $level = $event->getLevel();
  223 + $format .= $level->toString().' ';
  224 +
  225 + if($this->categoryPrefixing) {
  226 + $format .= $event->getLoggerName().' ';
  227 + }
  228 +
  229 + if($this->contextPrinting) {
  230 + $ndc = $event->getNDC();
  231 + if($ndc != null) {
  232 + $format .= $ndc.' ';
  233 + }
  234 + }
  235 +
  236 + $format .= '- '.$event->getRenderedMessage();
  237 + $format .= LOG4PHP_LINE_SEP;
  238 +
  239 + return $format;
  240 + }
  241 +
  242 + public function ignoresThrowable()
  243 + {
  244 + return true;
  245 + }
  246 +}
... ...
thirdparty/apache-log4php/src/main/php/layouts/LoggerPatternLayout.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage layouts
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/helpers/LoggerPatternParser.php');
  31 +require_once(LOG4PHP_DIR . '/LoggerLayout.php');
  32 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  33 +
  34 +/**
  35 + * Default conversion Pattern
  36 + */
  37 +define('LOG4PHP_LOGGER_PATTERN_LAYOUT_DEFAULT_CONVERSION_PATTERN', '%m%n');
  38 +
  39 +define('LOG4PHP_LOGGER_PATTERN_LAYOUT_TTCC_CONVERSION_PATTERN', '%r [%t] %p %c %x - %m%n');
  40 +
  41 +/**
  42 + * A flexible layout configurable with pattern string.
  43 + *
  44 + * <p>The goal of this class is to {@link format()} a {@link LoggerLoggingEvent} and return the results as a string.
  45 + * The results depend on the conversion pattern.
  46 + * The conversion pattern is closely related to the conversion pattern of the printf function in C.
  47 + * A conversion pattern is composed of literal text and format control expressions called conversion specifiers.
  48 + * You are free to insert any literal text within the conversion pattern.</p>
  49 + *
  50 + * <p>Each conversion specifier starts with a percent sign (%) and is followed by optional
  51 + * format modifiers and a conversion character.</p>
  52 + *
  53 + * <p>The conversion character specifies the type of data, e.g. category, priority, date, thread name.
  54 + * The format modifiers control such things as field width, padding, left and right justification.</p>
  55 + *
  56 + * The following is a simple example.
  57 + *
  58 + * <p>Let the conversion pattern be "%-5p [%t]: %m%n" and assume that the log4php environment
  59 + * was set to use a LoggerPatternLayout.</p>
  60 + *
  61 + * Then the statements
  62 + * <code>
  63 + * $root =& LoggerManager::getRoot();
  64 + * $root->debug("Message 1");
  65 + * $root->warn("Message 2");
  66 + * </code>
  67 + * would yield the output
  68 + * <pre>
  69 + * DEBUG [main]: Message 1
  70 + * WARN [main]: Message 2
  71 + * </pre>
  72 + *
  73 + * <p>Note that there is no explicit separator between text and conversion specifiers.</p>
  74 + *
  75 + * <p>The pattern parser knows when it has reached the end of a conversion specifier when it reads a conversion character.
  76 + * In the example above the conversion specifier %-5p means the priority of the logging event should be
  77 + * left justified to a width of five characters.</p>
  78 + *
  79 + * Not all log4j conversion characters are implemented. The recognized conversion characters are:
  80 + * - <b>c</b> Used to output the category of the logging event. The category conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets.
  81 + * If a precision specifier is given, then only the corresponding number of right most components of the category name will be printed.
  82 + * By default the category name is printed in full.
  83 + * For example, for the category name "a.b.c" the pattern %c{2} will output "b.c".
  84 + * - <b>C</b> Used to output the fully qualified class name of the caller issuing the logging request.
  85 + * This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets.
  86 + * If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed.
  87 + * By default the class name is output in fully qualified form.
  88 + * For example, for the class name "org.apache.xyz.SomeClass", the pattern %C{1} will output "SomeClass".
  89 + * - <b>d</b> Used to output the date of the logging event.
  90 + * The date conversion specifier may be followed by a date format specifier enclosed between braces.
  91 + * The format specifier follows the {@link PHP_MANUAL#date} function.
  92 + * Note that the special character <b>u</b> is used to as microseconds replacement (to avoid replacement,
  93 + * use <b>\u</b>).
  94 + * For example, %d{H:i:s,u} or %d{d M Y H:i:s,u}. If no date format specifier is given then ISO8601 format is assumed.
  95 + * The date format specifier admits the same syntax as the time pattern string of the SimpleDateFormat.
  96 + * It is recommended to use the predefined log4php date formatters.
  97 + * These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying
  98 + * AbsoluteTimeDateFormat, DateTimeDateFormat and respectively ISO8601DateFormat.
  99 + * For example, %d{ISO8601} or %d{ABSOLUTE}.
  100 + * - <b>F</b> Used to output the file name where the logging request was issued.
  101 + * - <b>l</b> Used to output location information of the caller which generated the logging event.
  102 + * - <b>L</b> Used to output the line number from where the logging request was issued.
  103 + * - <b>m</b> Used to output the application supplied message associated with the logging event.
  104 + * - <b>M</b> Used to output the method name where the logging request was issued.
  105 + * - <b>p</b> Used to output the priority of the logging event.
  106 + * - <b>r</b> Used to output the number of milliseconds elapsed since the start of
  107 + * the application until the creation of the logging event.
  108 + * - <b>t</b> Used to output the name of the thread that generated the logging event.
  109 + * - <b>x</b> Used to output the NDC (nested diagnostic context) associated with
  110 + * the thread that generated the logging event.
  111 + * - <b>X</b> Used to output the MDC (mapped diagnostic context) associated with
  112 + * the thread that generated the logging event.
  113 + * The X conversion character must be followed by the key for the map placed between braces,
  114 + * as in <i>%X{clientNumber}</i> where clientNumber is the key.
  115 + * The value in the MDC corresponding to the key will be output.
  116 + * See {@link LoggerMDC} class for more details.
  117 + * - <b>%</b> The sequence %% outputs a single percent sign.
  118 + *
  119 + * <p>By default the relevant information is output as is.
  120 + * However, with the aid of format modifiers it is possible to change the minimum field width,
  121 + * the maximum field width and justification.</p>
  122 + *
  123 + * <p>The optional format modifier is placed between the percent sign and the conversion character.</p>
  124 + * <p>The first optional format modifier is the left justification flag which is just the minus (-) character.
  125 + * Then comes the optional minimum field width modifier.
  126 + * This is a decimal constant that represents the minimum number of characters to output.
  127 + * If the data item requires fewer characters, it is padded on either the left or the right until the minimum width is reached. The default is to pad on the left (right justify) but you can specify right padding with the left justification flag. The padding character is space. If the data item is larger than the minimum field width, the field is expanded to accommodate the data.
  128 + * The value is never truncated.</p>
  129 + *
  130 + * <p>This behavior can be changed using the maximum field width modifier which is designated by a period
  131 + * followed by a decimal constant.
  132 + * If the data item is longer than the maximum field,
  133 + * then the extra characters are removed from the beginning of the data item and not from the end.
  134 + * For example, it the maximum field width is eight and the data item is ten characters long,
  135 + * then the first two characters of the data item are dropped.
  136 + * This behavior deviates from the printf function in C where truncation is done from the end.</p>
  137 + *
  138 + * <p>Below are various format modifier examples for the category conversion specifier.</p>
  139 + * <pre>
  140 + * Format modifier left justify minimum width maximum width comment
  141 + * %20c false 20 none Left pad with spaces if the category name
  142 + * is less than 20 characters long.
  143 + * %-20c true 20 none Right pad with spaces if the category name
  144 + * is less than 20 characters long.
  145 + * %.30c NA none 30 Truncate from the beginning if the category name
  146 + * is longer than 30 characters.
  147 + * %20.30c false 20 30 Left pad with spaces if the category name
  148 + * is shorter than 20 characters.
  149 + * However, if category name is longer than 30 chars,
  150 + * then truncate from the beginning.
  151 + * %-20.30c true 20 30 Right pad with spaces if the category name is
  152 + * shorter than 20 chars.
  153 + * However, if category name is longer than 30 chars,
  154 + * then truncate from the beginning.
  155 + * </pre>
  156 + *
  157 + * @author Marco Vassura
  158 + * @version $Revision: 635069 $
  159 + * @package log4php
  160 + * @subpackage layouts
  161 + * @since 0.3
  162 + */
  163 +class LoggerPatternLayout extends LoggerLayout {
  164 +
  165 + /**
  166 + * @var string output buffer appended to when format() is invoked
  167 + */
  168 + var $sbuf;
  169 +
  170 + /**
  171 + * @var string
  172 + */
  173 + var $pattern;
  174 +
  175 + /**
  176 + * @var LoggerPatternConverter head chain
  177 + */
  178 + var $head;
  179 +
  180 + var $timezone;
  181 +
  182 + /**
  183 + * Constructs a PatternLayout using the
  184 + * {@link LOG4PHP_LOGGER_PATTERN_LAYOUT_DEFAULT_LAYOUT_PATTERN}.
  185 + * The default pattern just produces the application supplied message.
  186 + */
  187 + function LoggerPatternLayout($pattern = null)
  188 + {
  189 + if ($pattern === null) {
  190 + $this->LoggerPatternLayout(LOG4PHP_LOGGER_PATTERN_LAYOUT_DEFAULT_CONVERSION_PATTERN);
  191 + } else {
  192 + $this->pattern = $pattern;
  193 + }
  194 + }
  195 +
  196 + /**
  197 + * Set the <b>ConversionPattern</b> option. This is the string which
  198 + * controls formatting and consists of a mix of literal content and
  199 + * conversion specifiers.
  200 + */
  201 + function setConversionPattern($conversionPattern)
  202 + {
  203 + $this->pattern = $conversionPattern;
  204 + $patternParser = $this->createPatternParser($this->pattern);
  205 + $this->head = $patternParser->parse();
  206 + }
  207 +
  208 + /**
  209 + * @return string Returns the value of the <b>ConversionPattern</b> option.
  210 + */
  211 + function getConversionPattern()
  212 + {
  213 + return $this->pattern;
  214 + }
  215 +
  216 + /**
  217 + * Does not do anything as options become effective
  218 + */
  219 + function activateOptions()
  220 + {
  221 + // nothing to do.
  222 + }
  223 +
  224 + function ignoresThrowable()
  225 + {
  226 + return true;
  227 + }
  228 +
  229 + /**
  230 + * Returns LoggerPatternParser used to parse the conversion string. Subclasses
  231 + * may override this to return a subclass of PatternParser which recognize
  232 + * custom conversion characters.
  233 + *
  234 + * @param string $pattern
  235 + * @return LoggerPatternParser
  236 + */
  237 + function createPatternParser($pattern)
  238 + {
  239 + return new LoggerPatternParser($pattern);
  240 + }
  241 +
  242 + /**
  243 + * Produces a formatted string as specified by the conversion pattern.
  244 + *
  245 + * @param LoggerLoggingEvent $event
  246 + * @return string
  247 + */
  248 + function format($event)
  249 + {
  250 + LoggerLog::debug("LoggerPatternLayout::format()");
  251 +
  252 + // Reset working stringbuffer
  253 + $this->sbuf = '';
  254 + $c = $this->head;
  255 + while($c !== null) {
  256 + $c->format($this->sbuf, $event);
  257 + $c = $c->next;
  258 + }
  259 + return $this->sbuf;
  260 + }
  261 +
  262 +}
... ...
thirdparty/apache-log4php/src/main/php/layouts/LoggerXmlLayout.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage layouts
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +define('LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS_PREFIX', 'log4j');
  29 +define('LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS', 'http://jakarta.apache.org/log4j/');
  30 +
  31 +define('LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX', 'log4php');
  32 +define('LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS', 'http://logging.apache.org/log4php/');
  33 +
  34 +/**
  35 + */
  36 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  37 +require_once(LOG4PHP_DIR . '/helpers/LoggerTransform.php');
  38 +require_once(LOG4PHP_DIR . '/LoggerLayout.php');
  39 +
  40 +/**
  41 + * The output of the LoggerXmlLayout consists of a series of log4php:event elements.
  42 + *
  43 + * <p>Parameters: {@link $locationInfo}.</p>
  44 + *
  45 + * <p>It does not output a complete well-formed XML file.
  46 + * The output is designed to be included as an external entity in a separate file to form
  47 + * a correct XML file.</p>
  48 + *
  49 + * @author Marco Vassura
  50 + * @version $Revision: 635069 $
  51 + * @package log4php
  52 + * @subpackage layouts
  53 + */
  54 +class LoggerXmlLayout extends LoggerLayout {
  55 +
  56 + /**
  57 + * The <b>LocationInfo</b> option takes a boolean value. By default,
  58 + * it is set to false which means there will be no location
  59 + * information output by this layout. If the the option is set to
  60 + * true, then the file name and line number of the statement at the
  61 + * origin of the log statement will be output.
  62 + * @var boolean
  63 + */
  64 + var $locationInfo = true;
  65 +
  66 + /**
  67 + * @var boolean set the elements namespace
  68 + */
  69 + var $log4jNamespace = false;
  70 +
  71 +
  72 + /**
  73 + * @var string namespace
  74 + * @private
  75 + */
  76 + var $_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS;
  77 +
  78 + /**
  79 + * @var string namespace prefix
  80 + * @private
  81 + */
  82 + var $_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX;
  83 +
  84 + /**
  85 + * No options to activate.
  86 + */
  87 + function activateOptions()
  88 + {
  89 + if ($this->getLog4jNamespace()) {
  90 + $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS;
  91 + $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS_PREFIX;
  92 + } else {
  93 + $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS;
  94 + $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX;
  95 + }
  96 + }
  97 +
  98 + /**
  99 + * @return string
  100 + */
  101 + function getHeader()
  102 + {
  103 + return "<{$this->_namespacePrefix}:eventSet ".
  104 + "xmlns:{$this->_namespacePrefix}=\"{$this->_namespace}\" ".
  105 + "version=\"0.3\" ".
  106 + "includesLocationInfo=\"".($this->getLocationInfo() ? "true" : "false")."\"".
  107 + ">\r\n";
  108 + }
  109 +
  110 + /**
  111 + * Formats a {@link LoggerLoggingEvent} in conformance with the log4php.dtd.
  112 + *
  113 + * @param LoggerLoggingEvent $event
  114 + * @return string
  115 + */
  116 + function format($event)
  117 + {
  118 + $loggerName = $event->getLoggerName();
  119 + $timeStamp = number_format((float)($event->getTimeStamp() * 1000), 0, '', '');
  120 + $thread = $event->getThreadName();
  121 + $level = $event->getLevel();
  122 + $levelStr = $level->toString();
  123 +
  124 + $buf = "<{$this->_namespacePrefix}:event logger=\"{$loggerName}\" level=\"{$levelStr}\" thread=\"{$thread}\" timestamp=\"{$timeStamp}\">\r\n";
  125 + $buf .= "<{$this->_namespacePrefix}:message><![CDATA[";
  126 + LoggerTransform::appendEscapingCDATA($buf, $event->getRenderedMessage());
  127 + $buf .= "]]></{$this->_namespacePrefix}:message>\r\n";
  128 +
  129 + $ndc = $event->getNDC();
  130 + if($ndc != null) {
  131 + $buf .= "<{$this->_namespacePrefix}:NDC><![CDATA[";
  132 + LoggerTransform::appendEscapingCDATA($buf, $ndc);
  133 + $buf .= "]]></{$this->_namespacePrefix}:NDC>\r\n";
  134 + }
  135 +
  136 + if ($this->getLocationInfo()) {
  137 + $locationInfo = $event->getLocationInformation();
  138 + $buf .= "<{$this->_namespacePrefix}:locationInfo ".
  139 + "class=\"" . $locationInfo->getClassName() . "\" ".
  140 + "file=\"" . htmlentities($locationInfo->getFileName(), ENT_QUOTES) . "\" ".
  141 + "line=\"" . $locationInfo->getLineNumber() . "\" ".
  142 + "method=\"" . $locationInfo->getMethodName() . "\" ";
  143 + $buf .= "/>\r\n";
  144 +
  145 + }
  146 +
  147 + $buf .= "</{$this->_namespacePrefix}:event>\r\n\r\n";
  148 +
  149 + return $buf;
  150 +
  151 + }
  152 +
  153 + /**
  154 + * @return string
  155 + */
  156 + function getFooter()
  157 + {
  158 +
  159 + return "</{$this->_namespacePrefix}:eventSet>\r\n";
  160 + }
  161 +
  162 + /**
  163 + * @return boolean
  164 + */
  165 + function getLocationInfo()
  166 + {
  167 + return $this->locationInfo;
  168 + }
  169 +
  170 + /**
  171 + * @return boolean
  172 + */
  173 + function getLog4jNamespace()
  174 + {
  175 + return $this->log4jNamespace;
  176 + }
  177 +
  178 + /**
  179 + * The XMLLayout prints and does not ignore exceptions. Hence the
  180 + * return value <b>false</b>.
  181 + * @return boolean
  182 + */
  183 + function ignoresThrowable()
  184 + {
  185 + return false;
  186 + }
  187 +
  188 + /**
  189 + * The {@link $locationInfo} option takes a boolean value. By default,
  190 + * it is set to false which means there will be no location
  191 + * information output by this layout. If the the option is set to
  192 + * true, then the file name and line number of the statement at the
  193 + * origin of the log statement will be output.
  194 + */
  195 + function setLocationInfo($flag)
  196 + {
  197 + $this->locationInfo = LoggerOptionConverter::toBoolean($flag, true);
  198 + }
  199 +
  200 + /**
  201 + * @param boolean
  202 + */
  203 + function setLog4jNamespace($flag)
  204 + {
  205 + $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, true);
  206 + }
  207 +}
  208 +
... ...
thirdparty/apache-log4php/src/main/php/or/LoggerDefaultRenderer.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage or
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once LOG4PHP_DIR.'/or/LoggerObjectRenderer.php';
  31 +
  32 +/**
  33 + * The default Renderer renders objects by type casting
  34 + *
  35 + * @author Marco Vassura
  36 + * @package log4php
  37 + * @subpackage or
  38 + * @since 0.3
  39 + */
  40 +class LoggerDefaultRenderer extends LoggerObjectRenderer{
  41 +
  42 + /**
  43 + * Render objects by type casting
  44 + *
  45 + * @param mixed $o the object to render
  46 + * @return string
  47 + */
  48 + public function doRender($o) {
  49 + return var_export($o, true);
  50 + }
  51 +}
... ...
thirdparty/apache-log4php/src/main/php/or/LoggerObjectRenderer.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage or
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + * Subclass this abstract class in order to render objects as strings.
  30 + *
  31 + * @author Marco Vassura
  32 + * @version $Revision: 635069 $
  33 + * @package log4php
  34 + * @subpackage or
  35 + * @abstract
  36 + * @since 0.3
  37 + */
  38 +abstract class LoggerObjectRenderer {
  39 +
  40 + /**
  41 + * @param string $class classname
  42 + * @return LoggerObjectRenderer create LoggerObjectRenderer instances
  43 + */
  44 + public static function factory($class) {
  45 + if (!empty($class)) {
  46 + $class = basename($class);
  47 + include_once LOG4PHP_DIR."/or/{$class}.php";
  48 + if (class_exists($class)) {
  49 + return new $class();
  50 + }
  51 + }
  52 + return null;
  53 + }
  54 +
  55 + /**
  56 + * Render the entity passed as parameter as a String.
  57 + * @param mixed $o entity to render
  58 + * @return string
  59 + */
  60 + abstract public function doRender($o);
  61 +}
... ...
thirdparty/apache-log4php/src/main/php/or/LoggerRendererMap.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage or
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/or/LoggerDefaultRenderer.php');
  31 +require_once(LOG4PHP_DIR . '/or/LoggerObjectRenderer.php');
  32 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  33 +
  34 +/**
  35 + * Map class objects to an {@link LoggerObjectRenderer}.
  36 + *
  37 + * @author Marco Vassura
  38 + * @version $Revision: 635069 $
  39 + * @package log4php
  40 + * @subpackage or
  41 + * @since 0.3
  42 + */
  43 +class LoggerRendererMap {
  44 +
  45 + /**
  46 + * @var array
  47 + */
  48 + var $map;
  49 +
  50 + /**
  51 + * @var LoggerDefaultRenderer
  52 + */
  53 + var $defaultRenderer;
  54 +
  55 + /**
  56 + * Constructor
  57 + */
  58 + public function __construct()
  59 + {
  60 + $this->map = array();
  61 + $this->defaultRenderer = new LoggerDefaultRenderer();
  62 + }
  63 +
  64 + /**
  65 + * Add a renderer to a hierarchy passed as parameter.
  66 + * Note that hierarchy must implement getRendererMap() and setRenderer() methods.
  67 + *
  68 + * @param LoggerHierarchy $repository a logger repository.
  69 + * @param string $renderedClassName
  70 + * @param string $renderingClassName
  71 + * @static
  72 + */
  73 + public static function addRenderer($repository, $renderedClassName, $renderingClassName)
  74 + {
  75 + LoggerLog::debug("LoggerRendererMap::addRenderer() Rendering class: [{$renderingClassName}], Rendered class: [{$renderedClassName}].");
  76 + $renderer = LoggerObjectRenderer::factory($renderingClassName);
  77 + if($renderer == null) {
  78 + LoggerLog::warn("LoggerRendererMap::addRenderer() Could not instantiate renderer [{$renderingClassName}].");
  79 + return;
  80 + } else {
  81 + $repository->setRenderer($renderedClassName, $renderer);
  82 + }
  83 + }
  84 +
  85 +
  86 + /**
  87 + * Find the appropriate renderer for the class type of the
  88 + * <var>o</var> parameter.
  89 + *
  90 + * This is accomplished by calling the {@link getByObject()}
  91 + * method if <var>o</var> is object or using {@link LoggerDefaultRenderer}.
  92 + * Once a renderer is found, it is applied on the object <var>o</var> and
  93 + * the result is returned as a string.
  94 + *
  95 + * @param mixed $o
  96 + * @return string
  97 + */
  98 + public function findAndRender($o)
  99 + {
  100 + if($o == null) {
  101 + return null;
  102 + } else {
  103 + if (is_object($o)) {
  104 + $renderer = $this->getByObject($o);
  105 + if ($renderer !== null) {
  106 + return $renderer->doRender($o);
  107 + } else {
  108 + return null;
  109 + }
  110 + } else {
  111 + $renderer = $this->defaultRenderer;
  112 + return $renderer->doRender($o);
  113 + }
  114 + }
  115 + }
  116 +
  117 + /**
  118 + * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the
  119 + * class of the object parameter.
  120 + *
  121 + * @param mixed $o
  122 + * @return string
  123 + */
  124 + public function getByObject($o)
  125 + {
  126 + return ($o == null) ? null : $this->getByClassName(get_class($o));
  127 + }
  128 +
  129 +
  130 + /**
  131 + * Search the parents of <var>clazz</var> for a renderer.
  132 + *
  133 + * The renderer closest in the hierarchy will be returned. If no
  134 + * renderers could be found, then the default renderer is returned.
  135 + *
  136 + * @param string $class
  137 + * @return LoggerObjectRenderer
  138 + */
  139 + public function getByClassName($class)
  140 + {
  141 + $r = null;
  142 + for($c = strtolower($class); !empty($c); $c = get_parent_class($c)) {
  143 + if (isset($this->map[$c])) {
  144 + return $this->map[$c];
  145 + }
  146 + }
  147 + return $this->defaultRenderer;
  148 + }
  149 +
  150 + /**
  151 + * @return LoggerDefaultRenderer
  152 + */
  153 + public function getDefaultRenderer()
  154 + {
  155 + return $this->defaultRenderer;
  156 + }
  157 +
  158 +
  159 + public function clear()
  160 + {
  161 + $this->map = array();
  162 + }
  163 +
  164 + /**
  165 + * Register a {@link LoggerObjectRenderer} for <var>clazz</var>.
  166 + * @param string $class
  167 + * @param LoggerObjectRenderer $or
  168 + */
  169 + public function put($class, $or)
  170 + {
  171 + $this->map[strtolower($class)] = $or;
  172 + }
  173 +
  174 + /**
  175 + * @param string $class
  176 + * @return boolean
  177 + */
  178 + public function rendererExists($class)
  179 + {
  180 + $class = basename($class);
  181 + if (!class_exists($class)) {
  182 + include_once(LOG4PHP_DIR ."/or/{$class}.php");
  183 + }
  184 + return class_exists($class);
  185 + }
  186 +}
... ...
thirdparty/apache-log4php/src/main/php/spi/LoggerConfigurator.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage spi
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  27 +
  28 +/**
  29 + * Special level value signifying inherited behaviour. The current
  30 + * value of this string constant is <b>inherited</b>.
  31 + * {@link LOG4PHP_LOGGER_CONFIGURATOR_NULL} is a synonym.
  32 + */
  33 +define('LOG4PHP_LOGGER_CONFIGURATOR_INHERITED', 'inherited');
  34 +
  35 +/**
  36 + * Special level signifying inherited behaviour, same as
  37 + * {@link LOG4PHP_LOGGER_CONFIGURATOR_INHERITED}.
  38 + * The current value of this string constant is <b>null</b>.
  39 + */
  40 +define('LOG4PHP_LOGGER_CONFIGURATOR_NULL', 'null');
  41 +
  42 +/**
  43 + * Implemented by classes capable of configuring log4php using a URL.
  44 + *
  45 + * @author Marco Vassura
  46 + * @version $Revision: 635069 $
  47 + * @package log4php
  48 + * @subpackage spi
  49 + */
  50 +interface LoggerConfigurator {
  51 +
  52 + /**
  53 + * Interpret a resource pointed by a <var>url</var> and configure accordingly.
  54 + *
  55 + * The configuration is done relative to the <var>repository</var>
  56 + * parameter.
  57 + *
  58 + * @param string $url The URL to parse
  59 + */
  60 + public static function configure($url=null);
  61 +
  62 +}
... ...
thirdparty/apache-log4php/src/main/php/spi/LoggerFactory.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage spi
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
  27 +
  28 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  29 +
  30 +/**
  31 + * Extend and implement this abstract class to create new instances of
  32 + * {@link Logger} or a sub-class of {@link Logger}.
  33 + *
  34 + * @author Marco Vassura
  35 + * @version $Revision: 635069 $
  36 + * @package log4php
  37 + * @subpackage spi
  38 + * @since 0.5
  39 + * @abstract
  40 + */
  41 +abstract class LoggerFactory {
  42 +
  43 + /**
  44 + * @abstract
  45 + * @param string $name
  46 + * @return Logger
  47 + */
  48 + abstract function makeNewLoggerInstance($name);
  49 +
  50 +}
... ...
thirdparty/apache-log4php/src/main/php/spi/LoggerFilter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage spi
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + * The log event must be logged immediately without consulting with
  30 + * the remaining filters, if any, in the chain.
  31 + */
  32 +define('LOG4PHP_LOGGER_FILTER_ACCEPT', 1);
  33 +
  34 +/**
  35 + * This filter is neutral with respect to the log event. The
  36 + * remaining filters, if any, should be consulted for a final decision.
  37 + */
  38 +define('LOG4PHP_LOGGER_FILTER_NEUTRAL', 0);
  39 +
  40 +/**
  41 + * The log event must be dropped immediately without consulting
  42 + * with the remaining filters, if any, in the chain.
  43 + */
  44 +define('LOG4PHP_LOGGER_FILTER_DENY', -1);
  45 +
  46 +/**
  47 + * Users should extend this class to implement customized logging
  48 + * event filtering. Note that {@link LoggerCategory} and {@link LoggerAppenderSkeleton},
  49 + * the parent class of all standard
  50 + * appenders, have built-in filtering rules. It is suggested that you
  51 + * first use and understand the built-in rules before rushing to write
  52 + * your own custom filters.
  53 + *
  54 + * <p>This abstract class assumes and also imposes that filters be
  55 + * organized in a linear chain. The {@link #decide
  56 + * decide(LoggerLoggingEvent)} method of each filter is called sequentially,
  57 + * in the order of their addition to the chain.
  58 + *
  59 + * <p>The {@link decide()} method must return one
  60 + * of the integer constants {@link LOG4PHP_LOG4PHP_LOGGER_FILTER_DENY},
  61 + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_ACCEPT}.
  62 + *
  63 + * <p>If the value {@link LOG4PHP_LOGGER_FILTER_DENY} is returned, then the log event is
  64 + * dropped immediately without consulting with the remaining
  65 + * filters.
  66 + *
  67 + * <p>If the value {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned, then the next filter
  68 + * in the chain is consulted. If there are no more filters in the
  69 + * chain, then the log event is logged. Thus, in the presence of no
  70 + * filters, the default behaviour is to log all logging events.
  71 + *
  72 + * <p>If the value {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, then the log
  73 + * event is logged without consulting the remaining filters.
  74 + *
  75 + * <p>The philosophy of log4php filters is largely inspired from the
  76 + * Linux ipchains.
  77 + *
  78 + * @author Marco Vassura
  79 + * @version $Revision: 635069 $
  80 + * @package log4php
  81 + * @subpackage spi
  82 + */
  83 +class LoggerFilter {
  84 +
  85 + /**
  86 + * @var LoggerFilter Points to the next {@link LoggerFilter} in the filter chain.
  87 + */
  88 + protected $next;
  89 +
  90 + /**
  91 + * Usually filters options become active when set. We provide a
  92 + * default do-nothing implementation for convenience.
  93 + */
  94 + public function activateOptions()
  95 + {
  96 + return;
  97 + }
  98 +
  99 + /**
  100 + * Decide what to do.
  101 + * <p>If the decision is {@link LOG4PHP_LOGGER_FILTER_DENY}, then the event will be
  102 + * dropped. If the decision is {@link LOG4PHP_LOGGER_FILTER_NEUTRAL}, then the next
  103 + * filter, if any, will be invoked. If the decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} then
  104 + * the event will be logged without consulting with other filters in
  105 + * the chain.
  106 + *
  107 + * @param LoggerLoggingEvent $event The {@link LoggerLoggingEvent} to decide upon.
  108 + * @return integer {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_DENY}|{@link LOG4PHP_LOGGER_FILTER_ACCEPT}
  109 + */
  110 + public function decide($event)
  111 + {
  112 + return LOG4PHP_LOGGER_FILTER_NEUTRAL;
  113 + }
  114 +
  115 + public function getNext() {
  116 + return $this->next;
  117 + }
  118 +
  119 +}
... ...
thirdparty/apache-log4php/src/main/php/spi/LoggerLocationInfo.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage spi
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + * When location information is not available the constant
  30 + * <i>NA</i> is returned. Current value of this string
  31 + * constant is <b>?</b>.
  32 + */
  33 +define('LOG4PHP_LOGGER_LOCATION_INFO_NA', 'NA');
  34 +
  35 +/**
  36 + * The internal representation of caller location information.
  37 + *
  38 + * @author Marco Vassura
  39 + * @version $Revision: 635069 $
  40 + * @package log4php
  41 + * @subpackage spi
  42 + * @since 0.3
  43 + */
  44 +class LoggerLocationInfo {
  45 +
  46 + /**
  47 + * @var string Caller's line number.
  48 + */
  49 + protected $lineNumber = null;
  50 +
  51 + /**
  52 + * @var string Caller's file name.
  53 + */
  54 + protected $fileName = null;
  55 +
  56 + /**
  57 + * @var string Caller's fully qualified class name.
  58 + */
  59 + protected $className = null;
  60 +
  61 + /**
  62 + * @var string Caller's method name.
  63 + */
  64 + protected $methodName = null;
  65 +
  66 + /**
  67 + * @var string
  68 + */
  69 + protected $fullInfo = null;
  70 +
  71 + /**
  72 + * Instantiate location information based on a {@link PHP_MANUAL#debug_backtrace}.
  73 + *
  74 + * @param array $trace
  75 + * @param mixed $caller
  76 + */
  77 + public function __construct($trace, $fqcn = null)
  78 + {
  79 + $this->lineNumber = isset($trace['line']) ? $trace['line'] : null;
  80 + $this->fileName = isset($trace['file']) ? $trace['file'] : null;
  81 + $this->className = isset($trace['class']) ? $trace['class'] : null;
  82 + $this->methodName = isset($trace['function']) ? $trace['function'] : null;
  83 +
  84 + $this->fullInfo = $this->getClassName() . '.' . $this->getMethodName() .
  85 + '(' . $this->getFileName() . ':' . $this->getLineNumber() . ')';
  86 + }
  87 +
  88 + public function getClassName()
  89 + {
  90 + return ($this->className === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->className;
  91 + }
  92 +
  93 + /**
  94 + * Return the file name of the caller.
  95 + * <p>This information is not always available.
  96 + */
  97 + public function getFileName()
  98 + {
  99 + return ($this->fileName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->fileName;
  100 + }
  101 +
  102 + /**
  103 + * Returns the line number of the caller.
  104 + * <p>This information is not always available.
  105 + */
  106 + public function getLineNumber()
  107 + {
  108 + return ($this->lineNumber === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->lineNumber;
  109 + }
  110 +
  111 + /**
  112 + * Returns the method name of the caller.
  113 + */
  114 + public function getMethodName()
  115 + {
  116 + return ($this->methodName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->methodName;
  117 + }
  118 +}
... ...
thirdparty/apache-log4php/src/main/php/spi/LoggerLoggingEvent.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage spi
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/spi/LoggerLocationInfo.php');
  31 +require_once(LOG4PHP_DIR . '/LoggerManager.php');
  32 +require_once(LOG4PHP_DIR . '/LoggerMDC.php');
  33 +require_once(LOG4PHP_DIR . '/LoggerNDC.php');
  34 +
  35 +/**
  36 + * The internal representation of logging event.
  37 + *
  38 + * @author Marco Vassura
  39 + * @version $Revision: 635069 $
  40 + * @package log4php
  41 + * @subpackage spi
  42 + */
  43 +class LoggerLoggingEvent {
  44 +
  45 + private static $startTime;
  46 +
  47 + /**
  48 + * @var string Fully Qualified Class Name of the calling category class.
  49 + */
  50 + var $fqcn;
  51 +
  52 + /**
  53 + * @var Logger reference
  54 + */
  55 + var $logger = null;
  56 +
  57 + /**
  58 + * The category (logger) name.
  59 + * This field will be marked as private in future
  60 + * releases. Please do not access it directly.
  61 + * Use the {@link getLoggerName()} method instead.
  62 + * @deprecated
  63 + */
  64 + var $categoryName;
  65 +
  66 + /**
  67 + * Level of logging event.
  68 + * <p> This field should not be accessed directly. You shoud use the
  69 + * {@link getLevel()} method instead.
  70 + *
  71 + * @deprecated
  72 + * @var LoggerLevel
  73 + */
  74 + protected $level;
  75 +
  76 + /**
  77 + * @var string The nested diagnostic context (NDC) of logging event.
  78 + */
  79 + var $ndc;
  80 +
  81 + /**
  82 + * Have we tried to do an NDC lookup? If we did, there is no need
  83 + * to do it again. Note that its value is always false when
  84 + * serialized. Thus, a receiving SocketNode will never use it's own
  85 + * (incorrect) NDC. See also writeObject method.
  86 + * @var boolean
  87 + */
  88 + var $ndcLookupRequired = true;
  89 +
  90 + /**
  91 + * Have we tried to do an MDC lookup? If we did, there is no need
  92 + * to do it again. Note that its value is always false when
  93 + * serialized. See also the getMDC and getMDCCopy methods.
  94 + * @var boolean
  95 + */
  96 + var $mdcCopyLookupRequired = true;
  97 +
  98 + /**
  99 + * @var mixed The application supplied message of logging event.
  100 + */
  101 + var $message;
  102 +
  103 + /**
  104 + * The application supplied message rendered through the log4php
  105 + * objet rendering mechanism. At present renderedMessage == message.
  106 + * @var string
  107 + */
  108 + var $renderedMessage = null;
  109 +
  110 + /**
  111 + * The name of thread in which this logging event was generated.
  112 + * log4php saves here the process id via {@link PHP_MANUAL#getmypid getmypid()}
  113 + * @var mixed
  114 + */
  115 + var $threadName = null;
  116 +
  117 + /**
  118 + * The number of seconds elapsed from 1/1/1970 until logging event
  119 + * was created plus microseconds if available.
  120 + * @var float
  121 + */
  122 + public $timeStamp;
  123 +
  124 + /**
  125 + * @var LoggerLocationInfo Location information for the caller.
  126 + */
  127 + var $locationInfo = null;
  128 +
  129 + /**
  130 + * Instantiate a LoggingEvent from the supplied parameters.
  131 + *
  132 + * <p>Except {@link $timeStamp} all the other fields of
  133 + * LoggerLoggingEvent are filled when actually needed.
  134 + *
  135 + * @param string $fqcn name of the caller class.
  136 + * @param mixed $logger The {@link Logger} category of this event or the logger name.
  137 + * @param LoggerLevel $priority The level of this event.
  138 + * @param mixed $message The message of this event.
  139 + * @param integer $timeStamp the timestamp of this logging event.
  140 + */
  141 + public function __construct($fqcn, $logger, $priority, $message, $timeStamp = null)
  142 + {
  143 + $this->fqcn = $fqcn;
  144 + if ($logger instanceof Logger) {
  145 + $this->logger = $logger;
  146 + $this->categoryName = $logger->getName();
  147 + } else {
  148 + $this->categoryName = strval($logger);
  149 + }
  150 + $this->level = $priority;
  151 + $this->message = $message;
  152 + if ($timeStamp !== null && is_float($timeStamp)) {
  153 + $this->timeStamp = $timeStamp;
  154 + } else {
  155 + if (function_exists('microtime')) {
  156 + // get microtime as float
  157 + $this->timeStamp = microtime(true);
  158 + } else {
  159 + $this->timeStamp = floatval(time());
  160 + }
  161 + }
  162 + }
  163 +
  164 + /**
  165 + * Set the location information for this logging event. The collected
  166 + * information is cached for future use.
  167 + *
  168 + * <p>This method uses {@link PHP_MANUAL#debug_backtrace debug_backtrace()} function (if exists)
  169 + * to collect informations about caller.</p>
  170 + * <p>It only recognize informations generated by {@link Logger} and its subclasses.</p>
  171 + * @return LoggerLocationInfo
  172 + */
  173 + public function getLocationInformation()
  174 + {
  175 + if($this->locationInfo === null) {
  176 +
  177 + $locationInfo = array();
  178 +
  179 + if (function_exists('debug_backtrace')) {
  180 + $trace = debug_backtrace();
  181 + $prevHop = null;
  182 + // make a downsearch to identify the caller
  183 + $hop = array_pop($trace);
  184 + while ($hop !== null) {
  185 + $className = @strtolower($hop['class']);
  186 + if ( !empty($className) and ($className == 'logger' or $className == 'loggercategory' or
  187 + get_parent_class($className) == 'logger') or get_parent_class($className) == 'loggercategory') {
  188 + $locationInfo['line'] = $hop['line'];
  189 + $locationInfo['file'] = $hop['file'];
  190 + break;
  191 + }
  192 + $prevHop = $hop;
  193 + $hop = array_pop($trace);
  194 + }
  195 + $locationInfo['class'] = isset($prevHop['class']) ? $prevHop['class'] : 'main';
  196 + if (isset($prevHop['function']) and
  197 + $prevHop['function'] !== 'include' and
  198 + $prevHop['function'] !== 'include_once' and
  199 + $prevHop['function'] !== 'require' and
  200 + $prevHop['function'] !== 'require_once') {
  201 +
  202 + $locationInfo['function'] = $prevHop['function'];
  203 + } else {
  204 + $locationInfo['function'] = 'main';
  205 + }
  206 + }
  207 +
  208 + $this->locationInfo = new LoggerLocationInfo($locationInfo, $this->fqcn);
  209 + }
  210 + return $this->locationInfo;
  211 + }
  212 +
  213 + /**
  214 + * Return the level of this event. Use this form instead of directly
  215 + * accessing the {@link $level} field.
  216 + * @return LoggerLevel
  217 + */
  218 + public function getLevel()
  219 + {
  220 + return $this->level;
  221 + }
  222 +
  223 + /**
  224 + * Return the name of the logger. Use this form instead of directly
  225 + * accessing the {@link $categoryName} field.
  226 + * @return string
  227 + */
  228 + public function getLoggerName()
  229 + {
  230 + return $this->categoryName;
  231 + }
  232 +
  233 + /**
  234 + * Return the message for this logging event.
  235 + *
  236 + * <p>Before serialization, the returned object is the message
  237 + * passed by the user to generate the logging event. After
  238 + * serialization, the returned value equals the String form of the
  239 + * message possibly after object rendering.
  240 + * @return mixed
  241 + */
  242 + public function getMessage()
  243 + {
  244 + if($this->message !== null) {
  245 + return $this->message;
  246 + } else {
  247 + return $this->getRenderedMessage();
  248 + }
  249 + }
  250 +
  251 + /**
  252 + * This method returns the NDC for this event. It will return the
  253 + * correct content even if the event was generated in a different
  254 + * thread or even on a different machine. The {@link LoggerNDC::get()} method
  255 + * should <b>never</b> be called directly.
  256 + * @return string
  257 + */
  258 + public function getNDC()
  259 + {
  260 + if ($this->ndcLookupRequired) {
  261 + $this->ndcLookupRequired = false;
  262 + $this->ndc = implode(' ',LoggerNDC::get());
  263 + }
  264 + return $this->ndc;
  265 + }
  266 +
  267 +
  268 + /**
  269 + * Returns the the context corresponding to the <code>key</code>
  270 + * parameter.
  271 + * @return string
  272 + */
  273 + public function getMDC($key)
  274 + {
  275 + return LoggerMDC::get($key);
  276 + }
  277 +
  278 + /**
  279 + * Render message.
  280 + * @return string
  281 + */
  282 + public function getRenderedMessage()
  283 + {
  284 + if($this->renderedMessage === null and $this->message !== null) {
  285 + if (is_string($this->message)) {
  286 + $this->renderedMessage = $this->message;
  287 + } else {
  288 + if ($this->logger !== null) {
  289 + $repository = $this->logger->getLoggerRepository();
  290 + } else {
  291 + $repository = LoggerManager::getLoggerRepository();
  292 + }
  293 + if (method_exists($repository, 'getRendererMap')) {
  294 + $rendererMap = $repository->getRendererMap();
  295 + $this->renderedMessage= $rendererMap->findAndRender($this->message);
  296 + } else {
  297 + $this->renderedMessage = (string)$this->message;
  298 + }
  299 + }
  300 + }
  301 + return $this->renderedMessage;
  302 + }
  303 +
  304 + /**
  305 + * Returns the time when the application started, in seconds
  306 + * elapsed since 01.01.1970 plus microseconds if available.
  307 + *
  308 + * @return float
  309 + * @static
  310 + */
  311 + public static function getStartTime() {
  312 + if (!isset(self::$startTime)) {
  313 + if (function_exists('microtime')) {
  314 + // microtime as float
  315 + self::$startTime = microtime(true);
  316 + } else {
  317 + self::$startTime = floatval(time());
  318 + }
  319 + }
  320 + return self::$startTime;
  321 + }
  322 +
  323 + /**
  324 + * @return float
  325 + */
  326 + public function getTimeStamp()
  327 + {
  328 + return $this->timeStamp;
  329 + }
  330 +
  331 + /**
  332 + * @return mixed
  333 + */
  334 + public function getThreadName()
  335 + {
  336 + if ($this->threadName === null)
  337 + $this->threadName = (string)getmypid();
  338 + return $this->threadName;
  339 + }
  340 +
  341 + /**
  342 + * @return mixed null
  343 + */
  344 + public function getThrowableInformation()
  345 + {
  346 + return null;
  347 + }
  348 +
  349 + /**
  350 + * Serialize this object
  351 + * @return string
  352 + */
  353 + public function toString()
  354 + {
  355 + serialize($this);
  356 + }
  357 +
  358 + /**
  359 + * Avoid serialization of the {@link $logger} object
  360 + */
  361 + public function __sleep()
  362 + {
  363 + return array(
  364 + 'fqcn','categoryName',
  365 + 'level',
  366 + 'ndc','ndcLookupRequired',
  367 + 'message','renderedMessage',
  368 + 'threadName',
  369 + 'timeStamp',
  370 + 'locationInfo'
  371 + );
  372 + }
  373 +
  374 +}
  375 +
  376 +LoggerLoggingEvent::getStartTime();
  377 +
... ...
thirdparty/apache-log4php/src/main/php/varia/LoggerDenyAllFilter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage varia
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php');
  31 +
  32 +/**
  33 + * This filter drops all logging events.
  34 + *
  35 + * <p>You can add this filter to the end of a filter chain to
  36 + * switch from the default "accept all unless instructed otherwise"
  37 + * filtering behaviour to a "deny all unless instructed otherwise"
  38 + * behaviour.</p>
  39 + *
  40 + * @author Marco Vassura
  41 + * @version $Revision: 635069 $
  42 + * @package log4php
  43 + * @subpackage varia
  44 + * @since 0.3
  45 + */
  46 +class LoggerDenyAllFilter extends LoggerFilter {
  47 +
  48 + /**
  49 + * Always returns the integer constant {@link LOG4PHP_LOGGER_FILTER_DENY}
  50 + * regardless of the {@link LoggerLoggingEvent} parameter.
  51 + *
  52 + * @param LoggerLoggingEvent $event The {@link LoggerLoggingEvent} to filter.
  53 + * @return LOG4PHP_LOGGER_FILTER_DENY Always returns {@link LOG4PHP_LOGGER_FILTER_DENY}
  54 + */
  55 + function decide($event)
  56 + {
  57 + return LOG4PHP_LOGGER_FILTER_DENY;
  58 + }
  59 +}
... ...
thirdparty/apache-log4php/src/main/php/varia/LoggerLevelMatchFilter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage varia
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  31 +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php');
  32 +
  33 +/**
  34 + * This is a very simple filter based on level matching.
  35 + *
  36 + * <p>The filter admits two options <b><var>LevelToMatch</var></b> and
  37 + * <b><var>AcceptOnMatch</var></b>. If there is an exact match between the value
  38 + * of the <b><var>LevelToMatch</var></b> option and the level of the
  39 + * {@link LoggerLoggingEvent}, then the {@link decide()} method returns
  40 + * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} in case the <b><var>AcceptOnMatch</var></b>
  41 + * option value is set to <i>true</i>, if it is <i>false</i> then
  42 + * {@link LOG4PHP_LOGGER_FILTER_DENY} is returned. If there is no match,
  43 + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned.</p>
  44 + *
  45 + * @author Marco Vassura
  46 + * @version $Revision: 635069 $
  47 + * @package log4php
  48 + * @subpackage varia
  49 + * @since 0.6
  50 + */
  51 +class LoggerLevelMatchFilter extends LoggerFilter {
  52 +
  53 + /**
  54 + * @var boolean
  55 + */
  56 + var $acceptOnMatch = true;
  57 +
  58 + /**
  59 + * @var LoggerLevel
  60 + */
  61 + var $levelToMatch;
  62 +
  63 + /**
  64 + * @return boolean
  65 + */
  66 + function getAcceptOnMatch()
  67 + {
  68 + return $this->acceptOnMatch;
  69 + }
  70 +
  71 + /**
  72 + * @param boolean $acceptOnMatch
  73 + */
  74 + function setAcceptOnMatch($acceptOnMatch)
  75 + {
  76 + $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true);
  77 + }
  78 +
  79 + /**
  80 + * @return LoggerLevel
  81 + */
  82 + function getLevelToMatch()
  83 + {
  84 + return $this->levelToMatch;
  85 + }
  86 +
  87 + /**
  88 + * @param string $l the level to match
  89 + */
  90 + function setLevelToMatch($l)
  91 + {
  92 + $this->levelToMatch = LoggerOptionConverter::toLevel($l, null);
  93 + }
  94 +
  95 + /**
  96 + * Return the decision of this filter.
  97 + *
  98 + * Returns {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} if the <b><var>LevelToMatch</var></b>
  99 + * option is not set or if there is not match. Otherwise, if there is a
  100 + * match, then the returned decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} if the
  101 + * <b><var>AcceptOnMatch</var></b> property is set to <i>true</i>. The
  102 + * returned decision is {@link LOG4PHP_LOGGER_FILTER_DENY} if the
  103 + * <b><var>AcceptOnMatch</var></b> property is set to <i>false</i>.
  104 + *
  105 + * @param LoggerLoggingEvent $event
  106 + * @return integer
  107 + */
  108 + function decide($event)
  109 + {
  110 + if($this->levelToMatch === null)
  111 + return LOG4PHP_LOGGER_FILTER_NEUTRAL;
  112 +
  113 + if ($this->levelToMatch->equals($event->getLevel())) {
  114 + return $this->getAcceptOnMatch() ?
  115 + LOG4PHP_LOGGER_FILTER_ACCEPT :
  116 + LOG4PHP_LOGGER_FILTER_DENY;
  117 + } else {
  118 + return LOG4PHP_LOGGER_FILTER_NEUTRAL;
  119 + }
  120 + }
  121 +}
... ...
thirdparty/apache-log4php/src/main/php/varia/LoggerLevelRangeFilter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage varia
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  31 +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php');
  32 +
  33 +/**
  34 + * This is a very simple filter based on level matching, which can be
  35 + * used to reject messages with priorities outside a certain range.
  36 + *
  37 + * <p>The filter admits three options <b><var>LevelMin</var></b>, <b><var>LevelMax</var></b>
  38 + * and <b><var>AcceptOnMatch</var></b>.</p>
  39 + *
  40 + * <p>If the level of the {@link LoggerLoggingEvent} is not between Min and Max
  41 + * (inclusive), then {@link LOG4PHP_LOGGER_FILTER_DENY} is returned.</p>
  42 + *
  43 + * <p>If the Logging event level is within the specified range, then if
  44 + * <b><var>AcceptOnMatch</var></b> is <i>true</i>,
  45 + * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, and if
  46 + * <b><var>AcceptOnMatch</var></b> is <i>false</i>,
  47 + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned.</p>
  48 + *
  49 + * <p>If <b><var>LevelMin</var></b> is not defined, then there is no
  50 + * minimum acceptable level (i.e. a level is never rejected for
  51 + * being too "low"/unimportant). If <b><var>LevelMax</var></b> is not
  52 + * defined, then there is no maximum acceptable level (ie a
  53 + * level is never rejected for being too "high"/important).</p>
  54 + *
  55 + * <p>Refer to the {@link LoggerAppenderSkeleton::setThreshold()} method
  56 + * available to <b>all</b> appenders extending {@link LoggerAppenderSkeleton}
  57 + * for a more convenient way to filter out events by level.</p>
  58 + *
  59 + * @log4j-class org.apache.log4j.varia.LevelRangeFilter
  60 + * @log4j-author Simon Kitching
  61 + * @log4j-author based on code by Ceki G&uuml;lc&uuml;
  62 + *
  63 + * @author Marco Vassura
  64 + * @version $Revision: 635069 $
  65 + * @package log4php
  66 + * @subpackage varia
  67 + * @since 0.6
  68 + */
  69 +class LoggerLevelRangeFilter extends LoggerFilter {
  70 +
  71 + /**
  72 + * @var boolean
  73 + */
  74 + var $acceptOnMatch = true;
  75 +
  76 + /**
  77 + * @var LoggerLevel
  78 + */
  79 + var $levelMin;
  80 +
  81 + /**
  82 + * @var LoggerLevel
  83 + */
  84 + var $levelMax;
  85 +
  86 + /**
  87 + * @return boolean
  88 + */
  89 + function getAcceptOnMatch()
  90 + {
  91 + return $this->acceptOnMatch;
  92 + }
  93 +
  94 + /**
  95 + * @param boolean $acceptOnMatch
  96 + */
  97 + function setAcceptOnMatch($acceptOnMatch)
  98 + {
  99 + $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true);
  100 + }
  101 +
  102 + /**
  103 + * @return LoggerLevel
  104 + */
  105 + function getLevelMin()
  106 + {
  107 + return $this->levelMin;
  108 + }
  109 +
  110 + /**
  111 + * @param string $l the level min to match
  112 + */
  113 + function setLevelMin($l)
  114 + {
  115 + $this->levelMin = LoggerOptionConverter::toLevel($l, null);
  116 + }
  117 +
  118 + /**
  119 + * @return LoggerLevel
  120 + */
  121 + function getLevelMax()
  122 + {
  123 + return $this->levelMax;
  124 + }
  125 +
  126 + /**
  127 + * @param string $l the level max to match
  128 + */
  129 + function setLevelMax($l)
  130 + {
  131 + $this->levelMax = LoggerOptionConverter::toLevel($l, null);
  132 + }
  133 +
  134 + /**
  135 + * Return the decision of this filter.
  136 + *
  137 + * @param LoggerLoggingEvent $event
  138 + * @return integer
  139 + */
  140 + function decide($event)
  141 + {
  142 + $level = $event->getLevel();
  143 +
  144 + if($this->levelMin !== null) {
  145 + if ($level->isGreaterOrEqual($this->levelMin) == false) {
  146 + // level of event is less than minimum
  147 + return LOG4PHP_LOGGER_FILTER_DENY;
  148 + }
  149 + }
  150 +
  151 + if($this->levelMax !== null) {
  152 + if ($level->toInt() > $this->levelMax->toInt()) {
  153 + // level of event is greater than maximum
  154 + // Alas, there is no Level.isGreater method. and using
  155 + // a combo of isGreaterOrEqual && !Equal seems worse than
  156 + // checking the int values of the level objects..
  157 + return LOG4PHP_LOGGER_FILTER_DENY;
  158 + }
  159 + }
  160 +
  161 + if ($this->getAcceptOnMatch()) {
  162 + // this filter set up to bypass later filters and always return
  163 + // accept if level in range
  164 + return LOG4PHP_LOGGER_FILTER_ACCEPT;
  165 + } else {
  166 + // event is ok for this filter; allow later filters to have a look..
  167 + return LOG4PHP_LOGGER_FILTER_NEUTRAL;
  168 + }
  169 + }
  170 +}
... ...
thirdparty/apache-log4php/src/main/php/varia/LoggerStringMatchFilter.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage varia
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +/**
  29 + */
  30 +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php');
  31 +
  32 +/**
  33 + * This is a very simple filter based on string matching.
  34 + *
  35 + * <p>The filter admits two options {@link $stringToMatch} and
  36 + * {@link $acceptOnMatch}. If there is a match (using {@link PHP_MANUAL#strpos}
  37 + * between the value of the {@link $stringToMatch} option and the message
  38 + * of the {@link LoggerLoggingEvent},
  39 + * then the {@link decide()} method returns {@link LOG4PHP_LOGGER_FILTER_ACCEPT} if
  40 + * the <b>AcceptOnMatch</b> option value is true, if it is false then
  41 + * {@link LOG4PHP_LOGGER_FILTER_DENY} is returned. If there is no match, {@link LOG4PHP_LOGGER_FILTER_NEUTRAL}
  42 + * is returned.</p>
  43 + *
  44 + * @author Marco Vassura
  45 + * @version $Revision: 635069 $
  46 + * @package log4php
  47 + * @subpackage varia
  48 + * @since 0.3
  49 + */
  50 +class LoggerStringMatchFilter extends LoggerFilter {
  51 +
  52 + /**
  53 + * @var boolean
  54 + */
  55 + var $acceptOnMatch = true;
  56 +
  57 + /**
  58 + * @var string
  59 + */
  60 + var $stringToMatch = null;
  61 +
  62 + /**
  63 + * @return boolean
  64 + */
  65 + function getAcceptOnMatch()
  66 + {
  67 + return $this->acceptOnMatch;
  68 + }
  69 +
  70 + /**
  71 + * @param mixed $acceptOnMatch a boolean or a string ('true' or 'false')
  72 + */
  73 + function setAcceptOnMatch($acceptOnMatch)
  74 + {
  75 + $this->acceptOnMatch = is_bool($acceptOnMatch) ?
  76 + $acceptOnMatch :
  77 + (bool)(strtolower($acceptOnMatch) == 'true');
  78 + }
  79 +
  80 + /**
  81 + * @return string
  82 + */
  83 + function getStringToMatch()
  84 + {
  85 + return $this->stringToMatch;
  86 + }
  87 +
  88 + /**
  89 + * @param string $s the string to match
  90 + */
  91 + function setStringToMatch($s)
  92 + {
  93 + $this->stringToMatch = $s;
  94 + }
  95 +
  96 + /**
  97 + * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match.
  98 + */
  99 + function decide($event)
  100 + {
  101 + $msg = $event->getRenderedMessage();
  102 +
  103 + if($msg === null or $this->stringToMatch === null)
  104 + return LOG4PHP_LOGGER_FILTER_NEUTRAL;
  105 + if( strpos($msg, $this->stringToMatch) !== false ) {
  106 + return ($this->acceptOnMatch) ? LOG4PHP_LOGGER_FILTER_ACCEPT : LOG4PHP_LOGGER_FILTER_DENY ;
  107 + }
  108 + return LOG4PHP_LOGGER_FILTER_NEUTRAL;
  109 + }
  110 +}
... ...
thirdparty/apache-log4php/src/main/php/xml/LoggerDOMConfigurator.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * Licensed to the Apache Software Foundation (ASF) under one or more
  4 + * contributor license agreements. See the NOTICE file distributed with
  5 + * this work for additional information regarding copyright ownership.
  6 + * The ASF licenses this file to You under the Apache License, Version 2.0
  7 + * (the "License"); you may not use this file except in compliance with
  8 + * the License. You may obtain a copy of the License at
  9 + *
  10 + * http://www.apache.org/licenses/LICENSE-2.0
  11 + *
  12 + * Unless required by applicable law or agreed to in writing, software
  13 + * distributed under the License is distributed on an "AS IS" BASIS,
  14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + * See the License for the specific language governing permissions and
  16 + * limitations under the License.
  17 + *
  18 + *
  19 + * @package log4php
  20 + * @subpackage xml
  21 + */
  22 +
  23 +/**
  24 + * @ignore
  25 + */
  26 +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  27 +
  28 +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
  29 +require_once(LOG4PHP_DIR . '/or/LoggerObjectRenderer.php');
  30 +require_once(LOG4PHP_DIR . '/spi/LoggerConfigurator.php');
  31 +require_once(LOG4PHP_DIR . '/LoggerAppender.php');
  32 +require_once(LOG4PHP_DIR . '/LoggerLayout.php');
  33 +require_once(LOG4PHP_DIR . '/LoggerLog.php');
  34 +require_once(LOG4PHP_DIR . '/LoggerManager.php');
  35 +
  36 +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_APPENDER_STATE', 1000);
  37 +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_LAYOUT_STATE', 1010);
  38 +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE', 1020);
  39 +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE', 1030);
  40 +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_FILTER_STATE', 1040);
  41 +
  42 +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_DEFAULT_FILENAME', './log4php.xml');
  43 +
  44 +/**
  45 + * @var string the default configuration document
  46 + */
  47 +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_DEFAULT_CONFIGURATION',
  48 +'<?xml version="1.0" ?>
  49 +<log4php:configuration threshold="all">
  50 + <appender name="A1" class="LoggerAppenderEcho">
  51 + <layout class="LoggerLayoutSimple" />
  52 + </appender>
  53 + <root>
  54 + <level value="debug" />
  55 + <appender_ref ref="A1" />
  56 + </root>
  57 +</log4php:configuration>');
  58 +
  59 +/**
  60 + * @var string the elements namespace
  61 + */
  62 +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS', 'HTTP://LOGGING.APACHE.ORG/LOG4PHP/');
  63 +
  64 +/**
  65 + * Use this class to initialize the log4php environment using expat parser.
  66 + *
  67 + * <p>Read the log4php.dtd included in the documentation directory. Note that
  68 + * php parser does not validate the document.</p>
  69 + *
  70 + * <p>Sometimes it is useful to see how log4php is reading configuration
  71 + * files. You can enable log4php internal logging by setting the <var>debug</var>
  72 + * attribute in the <var>log4php:configuration</var> element. As in
  73 + * <pre>
  74 + * &lt;log4php:configuration <b>debug="true"</b> xmlns:log4php="http://logging.apache.org/log4php/">
  75 + * ...
  76 + * &lt;/log4php:configuration>
  77 + * </pre>
  78 + *
  79 + * <p>There are sample XML files included in the package under <b>tests/</b>
  80 + * subdirectories.</p>
  81 + *
  82 + * @author Marco Vassura
  83 + * @author Knut Urdalen <knut.urdalen@gmail.com>
  84 + * @version $Revision: 635069 $
  85 + * @package log4php
  86 + * @subpackage xml
  87 + * @since 0.4
  88 + */
  89 +class LoggerDOMConfigurator implements LoggerConfigurator {
  90 +
  91 + /**
  92 + * @var LoggerHierarchy
  93 + */
  94 + var $repository;
  95 +
  96 + /**
  97 + * @var array state stack
  98 + */
  99 + var $state;
  100 +
  101 + /**
  102 + * @var Logger parsed Logger
  103 + */
  104 + var $logger;
  105 +
  106 + /**
  107 + * @var LoggerAppender parsed LoggerAppender
  108 + */
  109 + var $appender;
  110 +
  111 + /**
  112 + * @var LoggerFilter parsed LoggerFilter
  113 + */
  114 + var $filter;
  115 +
  116 + /**
  117 + * @var LoggerLayout parsed LoggerLayout
  118 + */
  119 + var $layout;
  120 +
  121 + /**
  122 + * Constructor
  123 + */
  124 + function LoggerDOMConfigurator()
  125 + {
  126 + $this->state = array();
  127 + $this->logger = null;
  128 + $this->appender = null;
  129 + $this->filter = null;
  130 + $this->layout = null;
  131 + }
  132 +
  133 + /**
  134 + * Configure the default repository using the resource pointed by <b>url</b>.
  135 + * <b>Url</b> is any valid resource as defined in {@link PHP_MANUAL#file} function.
  136 + * Note that the resource will be search with <i>use_include_path</i> parameter
  137 + * set to "1".
  138 + *
  139 + * @param string $url
  140 + * @static
  141 + */
  142 + public static function configure($url = '') {
  143 + $configurator = new LoggerDOMConfigurator();
  144 + $repository =& LoggerManager::getLoggerRepository();
  145 + return $configurator->doConfigure($url, $repository);
  146 + }
  147 +
  148 + /**
  149 + * Configure the given <b>repository</b> using the resource pointed by <b>url</b>.
  150 + * <b>Url</b> is any valid resurce as defined in {@link PHP_MANUAL#file} function.
  151 + * Note that the resource will be search with <i>use_include_path</i> parameter
  152 + * set to "1".
  153 + *
  154 + * @param string $url
  155 + * @param LoggerHierarchy &$repository
  156 + */
  157 + function doConfigure($url = '', &$repository)
  158 + {
  159 + $xmlData = '';
  160 + if (!empty($url))
  161 + $xmlData = implode('', file($url, 1));
  162 + return $this->doConfigureByString($xmlData, $repository);
  163 + }
  164 +
  165 + /**
  166 + * Configure the given <b>repository</b> using the configuration written in <b>xmlData</b>.
  167 + * Do not call this method directly. Use {@link doConfigure()} instead.
  168 + * @param string $xmlData
  169 + * @param LoggerHierarchy &$repository
  170 + */
  171 + function doConfigureByString($xmlData, &$repository)
  172 + {
  173 + return $this->parse($xmlData, $repository);
  174 + }
  175 +
  176 + /**
  177 + * @param LoggerHierarchy &$repository
  178 + */
  179 + function doConfigureDefault(&$repository)
  180 + {
  181 + return $this->doConfigureByString(LOG4PHP_LOGGER_DOM_CONFIGURATOR_DEFAULT_CONFIGURATION, $repository);
  182 + }
  183 +
  184 + /**
  185 + * @param string $xmlData
  186 + */
  187 + function parse($xmlData, &$repository)
  188 + {
  189 + // LoggerManager::resetConfiguration();
  190 + $this->repository =& $repository;
  191 +
  192 + $parser = xml_parser_create_ns();
  193 +
  194 + xml_set_object($parser, $this);
  195 + xml_set_element_handler($parser, "tagOpen", "tagClose");
  196 +
  197 + $result = xml_parse($parser, $xmlData, true);
  198 + if (!$result) {
  199 + $errorCode = xml_get_error_code($parser);
  200 + $errorStr = xml_error_string($errorCode);
  201 + $errorLine = xml_get_current_line_number($parser);
  202 + LoggerLog::warn(
  203 + "LoggerDOMConfigurator::parse() ".
  204 + "Parsing error [{$errorCode}] {$errorStr}, line {$errorLine}"
  205 + );
  206 + $this->repository->resetConfiguration();
  207 + } else {
  208 + xml_parser_free($parser);
  209 + }
  210 + return $result;
  211 + }
  212 +
  213 + /**
  214 + * @param mixed $parser
  215 + * @param string $tag
  216 + * @param array $attribs
  217 + *
  218 + * @todo In 'LOGGER' case find a better way to detect 'getLogger()' method
  219 + */
  220 + function tagOpen($parser, $tag, $attribs)
  221 + {
  222 + switch ($tag) {
  223 +
  224 + case 'CONFIGURATION' :
  225 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':CONFIGURATION':
  226 +
  227 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() CONFIGURATION");
  228 +
  229 + if (isset($attribs['THRESHOLD'])) {
  230 +
  231 + $this->repository->setThreshold(
  232 + LoggerOptionConverter::toLevel(
  233 + $this->subst($attribs['THRESHOLD']),
  234 + $this->repository->getThreshold()
  235 + )
  236 + );
  237 + }
  238 + if (isset($attribs['DEBUG'])) {
  239 + $debug = LoggerOptionConverter::toBoolean($this->subst($attribs['DEBUG']), LoggerLog::internalDebugging());
  240 + $this->repository->debug = $debug;
  241 + LoggerLog::internalDebugging($debug);
  242 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LOG4PHP:CONFIGURATION. Internal Debug turned ".($debug ? 'on':'off'));
  243 +
  244 + }
  245 + break;
  246 +
  247 + case 'APPENDER' :
  248 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':APPENDER':
  249 +
  250 + unset($this->appender);
  251 + $this->appender = null;
  252 +
  253 + $name = $this->subst(@$attribs['NAME']);
  254 + $class = $this->subst(@$attribs['CLASS']);
  255 +
  256 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen():tag=[$tag]:name=[$name]:class=[$class]");
  257 +
  258 + $this->appender =& LoggerAppender::singleton($name, $class);
  259 + if ($this->appender === null) {
  260 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER cannot instantiate appender '$name'");
  261 + }
  262 + $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_APPENDER_STATE;
  263 + break;
  264 +
  265 + case 'APPENDER_REF' :
  266 + case 'APPENDER-REF' :
  267 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':APPENDER_REF':
  268 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':APPENDER-REF':
  269 +
  270 +
  271 + if (isset($attribs['REF']) and !empty($attribs['REF'])) {
  272 + $appenderName = $this->subst($attribs['REF']);
  273 +
  274 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref='$appenderName'");
  275 +
  276 + $appender =& LoggerAppender::singleton($appenderName);
  277 + if ($appender !== null) {
  278 + switch (end($this->state)) {
  279 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE:
  280 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE:
  281 + $this->logger->addAppender($appender);
  282 + break;
  283 + }
  284 + } else {
  285 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref '$appenderName' points to a null appender");
  286 + }
  287 + } else {
  288 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref not set or empty");
  289 + }
  290 + break;
  291 +
  292 + case 'FILTER' :
  293 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':FILTER':
  294 +
  295 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() FILTER");
  296 +
  297 + unset($this->filter);
  298 + $this->filter = null;
  299 +
  300 + $filterName = basename($this->subst(@$attribs['CLASS']));
  301 + if (!empty($filterName)) {
  302 + if (!class_exists($filterName)) {
  303 + @include_once(LOG4PHP_DIR . "/varia/{$filterName}.php");
  304 + }
  305 + if (class_exists($filterName)) {
  306 + $this->filter = new $filterName();
  307 + } else {
  308 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() FILTER. class '$filterName' doesnt exist");
  309 + }
  310 + $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_FILTER_STATE;
  311 + } else {
  312 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() FILTER filter name cannot be empty");
  313 + }
  314 + break;
  315 +
  316 + case 'LAYOUT':
  317 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':LAYOUT':
  318 +
  319 + $class = @$attribs['CLASS'];
  320 +
  321 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LAYOUT class='{$class}'");
  322 +
  323 + $this->layout = LoggerLayout::factory($this->subst($class));
  324 + if ($this->layout === null)
  325 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LAYOUT unable to instanciate class='{$class}'");
  326 +
  327 + $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_LAYOUT_STATE;
  328 + break;
  329 +
  330 + case 'LOGGER':
  331 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':LOGGER':
  332 +
  333 + // $this->logger is assigned by reference.
  334 + // Only '$this->logger=null;' destroys referenced object
  335 + unset($this->logger);
  336 + $this->logger = null;
  337 +
  338 + $loggerName = $this->subst(@$attribs['NAME']);
  339 + if (!empty($loggerName)) {
  340 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LOGGER. name='$loggerName'");
  341 +
  342 + $class = $this->subst(@$attribs['CLASS']);
  343 + if (empty($class)) {
  344 + $this->logger =& $this->repository->getLogger($loggerName);
  345 + } else {
  346 + $className = basename($class);
  347 + if (!class_exists($className))
  348 + @include_once("{$class}.php");
  349 + if (!class_exists($className)) {
  350 + LoggerLog::warn(
  351 + "LoggerDOMConfigurator::tagOpen() LOGGER. ".
  352 + "cannot find '$className'."
  353 + );
  354 + } else {
  355 +
  356 + if (in_array('getlogger', get_class_methods($className))) {
  357 + $this->logger =& call_user_func(array($className, 'getlogger'), $loggerName);
  358 + } else {
  359 + LoggerLog::warn(
  360 + "LoggerDOMConfigurator::tagOpen() LOGGER. ".
  361 + "class '$className' doesnt implement 'getLogger()' method."
  362 + );
  363 + }
  364 + }
  365 + }
  366 + if ($this->logger !== null and isset($attribs['ADDITIVITY'])) {
  367 + $additivity = LoggerOptionConverter::toBoolean($this->subst($attribs['ADDITIVITY']), true);
  368 + $this->logger->setAdditivity($additivity);
  369 + }
  370 + } else {
  371 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LOGGER. Attribute 'name' is not set or is empty.");
  372 + }
  373 + $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE;;
  374 + break;
  375 +
  376 + case 'LEVEL':
  377 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':LEVEL':
  378 + case 'PRIORITY':
  379 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':PRIORITY':
  380 +
  381 + if (!isset($attribs['VALUE'])) {
  382 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL value not set");
  383 + break;
  384 + }
  385 +
  386 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL value={$attribs['VALUE']}");
  387 +
  388 + if ($this->logger === null) {
  389 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LEVEL. parent logger is null");
  390 + break;
  391 + }
  392 +
  393 + switch (end($this->state)) {
  394 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE:
  395 + $this->logger->setLevel(
  396 + LoggerOptionConverter::toLevel(
  397 + $this->subst($attribs['VALUE']),
  398 + $this->logger->getLevel()
  399 + )
  400 + );
  401 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL root level is now '{$attribs['VALUE']}' ");
  402 + break;
  403 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE:
  404 + $this->logger->setLevel(
  405 + LoggerOptionConverter::toLevel(
  406 + $this->subst($attribs['VALUE']),
  407 + $this->logger->getLevel()
  408 + )
  409 + );
  410 + break;
  411 + default:
  412 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LEVEL state '{$this->state}' not allowed here");
  413 + }
  414 + break;
  415 +
  416 + case 'PARAM':
  417 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':PARAM':
  418 +
  419 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() PARAM");
  420 +
  421 + if (!isset($attribs['NAME'])) {
  422 + LoggerLog::warn(
  423 + "LoggerDOMConfigurator::tagOpen() PARAM. ".
  424 + "attribute 'name' not defined."
  425 + );
  426 + break;
  427 + }
  428 + if (!isset($attribs['VALUE'])) {
  429 + LoggerLog::warn(
  430 + "LoggerDOMConfigurator::tagOpen() PARAM. ".
  431 + "attribute 'value' not defined."
  432 + );
  433 + break;
  434 + }
  435 +
  436 + switch (end($this->state)) {
  437 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_APPENDER_STATE:
  438 + if ($this->appender !== null) {
  439 + $this->setter($this->appender, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE']));
  440 + } else {
  441 + LoggerLog::warn(
  442 + "LoggerDOMConfigurator::tagOpen() PARAM. ".
  443 + " trying to set property to a null appender."
  444 + );
  445 + }
  446 + break;
  447 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_LAYOUT_STATE:
  448 + if ($this->layout !== null) {
  449 + $this->setter($this->layout, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE']));
  450 + } else {
  451 + LoggerLog::warn(
  452 + "LoggerDOMConfigurator::tagOpen() PARAM. ".
  453 + " trying to set property to a null layout."
  454 + );
  455 + }
  456 + break;
  457 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_FILTER_STATE:
  458 + if ($this->filter !== null) {
  459 + $this->setter($this->filter, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE']));
  460 + } else {
  461 + LoggerLog::warn(
  462 + "LoggerDOMConfigurator::tagOpen() PARAM. ".
  463 + " trying to set property to a null filter."
  464 + );
  465 + }
  466 + break;
  467 + default:
  468 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM state '{$this->state}' not allowed here");
  469 + }
  470 + break;
  471 +
  472 + case 'RENDERER':
  473 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':RENDERER':
  474 +
  475 + $renderedClass = $this->subst(@$attribs['RENDEREDCLASS']);
  476 + $renderingClass = $this->subst(@$attribs['RENDERINGCLASS']);
  477 +
  478 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() RENDERER renderedClass='$renderedClass' renderingClass='$renderingClass'");
  479 +
  480 + if (!empty($renderedClass) and !empty($renderingClass)) {
  481 + $renderer = LoggerObjectRenderer::factory($renderingClass);
  482 + if ($renderer === null) {
  483 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() RENDERER cannot instantiate '$renderingClass'");
  484 + } else {
  485 + $this->repository->setRenderer($renderedClass, $renderer);
  486 + }
  487 + } else {
  488 + LoggerLog::warn("LoggerDOMConfigurator::tagOpen() RENDERER renderedClass or renderingClass is empty");
  489 + }
  490 + break;
  491 +
  492 + case 'ROOT':
  493 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':ROOT':
  494 +
  495 + LoggerLog::debug("LoggerDOMConfigurator::tagOpen() ROOT");
  496 +
  497 + $this->logger =& LoggerManager::getRootLogger();
  498 +
  499 + $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE;
  500 + break;
  501 +
  502 + }
  503 +
  504 + }
  505 +
  506 +
  507 + /**
  508 + * @param mixed $parser
  509 + * @param string $tag
  510 + */
  511 + function tagClose($parser, $tag)
  512 + {
  513 + switch ($tag) {
  514 +
  515 + case 'CONFIGURATION' :
  516 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':CONFIGURATION':
  517 +
  518 + LoggerLog::debug("LoggerDOMConfigurator::tagClose() CONFIGURATION");
  519 + break;
  520 +
  521 + case 'APPENDER' :
  522 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':APPENDER':
  523 +
  524 + LoggerLog::debug("LoggerDOMConfigurator::tagClose() APPENDER");
  525 +
  526 + if ($this->appender !== null) {
  527 + if ($this->appender->requiresLayout() and $this->appender->getLayout() === null) {
  528 + $appenderName = $this->appender->getName();
  529 + LoggerLog::warn(
  530 + "LoggerDOMConfigurator::tagClose() APPENDER. ".
  531 + "'$appenderName' requires a layout that is not defined. ".
  532 + "Using a simple layout"
  533 + );
  534 + $this->appender->setLayout(LoggerLayout::factory('LoggerLayoutSimple'));
  535 + }
  536 + $this->appender->activateOptions();
  537 + }
  538 + array_pop($this->state);
  539 + break;
  540 +
  541 + case 'FILTER' :
  542 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':FILTER':
  543 +
  544 + LoggerLog::debug("LoggerDOMConfigurator::tagClose() FILTER");
  545 +
  546 + if ($this->filter !== null) {
  547 + $this->filter->activateOptions();
  548 + $this->appender->addFilter($this->filter);
  549 + $this->filter = null;
  550 + }
  551 + array_pop($this->state);
  552 + break;
  553 +
  554 + case 'LAYOUT':
  555 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':LAYOUT':
  556 +
  557 + LoggerLog::debug("LoggerDOMConfigurator::tagClose() LAYOUT");
  558 +
  559 + if ($this->appender !== null and $this->layout !== null and $this->appender->requiresLayout()) {
  560 + $this->layout->activateOptions();
  561 + $this->appender->setLayout($this->layout);
  562 + $this->layout = null;
  563 + }
  564 + array_pop($this->state);
  565 + break;
  566 +
  567 + case 'LOGGER':
  568 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':LOGGER':
  569 +
  570 + LoggerLog::debug("LoggerDOMConfigurator::tagClose() LOGGER");
  571 +
  572 + array_pop($this->state);
  573 + break;
  574 +
  575 + case 'ROOT':
  576 + case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS.':ROOT':
  577 +
  578 + LoggerLog::debug("LoggerDOMConfigurator::tagClose() ROOT");
  579 +
  580 + array_pop($this->state);
  581 + break;
  582 + }
  583 + }
  584 +
  585 + /**
  586 + * @param object $object
  587 + * @param string $name
  588 + * @param mixed $value
  589 + */
  590 + function setter(&$object, $name, $value)
  591 + {
  592 + if (empty($name)) {
  593 + LoggerLog::debug("LoggerDOMConfigurator::setter() 'name' param cannot be empty");
  594 + return false;
  595 + }
  596 + $methodName = 'set'.ucfirst($name);
  597 + if (method_exists($object, $methodName)) {
  598 + LoggerLog::debug("LoggerDOMConfigurator::setter() Calling ".get_class($object)."::{$methodName}({$value})");
  599 + return call_user_func(array(&$object, $methodName), $value);
  600 + } else {
  601 + LoggerLog::warn("LoggerDOMConfigurator::setter() ".get_class($object)."::{$methodName}() does not exists");
  602 + return false;
  603 + }
  604 + }
  605 +
  606 + function subst($value)
  607 + {
  608 + return LoggerOptionConverter::substVars($value);
  609 + }
  610 +
  611 +}
... ...
thirdparty/apache-log4php/src/main/php/xml/log4php.dtd 0 โ†’ 100644
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!--
  3 + Licensed to the Apache Software Foundation (ASF) under one or more
  4 + contributor license agreements. See the NOTICE file distributed with
  5 + this work for additional information regarding copyright ownership.
  6 + The ASF licenses this file to You under the Apache License, Version 2.0
  7 + (the "License"); you may not use this file except in compliance with
  8 + the License. You may obtain a copy of the License at
  9 +
  10 + http://www.apache.org/licenses/LICENSE-2.0
  11 +
  12 + Unless required by applicable law or agreed to in writing, software
  13 + distributed under the License is distributed on an "AS IS" BASIS,
  14 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 + See the License for the specific language governing permissions and
  16 + limitations under the License.
  17 + -->
  18 +<!-- Authors: Chris Taylor, Ceki Gulcu. -->
  19 +<!-- Version: 1.2 -->
  20 +
  21 +<!-- PHP Port Modifications Author: Marco Vassura -->
  22 +<!-- PHP dtd Version: $Revision: 609441 $ -->
  23 +
  24 +<!-- A configuration element consists of optional renderer
  25 +elements,appender elements, categories and an optional root
  26 +element. -->
  27 +
  28 +<!ELEMENT configuration (renderer*, appender*,(category|logger)*,root?,
  29 + categoryFactory?)>
  30 +
  31 +<!-- The "threshold" attribute takes a level value such that all -->
  32 +<!-- logging statements with a level equal or below this value are -->
  33 +<!-- disabled. -->
  34 +
  35 +<!-- Setting the "debug" enable the printing of internal log4j logging -->
  36 +<!-- statements. -->
  37 +
  38 +<!-- By default, debug attribute is "null", meaning that we not do touch -->
  39 +<!-- internal log4j logging settings. The "null" value for the threshold -->
  40 +<!-- attribute can be misleading. The threshold field of a repository -->
  41 +<!-- cannot be set to null. The "null" value for the threshold attribute -->
  42 +<!-- simply means don't touch the threshold field, the threshold field -->
  43 +<!-- keeps its old value. -->
  44 +<!-- [loh4php] -->
  45 +<!-- the "null" value in debug means "turn off debugging" -->
  46 +<!-- [/log4php] -->
  47 +
  48 +<!ATTLIST configuration
  49 + xmlns:log4php CDATA #FIXED "http://www.vxr.it/log4php/"
  50 + threshold (all|debug|info|warn|error|fatal|off|null) "null"
  51 + debug (true|false|null) "null"
  52 +>
  53 +
  54 +<!-- renderer elements allow the user to customize the conversion of -->
  55 +<!-- message objects to String. -->
  56 +<!ELEMENT renderer EMPTY>
  57 +<!ATTLIST renderer
  58 + renderedClass CDATA #REQUIRED
  59 + renderingClass CDATA #REQUIRED
  60 +>
  61 +
  62 +<!-- Appenders must have a name and a class. -->
  63 +<!-- Appenders may contain an error handler, a layout, optional parameters -->
  64 +<!-- and filters. They may also reference (or include) other appenders. -->
  65 +<!-- [log4php] -->
  66 +<!-- error handler tag has no effects since log4php does not handle errors. -->
  67 +<!-- [/log4php] -->
  68 +<!ELEMENT appender (errorHandler?, param*, layout?, filter*, appender-ref*)>
  69 +<!ATTLIST appender
  70 + name ID #REQUIRED
  71 + class CDATA #REQUIRED
  72 +>
  73 +
  74 +<!ELEMENT layout (param*)>
  75 +<!ATTLIST layout
  76 + class CDATA #REQUIRED
  77 +>
  78 +
  79 +<!ELEMENT filter (param*)>
  80 +<!ATTLIST filter
  81 + class CDATA #REQUIRED
  82 +>
  83 +
  84 +<!ELEMENT param EMPTY>
  85 +<!ATTLIST param
  86 + name CDATA #REQUIRED
  87 + value CDATA #REQUIRED
  88 +>
  89 +
  90 +<!ELEMENT priority EMPTY>
  91 +<!ATTLIST priority
  92 + value CDATA #REQUIRED
  93 +>
  94 +
  95 +<!ELEMENT level EMPTY>
  96 +<!ATTLIST level
  97 + value CDATA #REQUIRED
  98 +>
  99 +
  100 +<!-- If no level element is specified, then the configurator MUST not -->
  101 +<!-- touch the level of the named logger. -->
  102 +<!ELEMENT logger (level?,appender-ref*)>
  103 +<!ATTLIST logger
  104 + name ID #REQUIRED
  105 + additivity (true|false) "true"
  106 +>
  107 +
  108 +<!ELEMENT appender-ref EMPTY>
  109 +<!ATTLIST appender-ref
  110 + ref IDREF #REQUIRED
  111 +>
  112 +
  113 +<!-- If no priority element is specified, then the configurator MUST not -->
  114 +<!-- touch the priority of root. -->
  115 +<!-- The root category always exists and cannot be subclassed. -->
  116 +<!ELEMENT root (param*, (priority|level)?, appender-ref*)>
  117 +
  118 +
  119 +<!-- ==================================================================== -->
  120 +<!-- A logging event -->
  121 +<!-- ==================================================================== -->
  122 +<!ELEMENT log4php:eventSet (log4php:event*)>
  123 +<!ATTLIST log4php:eventSet
  124 + xmlns:log4php CDATA #FIXED "http://www.vxr.it/log4php/"
  125 + version (0.2|0.3) "0.3"
  126 + includesLocationInfo (true|false) "true"
  127 +>
  128 +
  129 +<!ELEMENT log4php:event (log4php:message, log4php:locationInfo?) >
  130 +
  131 +<!-- The timestamp format is application dependent. -->
  132 +<!ATTLIST log4php:event
  133 + logger CDATA #REQUIRED
  134 + level CDATA #REQUIRED
  135 + thread CDATA #REQUIRED
  136 + timestamp CDATA #REQUIRED
  137 +>
  138 +
  139 +<!ELEMENT log4php:message (#PCDATA)>
  140 +<!ELEMENT log4php:NDC (#PCDATA)>
  141 +
  142 +<!ELEMENT log4php:locationInfo EMPTY>
  143 +<!ATTLIST log4php:locationInfo
  144 + class CDATA #REQUIRED
  145 + method CDATA #REQUIRED
  146 + file CDATA #REQUIRED
  147 + line CDATA #REQUIRED
  148 +>
... ...