Skip to content

Commit

Permalink
feature: set unique name for logstation instance, prepend to <title/>
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrews committed Jul 1, 2018
1 parent 72988ae commit 667007b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "logstation"

version := "0.3.9"
version := "0.3.10"

scalaVersion := "2.10.4"

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>LogStation</title>
<title>logstation</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
</head>
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/webapp/js/LogStationScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ function updateMaxLogLinesPerLog(maxLogLinesPerLog) {
window.maxLogLinesPerLog = maxLogLinesPerLog
}

// update the logStationName in the title of the page
// called from LogStationPage
function updateLogStationName(logStationName) {
console.log("updating logStationName to " + logStationName);
window.logStationName = logStationName
if (logStationName !== '') {
document.title = logStationName + " - logstation"
}
}

// called from LogStationPage for resetting all local vars
function resetAll() {
console.log("resetting all");
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/webapp/templates-hidden/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<!-- Custom styles for this template -->
<link href="bootstrap/css/logstation.css" rel="stylesheet">

<!-- TODO: make these files be included in
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="bootstrap/js/html5shiv.min.js"></script>
Expand Down Expand Up @@ -68,7 +67,7 @@

<p class="text-muted float-right">
<!-- TODO: make version populate via sbt version -->
<a href="https://github.com/jdrews/logstation">logstation</a> 0.3.8</p>
<a href="https://github.com/jdrews/logstation">logstation</a> 0.3.10</p>
</div>
<div style="clear: both;"></div>

Expand Down
18 changes: 16 additions & 2 deletions src/main/scala/com/jdrews/logstation/LogStation.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jdrews.logstation

import java.io.{BufferedWriter, File, FileWriter}
import java.awt.Desktop;
import java.net.URI;
import java.awt.Desktop
import java.net.URI

import akka.actor.Props
import akka.event.Logging
Expand All @@ -28,6 +28,7 @@ import scala.util.matching.Regex
// TODO: move these to their own files to make it a bit cleaner
case class BufferLength (myVal: Int)
case class MaxLogLinesPerLog (myVal: Int)
case class LogStationName (myVal: String)

//TODO: fix the user lockout follow (or disable altogether) -- add button to scroll to bottom (maybe make it hover or something cool like that?)
object LogStation extends App {
Expand Down Expand Up @@ -90,10 +91,23 @@ object LogStation extends App {
}
}

val logStationName = {
if (conf.hasPath("logstation.logStationName")) {
val logStationName = conf.getString("logstation.logStationName")
logger.info(s"logStationName (user set): $logStationName")
logStationName
} else {
val logStationName = ""
logger.info(s"logStationName (default): $logStationName")
logStationName
}
}

// Start up the BridgeActor
private val bridge = BridgeController.getBridgeActor
bridge ! MaxLogLinesPerLog(maxLogLinesPerLog)
bridge ! BufferLength(bufferLength)
bridge ! LogStationName(logStationName)

// Start up the embedded webapp
val webServer = new EmbeddedWebapp(webServerPort, "/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jdrews.logstation.config

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

/**
Expand All @@ -18,13 +18,15 @@ class BridgeActor extends Actor with ActorLogging {
private var bufferLength = 12
private var maxLogLinesPerLog = 120
private var msgs = new FixedList[Any](bufferLength)
private var logStationName = ""
def receive = {
case lift: LiftActor =>
log.debug(s"received LiftActor: $lift")
target = Some(lift)

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

if (msgs.nonEmpty) {
log.debug("sending out buffered msgs")
Expand All @@ -42,6 +44,9 @@ class BridgeActor extends Actor with ActorLogging {
bufferLength = bl.myVal
// rebuild msgs list with new buffer length
msgs = new FixedList[Any](bufferLength)
case lsname: LogStationName =>
log.debug(s"received logStationName: $logStationName")
logStationName = lsname.myVal
case msg =>
if (target.isEmpty) {
log.debug(s"buffering this message since target is empty... $msg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ object DefaultConfigHolder {
| # These will be sent to any new connections so they have some history of logs
| # bufferLength is multiplied by number of logs, and buffered on best effort for each log
| bufferLength=10
|
| # Unique name for logstation instance
| # This name will be prepended to the browser tab
| # Can be useful when connecting to multiple logstations
| #logStationName="dc10srv42"
|}
""".stripMargin
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jdrews.logstation.webserver.comet

import com.jdrews.logstation.LogStationName
import com.jdrews.logstation.webserver.LogMessage
import net.liftweb.common.{Full, Loggable}
import net.liftweb.http.js.JE.JsFunc
Expand All @@ -22,15 +23,20 @@ class LogStationPage extends CometActor with CometListener with Loggable {
logger.debug(s"got LogMessage: $lm")
partialUpdate(JsFunc("addOrAppendLogMessage", lm.logFile, lm.logMessage).cmd)
case nlp: NewListenerPackage =>
logger.debug(s"received a new listener package: $nlp")
partialUpdate(JsFunc("updateMaxLogLinesPerLog", nlp.maxLogLinesPerLog).cmd)
logger.debug(s"received a new listener package: $nlp")
partialUpdate(JsFunc("updateMaxLogLinesPerLog", nlp.maxLogLinesPerLog).cmd)
partialUpdate(JsFunc("updateLogStationName", nlp.logStationName).cmd)
nlp.msgs.foreach{ lm =>
logger.debug(s"passing the following up: $lm")
partialUpdate(JsFunc("addOrAppendLogMessage", lm.logFile, lm.logMessage).cmd)
}
case mll: Int =>
logger.debug(s"received maxLogLinesPerLog: $mll")
partialUpdate(JsFunc("updateMaxLogLinesPerLog", mll).cmd)
maxLogLinesPerLog = mll
case lsname: LogStationName =>
logger.debug(s"received logStationName: $lsname")
partialUpdate(JsFunc("updateLogStationName", lsname.myVal).cmd)
case 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 @@ -4,7 +4,7 @@ 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 com.jdrews.logstation.{BufferLength, LogStationName, MaxLogLinesPerLog}
import net.liftweb.actor._
import net.liftweb.common.Loggable
import net.liftweb.http._
Expand All @@ -15,11 +15,12 @@ import net.liftweb.http._
* Communicates with LogStationPages to push updates to the web page
*/

case class NewListenerPackage ( maxLogLinesPerLog: Int, msgs: List[LogMessage])
case class NewListenerPackage ( maxLogLinesPerLog: Int, logStationName: String, msgs: List[LogMessage])

object LogStationWebServer extends LiftActor with ListenerManager with Loggable {
private var maxLogLinesPerLog = 130
private var bufferLength = 17
private var logStationName = ""
private var msgs = new FixedList[LogMessage](bufferLength)

logger.debug("at the front of LogStationWebServer...")
Expand All @@ -41,7 +42,7 @@ object LogStationWebServer extends LiftActor with ListenerManager with Loggable
*/
def createUpdate = {
logger.info("client connected")
NewListenerPackage(maxLogLinesPerLog, msgs.toList)
NewListenerPackage(maxLogLinesPerLog, logStationName, msgs.toList)
}

/**
Expand All @@ -63,6 +64,10 @@ object LogStationWebServer extends LiftActor with ListenerManager with Loggable
bufferLength = bl.myVal
// rebuild msgs list with new buffer length
msgs = new FixedList[LogMessage](bufferLength)
case lsname: LogStationName =>
logger.debug(s"received logStationName: $lsname")
logStationName = lsname.myVal
sendListenersMessage(lsname)
case something =>
logger.warn(s"in LogStationWebServer: got something, not sure what it is: $something")

Expand Down

0 comments on commit 667007b

Please sign in to comment.