Skip to content

Commit

Permalink
clean up some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrews committed May 30, 2016
1 parent 202e58a commit d10aac7
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
4 changes: 4 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<logger name="org.eclipse.jetty" level="INFO">
<appender-ref ref="STDOUT" />
</logger>

<logger name="net.liftweb.util.TimeHelpers" level="WARN">
<appender-ref ref="STDOUT" />
</logger>
</configuration>
5 changes: 3 additions & 2 deletions src/main/scala/com/jdrews/logstation/LogStation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ object LogStation extends App {
//filter through each config of syntax and convert into map
syntaxes.foreach(syntax => {
val matchList: java.util.ArrayList[String] = syntax.getValue().unwrapped().asInstanceOf[java.util.ArrayList[String]]
logger.info(matchList.toString)
logger.debug(matchList.toString)
syntaxList(matchList.get(0)) = matchList.get(1).r
})
}
logger.info(s"syntaxList: $syntaxList")
logger.debug(s"syntaxList: $syntaxList")

val maxLogLinesPerLog = {
if (conf.hasPath("logstation.maxLogLinesPerLog")) {
Expand Down Expand Up @@ -130,6 +130,7 @@ object LogStation extends App {
bw.write(DefaultConfigHolder.defaultConfig)
bw.close()
println("Please setup your logstation.conf located here: " + file.getAbsolutePath())
println("Then relaunch and logstation will be located at: http://127.0.0.1:" + webServerPort)
System.exit(0)
}
}
16 changes: 8 additions & 8 deletions src/main/scala/com/jdrews/logstation/config/BridgeActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ class BridgeActor extends Actor with ActorLogging {
private var msgs = new FixedList[Any](bufferLength)
def receive = {
case lift: LiftActor =>
log.info(s"received LiftActor: $lift")
log.debug(s"received LiftActor: $lift")
target = Some(lift)

// send LogStationWebServer the maxLogLinesPerLog
lift ! MaxLogLinesPerLog(maxLogLinesPerLog)

if (msgs.nonEmpty) {
log.info("sending out buffered msgs")
log.debug("sending out buffered msgs")
msgs.foreach{ m =>
log.info(s"passing the following to $lift: $m")
log.debug(s"passing the following to $lift: $m")
lift ! m
}
log.info("done")
log.debug("done")
}
case mll: MaxLogLinesPerLog =>
log.info(s"received maxLogLinesPerLog: $mll")
log.debug(s"received maxLogLinesPerLog: $mll")
maxLogLinesPerLog = mll.myVal
case bl: BufferLength =>
log.info(s"received bufferLength: $bl")
log.debug(s"received bufferLength: $bl")
bufferLength = bl.myVal
// rebuild msgs list with new buffer length
msgs = new FixedList[Any](bufferLength)
case msg =>
if (target.isEmpty) {
log.info(s"buffering this message since target is empty... $msg")
log.debug(s"buffering this message since target is empty... $msg")
msgs.append(msg)
} else {
log.info(s"passing the following to $target: $msg")
log.debug(s"passing the following to $target: $msg")
target.foreach(_ ! msg)
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/com/jdrews/logstation/tailer/LogTailerActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LogTailerActor extends Actor with ActorLogging {
if (!Thread.currentThread().isInterrupted) {
val l = r.readLine
if (l != null) {
log.info(s"read line: $l")
// log.info(s"read line: $l")
// pass to colorizer if it's up, otherwise skip it and go straight to bridge
colorizer.getOrElse(bridge) ! new LogMessage(XmlEscapers.xmlAttributeEscaper().escape(l), XmlEscapers.xmlAttributeEscaper().escape(logFile))
}
Expand All @@ -52,7 +52,7 @@ class LogTailerActor extends Actor with ActorLogging {
while (!Thread.currentThread().isInterrupted) {
val l = r.readLine
if (l != null) {
log.info(s"read line: $l")
// log.info(s"read line: $l")
// pass to colorizer if it's up, otherwise skip it and go straight to bridge
colorizer.getOrElse(bridge) ! new LogMessage(l, logFile)
}
Expand All @@ -64,7 +64,7 @@ class LogTailerActor extends Actor with ActorLogging {

def receive = {
case LogThisFile(logFile) =>
log.info(s"About to begin logging $logFile")
log.debug(s"About to begin logging $logFile")
// calculate bytes to skip to get to last N bytes of file
val file: File = new File(logFile)
val readLastNBytes = 100
Expand All @@ -84,9 +84,9 @@ class LogTailerActor extends Actor with ActorLogging {
readerThreads += readerThread
case cref: ActorRef =>
// load up the colorizer
log.warning(s"got the colorzier! $cref")
log.debug(s"got the colorzier! $cref")
colorizer = Some(cref)
log.info(s"the colorizer.getOrElse -> ${colorizer.getOrElse("nada hombre!")}")
log.debug(s"the colorizer.getOrElse -> ${colorizer.getOrElse("nada hombre!")}")
case ServiceShutdown =>
log.info("shutting down read thread")
readerThreads.foreach(thread => thread.interrupt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LogStationColorizer extends Actor with ActorLogging {
private val bridge = BridgeController.getBridgeActor
def receive = {
case syntax: scala.collection.mutable.Map[String, Regex] =>
log.info(s"Got config $syntax}")
log.debug(s"Got config $syntax}")
// load up the syntaxes
syntaxList = syntax

Expand All @@ -33,7 +33,7 @@ class LogStationColorizer extends Actor with ActorLogging {
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.info(s"got a match! ${syntax._1}")
// log.debug(s"got a match! ${syntax._1}")
// wrap log message in new colors
msg = s"<span style='color:${syntax._1}'>${lm.logMessage}</span>"
loop.break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EmbeddedWebapp(val port: Int = 8884, val contextPath: String = "/") {
val context = new WebAppContext()
context.setContextPath(contextPath)
val warUrlString = this.getClass.getClassLoader.getResource("webapp").toExternalForm()
logger.info(s"warUrlString: $warUrlString")
logger.debug(s"warUrlString: $warUrlString")
context.setWar(warUrlString)
server.setHandler(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ class LogStationPage extends CometActor with CometListener with Loggable {

override def lowPriority = {
case lm: LogMessage =>
logger.info(s"got LogMessage: $lm")
logger.debug(s"got LogMessage: $lm")
partialUpdate(JsFunc("addOrAppendLogMessage", lm.logFile, lm.logMessage).cmd)
case nlp: NewListenerPackage =>
logger.info(s"received a new listener package: $nlp")
logger.debug(s"received a new listener package: $nlp")
partialUpdate(JsFunc("updateMaxLogLinesPerLog", nlp.maxLogLinesPerLog).cmd)
nlp.msgs.foreach{ lm =>
logger.info(s"passing the following up: $lm")
logger.debug(s"passing the following up: $lm")
partialUpdate(JsFunc("addOrAppendLogMessage", lm.logFile, lm.logMessage).cmd)
}
case mll: Int =>
partialUpdate(JsFunc("updateMaxLogLinesPerLog", mll).cmd)
maxLogLinesPerLog = mll
case something =>
logger.info(s"in LogStationPage: got something, not sure what it is: $something")
logger.warn(s"in LogStationPage: got something, not sure what it is: $something")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object LogStationWebServer extends LiftActor with ListenerManager with Loggable
private var bufferLength = 17
private var msgs = new FixedList[LogMessage](bufferLength)

logger.info("at the front of LogStationWebServer...")
logger.debug("at the front of LogStationWebServer...")

// A bridge between the Lift and Akka actor libraries
private lazy val bridge: ActorRef = BridgeController.getBridgeActor
Expand All @@ -49,22 +49,22 @@ object LogStationWebServer extends LiftActor with ListenerManager with Loggable
*/
override def lowPriority = {
case lm: LogMessage =>
logger.info(s"got log message $lm")
logger.debug(s"got log message $lm")
// update client
sendListenersMessage(lm)
// store a copy in fixed list so we have something to send new clients
msgs.append(lm)
case mll: MaxLogLinesPerLog =>
logger.info(s"received maxLogLinesPerLog: $mll")
logger.debug(s"received maxLogLinesPerLog: $mll")
maxLogLinesPerLog = mll.myVal
sendListenersMessage(maxLogLinesPerLog)
case bl: BufferLength =>
logger.info(s"received bufferLength: $bl")
logger.debug(s"received bufferLength: $bl")
bufferLength = bl.myVal
// rebuild msgs list with new buffer length
msgs = new FixedList[LogMessage](bufferLength)
case something =>
logger.info(s"in LogStationWebServer: got something, not sure what it is: $something")
logger.warn(s"in LogStationWebServer: got something, not sure what it is: $something")

// case ServiceShutdown =>
// log.info("Received ServiceShutdown. Shutting down...")
Expand Down
2 changes: 1 addition & 1 deletion test/logGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object LoremIpsum {
val A = Array("ERROR", "WARN", "INFO", "DEBUG", "TRACE")
Random.shuffle(A.toList).head

val file = new File("logfile2.log")
val file = new File("logfile3.log")
val bw = new BufferedWriter(new FileWriter(file))
var i = 0
do {
Expand Down

0 comments on commit d10aac7

Please sign in to comment.