123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
- require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
- require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php');
- require_once(LOG4PHP_DIR . '/LoggerLog.php');
- class LoggerAppenderFile extends LoggerAppenderSkeleton {
-
- var $append = true;
-
- var $fileName;
-
- var $fp = false;
-
-
- var $requiresLayout = true;
-
-
- function LoggerAppenderFile($name)
- {
- $this->LoggerAppenderSkeleton($name);
- }
- function activateOptions()
- {
- $fileName = $this->getFile();
- LoggerLog::debug("LoggerAppenderFile::activateOptions() opening file '{$fileName}'");
- $this->fp = @fopen($fileName, ($this->getAppend()? 'a':'w'));
- if ($this->fp) {
- if ($this->getAppend())
- fseek($this->fp, 0, SEEK_END);
- @fwrite($this->fp, $this->layout->getHeader());
- $this->closed = false;
- } else {
- $this->closed = true;
- }
- }
-
- function close()
- {
- if ($this->fp and $this->layout !== null)
- @fwrite($this->fp, $this->layout->getFooter());
-
- $this->closeFile();
- $this->closed = true;
- }
-
- function closeFile()
- {
- if ($this->fp)
- @fclose($this->fp);
- }
-
-
- function getAppend()
- {
- return $this->append;
- }
-
- function getFile()
- {
- return $this->getFileName();
- }
-
-
- function getFileName()
- {
- return $this->fileName;
- }
-
-
- function reset()
- {
- $this->closeFile();
- $this->fileName = null;
- parent::reset();
- }
- function setAppend($flag)
- {
- $this->append = LoggerOptionConverter::toBoolean($flag, true);
- }
-
-
- function setFile()
- {
- $numargs = func_num_args();
- $args = func_get_args();
- if ($numargs == 1 and is_string($args[0])) {
- $this->setFileName($args[0]);
- } elseif ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) {
- $this->setFile($args[0]);
- $this->setAppend($args[1]);
- }
- }
-
- function setFileName($fileName)
- {
- $this->fileName = $fileName;
- }
- function append($event)
- {
- if ($this->fp and $this->layout !== null) {
- LoggerLog::debug("LoggerAppenderFile::append()");
-
- @fwrite($this->fp, $this->layout->format($event));
- }
- }
- }
- ?>
|