[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /** 3 * log4php is a PHP port of the log4j java logging package. 4 * 5 * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p> 6 * <p>Design, strategies and part of the methods documentation are developed by log4j team 7 * (Ceki Gülcü as log4j project founder and 8 * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p> 9 * 10 * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br> 11 * For more information, please see {@link http://www.vxr.it/log4php/}.</p> 12 * 13 * <p>This software is published under the terms of the LGPL License 14 * a copy of which has been included with this distribution in the LICENSE file.</p> 15 * 16 * @package log4php 17 * @subpackage appenders 18 */ 19 20 /** 21 * @ignore 22 */ 23 if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); 24 25 require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); 26 require_once (LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); 27 require_once (LOG4PHP_DIR . '/LoggerLog.php'); 28 29 /** 30 * FileAppender appends log events to a file. 31 * 32 * Parameters are ({@link $fileName} but option name is <b>file</b>), 33 * {@link $append}. 34 * 35 * @author VxR <vxr@vxr.it> 36 * @version $Revision: 1.15 $ 37 * @package log4php 38 * @subpackage appenders 39 */ 40 class LoggerAppenderFile extends LoggerAppenderSkeleton { 41 42 /** 43 * @var boolean if {@link $file} exists, appends events. 44 */ 45 var $append = true; 46 47 /** 48 * @var string the file name used to append events 49 */ 50 var $fileName; 51 52 /** 53 * @var mixed file resource 54 * @access private 55 */ 56 var $fp = false; 57 58 /** 59 * @access private 60 */ 61 var $requiresLayout = true; 62 63 /** 64 * Constructor. 65 * 66 * @param string $name appender name 67 */ 68 function LoggerAppenderFile($name) 69 { 70 $this->LoggerAppenderSkeleton($name); 71 } 72 73 function activateOptions() 74 { 75 $fileName = $this->getFile(); 76 LoggerLog::debug("LoggerAppenderFile::activateOptions() opening file '{$fileName}'"); 77 $this->fp = @fopen($fileName, ($this->getAppend()? 'a':'w')); 78 79 // Denying read option for log file. Added for Vulnerability fix 80 if (is_readable($fileName)) chmod ($fileName,0222); 81 82 if ($this->fp) { 83 if ($this->getAppend()) 84 fseek($this->fp, 0, SEEK_END); 85 @fwrite($this->fp, $this->layout->getHeader()); 86 $this->closed = false; 87 } else { 88 $this->closed = true; 89 } 90 } 91 92 function close() 93 { 94 if ($this->fp and $this->layout !== null) 95 @fwrite($this->fp, $this->layout->getFooter()); 96 97 $this->closeFile(); 98 $this->closed = true; 99 } 100 101 /** 102 * Closes the previously opened file. 103 */ 104 function closeFile() 105 { 106 if ($this->fp) 107 @fclose($this->fp); 108 } 109 110 /** 111 * @return boolean 112 */ 113 function getAppend() 114 { 115 return $this->append; 116 } 117 118 /** 119 * @return string 120 */ 121 function getFile() 122 { 123 return $this->getFileName(); 124 } 125 126 /** 127 * @return string 128 */ 129 function getFileName() 130 { 131 return $this->fileName; 132 } 133 134 /** 135 * Close any previously opened file and call the parent's reset. 136 */ 137 function reset() 138 { 139 $this->closeFile(); 140 $this->fileName = null; 141 parent::reset(); 142 } 143 144 function setAppend($flag) 145 { 146 $this->append = LoggerOptionConverter::toBoolean($flag, true); 147 } 148 149 /** 150 * Sets and opens the file where the log output will go. 151 * 152 * This is an overloaded method. It can be called with: 153 * - setFile(string $fileName) to set filename. 154 * - setFile(string $fileName, boolean $append) to set filename and append. 155 */ 156 function setFile() 157 { 158 $numargs = func_num_args(); 159 $args = func_get_args(); 160 161 if ($numargs == 1 and is_string($args[0])) { 162 $this->setFileName($args[0]); 163 } elseif ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) { 164 $this->setFile($args[0]); 165 $this->setAppend($args[1]); 166 } 167 } 168 169 function setFileName($fileName) 170 { 171 $this->fileName = $fileName; 172 } 173 174 function append($event) 175 { 176 if ($this->fp and $this->layout !== null) { 177 178 LoggerLog::debug("LoggerAppenderFile::append()"); 179 180 @fwrite($this->fp, $this->layout->format($event)); 181 } 182 } 183 } 184 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |