Skip to content

Commit

Permalink
cleanup imports and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrews committed May 29, 2016
1 parent d335dce commit 2096153
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 40 deletions.
10 changes: 8 additions & 2 deletions src/main/resources/webapp/js/LogStationScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ function stripSpecials( myid ) {
return myid.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'-')
}

//if the logFile doesn't exist, add it
// if the logFile doesn't exist, add it
// used to push in logs from LogStationPage via a JsFunc
function addOrAppendLogMessage(logFile, logMessage) {
if (window.pauseState == "play") {
//create logId
Expand Down Expand Up @@ -84,28 +85,31 @@ function addOrAppendLogMessage(logFile, logMessage) {
}

// update the current maxLogLinesPerLog
// called from LogStationPage
function updateMaxLogLinesPerLog(maxLogLinesPerLog) {
console.log("updating maxLogLinesPerLog to " + maxLogLinesPerLog);
window.maxLogLinesPerLog = maxLogLinesPerLog
}

// called from LogStationPage for resetting all local vars
function resetAll() {
console.log("resetting all");
window.totalLogLines = {};
window.scrollFollow = "follow"
}

// called from LogStationPage to default to following (tailing) to logs
function enableScrollFollow() {
window.scrollFollow = "follow"
}

// called from LogStationPage to default to playing log messages
function enablePlay() {
window.pauseState = "play"
}

// increment number of lines in all logs, and handle truncating if they get too large
function incrementTotalLogLines(logId) {

// increment number of total lines
if (typeof window.totalLogLines == 'undefined') {
// first time incrementing any logs. make the Object
Expand All @@ -128,6 +132,7 @@ function logExists(logId) {
return (logId in window.totalLogLines)
}

// chop some log messages off the head if we've hit maxLogLinesPerLog
function truncateLinesIfNeeded(logId) {
console.log(logId + " => log line calculations: " + window.totalLogLines[logId] + " / " + (window.maxLogLinesPerLog));
// if we've gone over maxLogLinesPerLog, truncate!
Expand Down Expand Up @@ -176,6 +181,7 @@ function setScrollFollow(desiredScrollFollow) {
console.log("scrollFollow: " + window.scrollFollow)
}

// Logic to control the state of the pause button
function updatePause () {
if ($("#pause-button").text().match(/play/)) { // if we're playing right now
console.log("pausing");
Expand Down
16 changes: 10 additions & 6 deletions src/main/scala/com/jdrews/logstation/LogStation.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package com.jdrews.logstation

import java.io.{BufferedWriter, File, FileWriter}

import akka.actor.Props
import akka.event.Logging
import akka.pattern._
import com.jdrews.logstation.config.{DefaultConfigHolder, BridgeController, GlobalActorSystem}
import com.jdrews.logstation.config.{BridgeController, DefaultConfigHolder, GlobalActorSystem}
import com.jdrews.logstation.service.{LogStationServiceActor, ServiceShutdown}
import com.jdrews.logstation.tailer.LogThisFile
import com.jdrews.logstation.webserver.{LogMessage, EmbeddedWebapp}
import com.typesafe.config.{ConfigRenderOptions, Config, ConfigFactory}
import collection.JavaConversions._
import com.jdrews.logstation.webserver.EmbeddedWebapp
import com.typesafe.config.ConfigFactory

import scala.collection.JavaConversions._
import scala.concurrent.Await
import scala.concurrent.duration._
import java.io.{BufferedWriter, FileWriter, File}

import scala.util.matching.Regex


/**
* Created by jdrews on 2/21/2015.
*
* The starting point of the LogStation
* holds toe GlobalActorSystem and kicks off new actors
*/
// TODO: move these to their own files to make it a bit cleaner
case class BufferLength (myVal: Int)
Expand Down
10 changes: 6 additions & 4 deletions src/main/scala/com/jdrews/logstation/config/BridgeActor.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.jdrews.logstation.config

import akka.actor.{ActorLogging, Actor}
import com.jdrews.logstation.{BufferLength, MaxLogLinesPerLog}
import akka.actor.{Actor, ActorLogging}
import com.jdrews.logstation.utils.FixedList
import com.jdrews.logstation.{BufferLength, MaxLogLinesPerLog}
import net.liftweb.actor.LiftActor
import net.liftweb.http.CometActor

/**
* Created by jdrews on 3/22/2015.
*
* Used to bridge between Lift and Scala
* Buffers up messages before a LiftActor connects and then hands over messages
* Stores configuration for the LiftActor
*/
class BridgeActor extends Actor with ActorLogging {
private var target: Option[LiftActor] = None
Expand Down Expand Up @@ -47,6 +50,5 @@ class BridgeActor extends Actor with ActorLogging {
log.info(s"passing the following to $target: $msg")
target.foreach(_ ! msg)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.jdrews.logstation.config

import akka.actor.ActorRef
import akka.agent.Agent
import scala.concurrent.ExecutionContext.Implicits.global
import net.liftweb.common.Loggable

import scala.concurrent.ExecutionContext.Implicits.global

/**
* Controls the life-cycle of Actor Bridges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.jdrews.logstation.config

/**
* Created by jdrews on 4/12/2015.
*
* Store a copy of the default config to be pushed to user environment on first boot
*/
object DefaultConfigHolder {
val defaultConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package com.jdrews.logstation.service

import akka.actor._
import akka.pattern._
import com.typesafe.config.{ConfigRenderOptions, Config, ConfigFactory}
import com.jdrews.logstation.tailer.{LogTailerActor, LogThisFile}
import com.jdrews.logstation.utils.LogStationColorizer


import scala.concurrent.Await
import scala.concurrent.duration._
import scala.util.matching.Regex

/**
* Created by jdrews on 2/21/2015.
*
* Hold the tailers and colorizer actors
*/
class LogStationServiceActor extends Actor with ActorLogging{
private var logTailers = Set.empty[ActorRef]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Created by jdrews on 2/21/2015.
* Object to be passed around when shutting down the LogStation
*/
package com.jdrews.logstation.service

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.jdrews.logstation.tailer

import java.io._

import akka.actor.{ActorRef, Actor, ActorLogging}
import com.google.common.html.HtmlEscapers
import akka.actor.{Actor, ActorLogging, ActorRef}
import com.google.common.xml.XmlEscapers
import com.jdrews.logstation.config.BridgeController
import com.jdrews.logstation.service.ServiceShutdown
Expand All @@ -12,6 +11,9 @@ import com.osinka.tailf.Tail

/**
* Created by jdrews on 2/21/2015.
*
* Actor to perform the tailing functionality
* Should be one of these actors per log
*/
class LogTailerActor extends Actor with ActorLogging {
// TODO: probably doesn't need to be a set. There should be only one thread per actor
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/jdrews/logstation/tailer/LogThisFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ package com.jdrews.logstation.tailer

/**
* Created by jdrews on 2/21/2015.
*
* Object used to signify a new log file to begin tailing
*/
case class LogThisFile(logFile: String)
2 changes: 2 additions & 0 deletions src/main/scala/com/jdrews/logstation/utils/FixedList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.jdrews.logstation.utils

/**
* Created by jdrews on 3/29/2015.
*
* Maintain a list of fixed size. i.e. drop old entries if list reaches $max
*/
import scala.collection._
import mutable.ListBuffer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.jdrews.logstation.utils

import akka.actor.{Terminated, Props, ActorLogging, Actor}
import akka.pattern._
import akka.actor.{Actor, ActorLogging, Terminated}
import com.jdrews.logstation.config.BridgeController
import com.jdrews.logstation.service.ServiceShutdown
import com.jdrews.logstation.tailer.{LogTailerActor, LogThisFile}
import com.jdrews.logstation.webserver.LogMessage
import com.typesafe.config.{ConfigRenderOptions, Config, ConfigFactory}

import scala.concurrent.Await
import scala.util.control.Breaks
import scala.util.matching.Regex

/**
* Created by jdrews on 4/12/2015.
*
* Uses a syntaxList to turn LogMessages into colorized messages
* Wraps the text in a <span/> to colorize it in the web page
*/
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 = {
Expand All @@ -29,9 +29,12 @@ class LogStationColorizer extends Actor with ActorLogging {
// 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.info(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
@@ -1,9 +1,12 @@
package com.jdrews.logstation.webserver

import akka.event.Logging
import com.jdrews.logstation.LogStation._
import com.jdrews.logstation.config.GlobalActorSystem


/**
* Serves up the web page
*/
class EmbeddedWebapp(val port: Int = 8884, val contextPath: String = "/") {

val system = GlobalActorSystem.getActorSystem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Created by jdrews on 2/21/2015.
*
* Represents a log message.
*/
package com.jdrews.logstation.webserver

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
package com.jdrews.logstation.webserver.comet

import akka.actor.{ActorRef, PoisonPill}
import com.jdrews.logstation.config.BridgeController
import com.jdrews.logstation.utils.FixedList
import com.jdrews.logstation.webserver.LogMessage
import net.liftweb.actor.LAPinger
import net.liftweb.common.{Full, Loggable}
import net.liftweb.http.js.JE.{JsRaw, JsFunc, Call, ValById}
import net.liftweb.http.js.{JsCmd, Jx, JsCmds}
import net.liftweb.http.js.jquery.JqJE.{JqAppend, JqId}
import net.liftweb.http.js.jquery.JqJsCmds
import net.liftweb.http.{RenderOut, CometActor, CometListener}
import net.liftweb.http.js.JE.JsFunc
import net.liftweb.http.{CometActor, CometListener}
import net.liftweb.util.ClearClearable

import scala.collection.mutable._
import scala.collection.mutable.HashMap
import scala.xml.NodeSeq

/**
* The screen real estate on the browser will be represented
* by this component. When the component changes on the server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.jdrews.logstation.webserver.comet

import akka.actor.{PoisonPill, ActorRef}
import com.jdrews.logstation.{BufferLength, MaxLogLinesPerLog}
import akka.actor.ActorRef
import com.jdrews.logstation.config.BridgeController
import com.jdrews.logstation.utils.FixedList
import com.jdrews.logstation.webserver.LogMessage
import com.jdrews.logstation.{BufferLength, MaxLogLinesPerLog}
import net.liftweb.actor._
import net.liftweb.common.Loggable
import net.liftweb.http._
import scala.collection.mutable
import scala.collection.mutable.{ListBuffer, HashMap}

/**
* Created by jdrews on 2/21/2015.
*
* Communicates with LogStationPages to push updates to the web page
*/

case class NewListenerPackage ( maxLogLinesPerLog: Int, msgs: List[LogMessage])
Expand Down

0 comments on commit 2096153

Please sign in to comment.