Changeset 4898 for OpenPNE/trunk
- Timestamp:
- Jan 10, 2008, 7:41:07 PM (15 years ago)
- Location:
- OpenPNE/trunk/lib/include
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE/trunk/lib/include/Log.php
r2 r4898 1 1 <?php 2 2 /** 3 * $Header: /repository/pear/Log/Log.php,v 1.6 3 2006/05/23 05:59:58jon Exp $3 * $Header: /repository/pear/Log/Log.php,v 1.67 2007/12/13 06:46:30 jon Exp $ 4 4 * $Horde: horde/lib/Log.php,v 1.15 2000/06/29 23:39:45 jon Exp $ 5 5 * 6 * @version $Revision: 1.6 3$6 * @version $Revision: 1.67 $ 7 7 * @package Log 8 8 */ … … 41 41 * 42 42 * @var boolean 43 * @access pr ivate43 * @access protected 44 44 */ 45 45 var $_opened = false; … … 49 49 * 50 50 * @var integer 51 * @access pr ivate51 * @access protected 52 52 */ 53 53 var $_id = 0; … … 57 57 * 58 58 * @var string 59 * @access pr ivate59 * @access protected 60 60 */ 61 61 var $_ident = ''; … … 65 65 * 66 66 * @var integer 67 * @access pr ivate67 * @access protected 68 68 */ 69 69 var $_priority = PEAR_LOG_INFO; … … 73 73 * 74 74 * @var integer 75 * @access pr ivate75 * @access protected 76 76 */ 77 77 var $_mask = PEAR_LOG_ALL; … … 81 81 * 82 82 * @var array 83 * @access pr ivate83 * @access protected 84 84 */ 85 85 var $_listeners = array(); … … 90 90 * 91 91 * @var array 92 * @access pr ivate92 * @access protected 93 93 */ 94 94 var $_formatMap = array('%{timestamp}' => '%1$s', … … 101 101 '%\{' => '%%{'); 102 102 103 /** 104 * Utility function which wraps PHP's class_exists() function to ensure 105 * consistent behavior between PHP versions 4 and 5. Autoloading behavior 106 * is always disabled. 107 * 108 * @param string $class The name of the class whose existence should 109 * be tested. 110 * 111 * @return bool True if the class exists. 112 * 113 * @access private 114 * @since Log 1.9.13 115 */ 116 function _classExists($class) 117 { 118 if (version_compare(PHP_VERSION, '5.0.0', 'ge')) { 119 return class_exists($class, false); 120 } 121 122 return class_exists($class); 123 } 103 124 104 125 /** … … 139 160 * version of the named class. 140 161 */ 141 if (! class_exists($class)) {162 if (!Log::_classExists($class)) { 142 163 include_once $classfile; 143 164 } 144 165 145 166 /* If the class exists, return a new instance of it. */ 146 if ( class_exists($class)) {167 if (Log::_classExists($class)) { 147 168 $obj = &new $class($name, $ident, $conf, $level); 148 169 return $obj; … … 391 412 * @return string The string representation of the message. 392 413 * 393 * @access pr ivate414 * @access protected 394 415 */ 395 416 function _extractMessage($message) … … 494 515 * @return string Formatted log string. 495 516 * 496 * @access pr ivate517 * @access protected 497 518 * @since Log 1.9.4 498 519 */ … … 503 524 * variables (%5, %6, %7), generate the backtrace and fetch them. 504 525 */ 505 if ( preg_match('/%[567]/', $format)) {526 if (strpos($format, '%5') || strpos($format, '%6') || strpos($format, '%7')) { 506 527 list($file, $line, $func) = $this->_getBacktraceVars(2); 507 528 } … … 529 550 * @return string The string representation of $level. 530 551 * 552 * @access public 531 553 * @since Log 1.0 532 554 */ … … 557 579 * the the specified priority name. 558 580 * 581 * @access public 559 582 * @since Log 1.9.0 560 583 */ … … 687 710 * log mask. 688 711 * 689 * @access pr ivate712 * @access protected 690 713 * @since Log 1.7.0 691 714 */ … … 773 796 * @param array $event A hash describing the log event. 774 797 * 775 * @access pr ivate798 * @access protected 776 799 */ 777 800 function _announce($event) -
OpenPNE/trunk/lib/include/Log/console.php
r2 r4898 1 1 <?php 2 2 /** 3 * $Header: /repository/pear/Log/Log/console.php,v 1.2 3 2006/06/29 07:09:21jon Exp $3 * $Header: /repository/pear/Log/Log/console.php,v 1.24 2006/12/07 04:15:02 jon Exp $ 4 4 * 5 * @version $Revision: 1.2 3$5 * @version $Revision: 1.24 $ 6 6 * @package Log 7 7 */ … … 151 151 } 152 152 153 return fflush($this->_stream); 153 if (is_resource($this->_stream)) { 154 return fflush($this->_stream); 155 } 156 157 return false; 154 158 } 155 159 -
OpenPNE/trunk/lib/include/Log/display.php
r2 r4898 1 1 <?php 2 2 /** 3 * $Header: /repository/pear/Log/Log/display.php,v 1. 9 2006/06/29 07:09:21jon Exp $3 * $Header: /repository/pear/Log/Log/display.php,v 1.10 2007/12/30 00:49:04 jon Exp $ 4 4 * 5 * @version $Revision: 1. 9$5 * @version $Revision: 1.10 $ 6 6 * @package Log 7 7 */ … … 23 23 { 24 24 /** 25 * String to output before an error message25 * String containing the format of a log line. 26 26 * @var string 27 27 * @access private 28 28 */ 29 var $_ error_prepend = '';29 var $_lineFormat = '<b>%3$s</b>: %4$s'; 30 30 31 31 /** 32 * String to output after an error message 32 * String containing the timestamp format. It will be passed directly to 33 * strftime(). Note that the timestamp string will generated using the 34 * current locale. 33 35 * @var string 34 36 * @access private 35 37 */ 36 var $_error_append = ''; 37 38 /** 39 * String used to represent a line break. 40 * @var string 41 * @access private 42 */ 43 var $_linebreak = "<br />\n"; 38 var $_timeFormat = '%b %d %H:%M:%S'; 44 39 45 40 /** … … 59 54 $this->_mask = Log::UPTO($level); 60 55 61 if (isset($conf['error_prepend'])) { 62 $this->_error_prepend = $conf['error_prepend']; 63 } else { 64 $this->_error_prepend = ini_get('error_prepend_string'); 56 /* Start by configuring the line format. */ 57 if (!empty($conf['lineFormat'])) { 58 $this->_lineFormat = str_replace(array_keys($this->_formatMap), 59 array_values($this->_formatMap), 60 $conf['lineFormat']); 65 61 } 66 62 67 if (isset($conf['error_append'])) { 68 $this->_error_append = $conf['error_append']; 63 /* We may need to prepend a string to our line format. */ 64 $prepend = null; 65 if (isset($conf['error_prepend'])) { 66 $prepend = $conf['error_prepend']; 69 67 } else { 70 $this->_error_append = ini_get('error_append_string'); 68 $prepend = ini_get('error_prepend_string'); 69 } 70 if (!empty($prepend)) { 71 $this->_lineFormat = $prepend . $this->_lineFormat; 71 72 } 72 73 74 /* We may also need to append a string to our line format. */ 75 $append = null; 76 if (isset($conf['error_append'])) { 77 $append = $conf['error_append']; 78 } else { 79 $append = ini_get('error_append_string'); 80 } 81 if (!empty($append)) { 82 $this->_lineFormat .= $append; 83 } 84 85 /* Lastly, the line ending sequence is also configurable. */ 73 86 if (isset($conf['linebreak'])) { 74 $this->_linebreak = $conf['linebreak']; 87 $this->_lineFormat .= $conf['linebreak']; 88 } 89 90 /* The user can also change the time format. */ 91 if (!empty($conf['timeFormat'])) { 92 $this->_timeFormat = $conf['timeFormat']; 75 93 } 76 94 } … … 128 146 129 147 /* Build and output the complete log line. */ 130 echo $this->_ error_prepend .131 '<b>' . ucfirst($this->priorityToString($priority)) . '</b>: '.132 nl2br(htmlspecialchars($message)) .133 $this->_error_append . $this->_linebreak;148 echo $this->_format($this->_lineFormat, 149 strftime($this->_timeFormat), 150 $priority, 151 nl2br(htmlspecialchars($message))); 134 152 135 153 /* Notify observers about this log message. */ -
OpenPNE/trunk/lib/include/Log/file.php
r2 r4898 1 1 <?php 2 2 /** 3 * $Header: /repository/pear/Log/Log/file.php,v 1.4 5 2006/01/11 07:56:37jon Exp $3 * $Header: /repository/pear/Log/Log/file.php,v 1.46 2006/12/07 04:15:02 jon Exp $ 4 4 * 5 * @version $Revision: 1.4 5$5 * @version $Revision: 1.46 $ 6 6 * @package Log 7 7 */ … … 251 251 function flush() 252 252 { 253 return fflush($this->_fp); 253 if (is_resource($this->_fp)) { 254 return fflush($this->_fp); 255 } 256 257 return false; 254 258 } 255 259 -
OpenPNE/trunk/lib/include/Log/mail.php
r2 r4898 1 1 <?php 2 2 /** 3 * $Header: /repository/pear/Log/Log/mail.php,v 1.2 4 2006/01/30 05:37:18jon Exp $4 * 5 * @version $Revision: 1.2 4$3 * $Header: /repository/pear/Log/Log/mail.php,v 1.26 2006/12/18 00:53:02 jon Exp $ 4 * 5 * @version $Revision: 1.26 $ 6 6 * @package Log 7 7 */ … … 29 29 { 30 30 /** 31 * String holding the recipient's email address. 32 * @var string 33 * @access private 34 */ 35 var $_recipient = ''; 31 * String holding the recipients' email addresses. Multiple addresses 32 * should be separated with commas. 33 * @var string 34 * @access private 35 */ 36 var $_recipients = ''; 36 37 37 38 /** … … 79 80 var $_message = ''; 80 81 82 /** 83 * Flag used to indicated that log lines have been written to the message 84 * body and the message should be sent on close(). 85 * @var boolean 86 * @access private 87 */ 88 var $_shouldSend = false; 81 89 82 90 /** … … 87 95 * $conf['subject'] : the mail's "Subject" line. 88 96 * 89 * @param string $name The filename of the logfile.97 * @param string $name The message's recipients. 90 98 * @param string $ident The identity string. 91 99 * @param array $conf The configuration array. … … 97 105 { 98 106 $this->_id = md5(microtime()); 99 $this->_recipient = $name;107 $this->_recipients = $name; 100 108 $this->_ident = $ident; 101 109 $this->_mask = Log::UPTO($level); … … 152 160 } 153 161 $this->_opened = true; 162 $_shouldSend = false; 154 163 } 155 164 … … 166 175 { 167 176 if ($this->_opened) { 168 if ( !empty($this->_message)) {177 if ($this->_shouldSend && !empty($this->_message)) { 169 178 $headers = "From: $this->_from\r\n"; 170 179 $headers .= "User-Agent: Log_mail"; 171 180 172 if (mail($this->_recipient , $this->_subject, $this->_message,181 if (mail($this->_recipients, $this->_subject, $this->_message, 173 182 $headers) == false) { 174 183 error_log("Log_mail: Failure executing mail()", 0); … … 178 187 /* Clear the message string now that the email has been sent. */ 179 188 $this->_message = ''; 189 $this->_shouldSend = false; 180 190 } 181 191 $this->_opened = false; … … 234 244 $message = $this->_extractMessage($message); 235 245 236 /* Build the string containing the complete log line. */246 /* Append the string containing the complete log line. */ 237 247 $this->_message .= $this->_format($this->_lineFormat, 238 248 strftime($this->_timeFormat), 239 249 $priority, $message) . "\r\n"; 250 $this->_shouldSend = true; 240 251 241 252 /* Notify observers about this log message. */ -
OpenPNE/trunk/lib/include/Log/sql.php
r2 r4898 1 1 <?php 2 2 /** 3 * $Header: /repository/pear/Log/Log/sql.php,v 1.4 0 2006/01/03 04:12:45jon Exp $3 * $Header: /repository/pear/Log/Log/sql.php,v 1.41 2007/12/23 20:30:23 jon Exp $ 4 4 * $Horde: horde/lib/Log/sql.php,v 1.12 2000/08/16 20:27:34 chuck Exp $ 5 5 * 6 * @version $Revision: 1.4 0$6 * @version $Revision: 1.41 $ 7 7 * @package Log 8 8 */ … … 126 126 127 127 /* Now that we have a table name, assign our SQL statement. */ 128 if (!empty($ this->_sql)) {128 if (!empty($conf['sql'])) { 129 129 $this->_sql = $conf['sql']; 130 130 } else { -
OpenPNE/trunk/lib/include/Log/syslog.php
r2 r4898 1 1 <?php 2 2 /** 3 * $Header: /repository/pear/Log/Log/syslog.php,v 1.2 3 2005/02/26 14:48:59 chagenbuExp $3 * $Header: /repository/pear/Log/Log/syslog.php,v 1.25 2007/01/29 05:09:07 jon Exp $ 4 4 * $Horde: horde/lib/Log/syslog.php,v 1.6 2000/06/28 21:36:13 jon Exp $ 5 5 * 6 * @version $Revision: 1.2 3$6 * @version $Revision: 1.25 $ 7 7 * @package Log 8 8 */ … … 14 14 * 15 15 * @author Chuck Hagenbuch <chuck@horde.org> 16 * @author Jon Parise <jon@php.net> 16 17 * @since Horde 1.3 17 18 * @since Log 1.0 … … 23 24 { 24 25 /** 25 * Integer holding the log facility to use.26 * @var string27 * @access private28 */26 * Integer holding the log facility to use. 27 * @var integer 28 * @access private 29 */ 29 30 var $_name = LOG_SYSLOG; 31 32 /** 33 * Should we inherit the current syslog connection for this process, or 34 * should we call openlog() to start a new syslog connection? 35 * @var boolean 36 * @access private 37 */ 38 var $_inherit = false; 30 39 31 40 /** … … 46 55 } 47 56 57 if (isset($conf['inherit'])) { 58 $this->_inherit = $conf['inherit']; 59 $this->_opened = $this->_inherit; 60 } 61 48 62 $this->_id = md5(microtime()); 49 63 $this->_name = $name; … … 60 74 { 61 75 if (!$this->_opened) { 62 openlog($this->_ident, LOG_PID, $this->_name); 63 $this->_opened = true; 76 $this->_opened = openlog($this->_ident, LOG_PID, $this->_name); 64 77 } 65 78 … … 73 86 function close() 74 87 { 75 if ($this->_opened ) {88 if ($this->_opened && !$this->_inherit) { 76 89 closelog(); 77 90 $this->_opened = false; 78 91 } 79 92 80 return ($this->_opened === false);93 return true; 81 94 } 82 95 … … 114 127 $message = $this->_extractMessage($message); 115 128 116 if (!syslog($this->_toSyslog($priority), $message)) { 129 /* Build a syslog priority value based on our current configuration. */ 130 $priority = $this->_toSyslog($priority); 131 if ($this->_inherit) { 132 $priority |= $this->_name; 133 } 134 135 if (!syslog($priority, $message)) { 117 136 return false; 118 137 }
Note: See TracChangeset
for help on using the changeset viewer.