You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ih...@apache.org on 2012/08/18 12:22:19 UTC
svn commit: r1374546 -
/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php
Author: ihabunek
Date: Sat Aug 18 10:22:19 2012
New Revision: 1374546
URL: http://svn.apache.org/viewvc?rev=1374546&view=rev
Log:
LoggerAppenderPDO: Fixed reconnect logic.
Modified:
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php?rev=1374546&r1=1374545&r2=1374546&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php Sat Aug 18 10:22:19 2012
@@ -119,7 +119,7 @@ class LoggerAppenderPDO extends LoggerAp
try {
$this->establishConnection();
} catch (PDOException $e) {
- $this->warn("Failed connecting to database: " . $e->getMessage());
+ $this->warn("Failed connecting to database. Closing appender. Error: " . $e->getMessage());
$this->close();
return;
}
@@ -157,27 +157,24 @@ class LoggerAppenderPDO extends LoggerAp
* the appender will close.
*/
public function append(LoggerLoggingEvent $event) {
-
- for ($attempt = 1; $attempt <= $this->reconnectAttempts; $attempt++) {
+
+ for ($attempt = 1; $attempt <= $this->reconnectAttempts + 1; $attempt++) {
try {
- // If it's a retry, reestablish the connection
- if ($attempt > 1) {
- $this->establishConnection();
- }
-
- // Write to database
- @$this->preparedInsert->execute($this->format($event));
- @$this->preparedInsert->closeCursor();
+ // Attempt to write to database
+ $this->preparedInsert->execute($this->format($event));
+ $this->preparedInsert->closeCursor();
break;
} catch (PDOException $e) {
$this->warn("Failed writing to database: ". $e->getMessage());
// Close the appender if it's the last attempt
- if ($attempt == $this->reconnectAttempts) {
- $this->warn("Failed after {$this->reconnectAttempts} attempts. Closing appender.");
+ if ($attempt > $this->reconnectAttempts) {
+ $this->warn("Failed writing to database after {$this->reconnectAttempts} reconnect attempts. Closing appender.");
$this->close();
+ // Otherwise reconnect and try to write again
} else {
$this->warn("Attempting a reconnect (attempt $attempt of {$this->reconnectAttempts}).");
+ $this->establishConnection();
}
}
}