scala.util.control.Breaks Scala Examples
The following examples show how to use scala.util.control.Breaks.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: LogStationColorizer.scala From logstation with Apache License 2.0 | 5 votes |
package com.jdrews.logstation.utils import akka.actor.{Actor, ActorLogging, Terminated} import com.jdrews.logstation.config.BridgeController import com.jdrews.logstation.service.ServiceShutdown import com.jdrews.logstation.webserver.LogMessage import scala.util.control.Breaks import scala.util.matching.Regex class LogStationColorizer extends Actor with ActorLogging { // contains a map of syntaxName to regular expression. var syntaxList = scala.collection.mutable.Map[String, Regex]() private val bridge = BridgeController.getBridgeActor def receive = { case syntax: scala.collection.mutable.Map[String, Regex] => log.debug(s"Got config $syntax}") // load up the syntaxes syntaxList = syntax case lm: LogMessage => var msg = lm.logMessage // colorize it! val loop = new Breaks loop.breakable { // for each syntax in list syntaxList.foreach(syntax => // get the first syntax regex, and find the first one to match the log message if (syntax._2.findFirstIn(lm.logMessage).isDefined) { // log.debug(s"got a match! ${syntax._1}") // wrap log message in new colors msg = s"<span style='color:${syntax._1}'>${xml.Utility.escape(lm.logMessage)}</span>" loop.break } ) } // send it to bridge actor bridge ! LogMessage(msg, lm.logFile) case ServiceShutdown => context stop self case actTerminated: Terminated => log.info(actTerminated.toString) case something => log.warning(s"huh? $something") } }