Created
April 2, 2011 21:07
-
-
Save fukata/899898 to your computer and use it in GitHub Desktop.
Date format files to rotate log4php appender.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- log4php-org/Logger.php 2010-07-27 03:21:18.705554189 +0900 | |
+++ log4php/Logger.php 2011-04-02 00:26:13.964032277 +0900 | |
@@ -77,6 +77,7 @@ | |
'LoggerAppenderMailEvent' => '/appenders/LoggerAppenderMailEvent.php', | |
'LoggerAppenderNull' => '/appenders/LoggerAppenderNull.php', | |
'LoggerAppenderPhp' => '/appenders/LoggerAppenderPhp.php', | |
+ 'LoggerAppenderRollingDailyFile' => '/appenders/LoggerAppenderRollingDailyFile.php', | |
'LoggerAppenderRollingFile' => '/appenders/LoggerAppenderRollingFile.php', | |
'LoggerAppenderSocket' => '/appenders/LoggerAppenderSocket.php', | |
'LoggerAppenderSyslog' => '/appenders/LoggerAppenderSyslog.php', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class LoggerAppenderRollingDailyFile extends LoggerAppenderDailyFile { | |
protected $_logFilePath = false; | |
protected $_nowDate = false; | |
public function setFile() { | |
$numargs = func_num_args(); | |
$args = func_get_args(); | |
if (!$this->_logFilePath && is_string($args[0])) { | |
$this->_logFilePath = $args[0]; | |
} | |
if($numargs == 1 and is_string($args[0])) { | |
parent::setFile( $args[0] ); | |
} else if ($numargs == 2 and is_string($args[0]) and is_bool($args[1])) { | |
parent::setFile( $args[0], $args[1] ); | |
} | |
} | |
private function updateFile() { | |
$_now = date($this->datePattern); | |
if ($_now != $this->_nowDate) { | |
$this->_nowDate = $_now; | |
$this->setFile($this->_logFilePath); | |
$this->close(); | |
$this->activateOptions(); | |
} | |
} | |
/** | |
* @param LoggerLoggingEvent $event | |
*/ | |
public function append(LoggerLoggingEvent $event) { | |
$this->updateFile(); | |
parent::append($event); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment