Skip to content

Commit

Permalink
util,finagle-core: Improve toStrings
Browse files Browse the repository at this point in the history
Problem / Solution

There are a variety of commonly used classes and defaults that end up
in the runtime registry which do not have a good `toString`
implementation.

RB_ID=880664
  • Loading branch information
kevinoliver authored and jenkins committed Oct 17, 2016
1 parent 1fa401a commit fc21480
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions util-core/src/main/scala/com/twitter/util/Monitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import java.util.logging.{Level, Logger}
* a monitor.
*/
case class MonitorException(
handlingExc: Throwable,
monitorExc: Throwable
) extends Exception(monitorExc) {
override def getMessage =
handlingExc: Throwable,
monitorExc: Throwable)
extends Exception(monitorExc) {
override def getMessage: String =
"threw exception \""+monitorExc+"\" while handling "+
"another exception \""+handlingExc+"\""
}
Expand Down Expand Up @@ -165,17 +165,19 @@ object Monitor extends Monitor {
* removing NullMonitor from the chain.
*/
object NullMonitor extends Monitor {
def handle(exc: Throwable) = false
override def orElse(next: Monitor) = next
override def andThen(next: Monitor) = next
def handle(exc: Throwable): Boolean = false
override def orElse(next: Monitor): Monitor = next
override def andThen(next: Monitor): Monitor = next

def getInstance: Monitor = this

override def toString: String = "NullMonitor"
}

object RootMonitor extends Monitor {
private[this] val log = Logger.getLogger("monitor")

def handle(exc: Throwable) = exc match {
def handle(exc: Throwable): Boolean = exc match {
case NonFatal(e) =>
log.log(Level.SEVERE, "Exception propagated to the root monitor!", e)
true /* Never propagate non fatal exception */
Expand Down

0 comments on commit fc21480

Please sign in to comment.