Skip to content
Browse files

report errors to log rather than stderr

  • Loading branch information...
1 parent d1fc21b commit 1b5be243466871aeaf6c58276442443b44c7671f @freels freels committed Dec 1, 2011
View
8 querulous-core/src/main/scala/com/twitter/querulous/Timeout.scala
@@ -1,5 +1,6 @@
package com.twitter.querulous
+import java.util.logging.{Logger, Level}
import java.util.{Timer, TimerTask}
import com.twitter.util.Duration
@@ -38,9 +39,10 @@ object Timeout {
try {
f
} catch {
- case e: Throwable =>
- System.err.println("Timeout task tried to throw an exception: " + e.toString())
- e.printStackTrace(System.err)
+ case e: Throwable => {
+ val l = Logger.getLogger("querulous")
+ l.log(Level.WARNING, "Timeout task tried to throw an exception", e)
+ }
}
}
}
View
22 querulous-core/src/main/scala/com/twitter/querulous/database/ThrottledPoolingDatabase.scala
@@ -1,5 +1,6 @@
package com.twitter.querulous.database
+import java.util.logging.{Logger, Level}
import java.util.concurrent.{TimeUnit, LinkedBlockingQueue}
import java.sql.{SQLException, DriverManager, Connection}
import org.apache.commons.dbcp.{PoolingDataSource, DelegatingConnection}
@@ -56,8 +57,10 @@ class ThrottledPool(factory: () => Connection, val size: Int, timeout: Duration,
try { for (i <- (0.until(size))) addObject() } catch {
// bail until the watchdog thread repopulates.
- case e: Throwable =>
- System.err.println(Time.now.format("yyyy-MM-dd HH:mm:ss Z") + ": Error initially populating pool "+name+": " + e)
+ case e: Throwable => {
+ val l = Logger.getLogger("querulous")
+ l.log(Level.WARNING, "Error initially populating pool "+name, e)
+ }
}
def addObject() {
@@ -160,16 +163,19 @@ class PoolWatchdogThread(
lastTimePoolPopulated = Time.now
pool.addObjectUnlessFull()
} catch {
- case t: Throwable => {
- System.err.println(Time.now.format("yyyy-MM-dd HH:mm:ss Z") + ": " +
- Thread.currentThread().getName() +
- " failed to add connection to the pool")
- t.printStackTrace(System.err)
- }
+ case t: Throwable => reportException(t)
}
}
}
+ def reportException(t: Throwable) {
+ val thread = Thread.currentThread().getName()
+ val errMsg = "%s: %s" format (t.getClass.getName, t.getMessage)
+
+ val l = Logger.getLogger("querulous")
+ l.log(Level.WARNING, "%s: Failed to add connection to the pool: %s" format (thread, errMsg), t)
+ }
+
// TODO: provide a reliable way to have this thread exit when shutdown is implemented
}

0 comments on commit 1b5be24

Please sign in to comment.
Something went wrong with that request. Please try again.