Skip to content

Commit

Permalink
regex filtering of logs in client
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrews committed Sep 18, 2016
1 parent 52823e0 commit 8e2de2d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/main/resources/webapp/bootstrap/css/logstation.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ a:hover {
background: #333333;
}

.text-field {
padding: 2px 3px;
background: #333333;
border: none;
color: #9c9b9b;
}

.button-link:hover, .button-link:focus {
background: #444;
border: solid 1px #555555;
Expand Down
71 changes: 54 additions & 17 deletions src/main/resources/webapp/js/LogStationScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Distributed under an Apache 2.0 License
*/

window.regexState = "off";

// Safe way to get document height
function getDocHeight() {
var D = document;
Expand Down Expand Up @@ -65,25 +67,44 @@ function stripSpecials( myid ) {
// used to push in logs from LogStationPage via a JsFunc
function addOrAppendLogMessage(logFile, logMessage) {
if (window.pauseState == "play") {
//create logId
var logId = stripSpecials(logFile);
incrementTotalLogLines(logId);
// Get the div corresponding to this log file
var logDiv = $("#"+logId);
console.log("working on " + logId + "; logDiv.length = " + logDiv.length);
if (logDiv.length) {
// log file already exists, append message
console.log("appending to " + logId + " the message " + logMessage);
logDiv.append("<div class=logMessage>" + logMessage + "<br/></div>")

if (window.regexState == "on") {
regex = $("#regex-field").val()
if (regex) {
if (logMessage.match(regex)) {
// regex match, display it
displayIt = true
} else {
// regex fail, discard
displayIt = false
}
} else {
// regex is empty, default to display it
displayIt = true
}
} else {
// log file doesn't exist yet. add it with this message
console.log("adding new logFile " + logId);
$("#logbody").append("<div id="+logId+" class=logFile style=\'display: none;\' title=\'"+logFile+"\'><div class=logMessage>"+logMessage+"<br/></div></div>");
addNavBarEntry(logFile)
// regex is off, display it
displayIt = true
}
if (displayIt) {
//create logId
var logId = stripSpecials(logFile);
incrementTotalLogLines(logId);
// Get the div corresponding to this log file
var logDiv = $("#"+logId);
console.log("working on " + logId + "; logDiv.length = " + logDiv.length);
if (logDiv.length) {
// log file already exists, append message
console.log("appending to " + logId + " the message " + logMessage);
logDiv.append("<div class=logMessage>" + logMessage + "<br/></div>")
} else {
// log file doesn't exist yet. add it with this message
console.log("adding new logFile " + logId);
$("#logbody").append("<div id="+logId+" class=logFile style=\'display: none;\' title=\'"+logFile+"\'><div class=logMessage>"+logMessage+"<br/></div></div>");
addNavBarEntry(logFile)
}
truncateLinesIfNeeded(logId);
adjustScroll()
}
truncateLinesIfNeeded(logId);
adjustScroll()
} else {
console.log("state paused, not appending message")
}
Expand Down Expand Up @@ -199,6 +220,19 @@ function updatePause () {
}
}

// Logic to control the state of the regex button
function updateRegex () {
if ($("#regex-button").text().match(/regex on/)) { // if we're playing right now
console.log("disabling regex");
$("#regex-button").html("regex off");
window.regexState = "off"
} else if ($("#regex-button").text().match(/regex off/)) { // if we're paused right now
console.log("enabling regex");
$("#regex-button").html("regex on");
window.regexState = "on"
}
}

// If we hit the bottom-- turn on follow scroll. unless the user locked it out
$(window).scroll(function() {
// If we're within 30px (one line) of the bottom we scroll follow
Expand All @@ -224,3 +258,6 @@ $( "#pause-button" ).click(function() {
updatePause()
});

$( "#regex-button" ).click(function() {
updateRegex()
});
6 changes: 5 additions & 1 deletion src/main/resources/webapp/templates-hidden/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">

<title>LogStation</title>
<title>logstation</title>

<!-- Bootstrap core CSS -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
Expand Down Expand Up @@ -60,6 +60,10 @@
<span id="pause-button" class="button-link">playing</span>
&nbsp;|&nbsp;
<span id="follow-indicator" class="button-link">loading...</span>
&nbsp;|&nbsp;
<input type="text" class="text-field" placeholder="regex..." id="regex-field">
&nbsp;
<span id="regex-button" class="button-link">regex off</span>
</p>

<p class="text-muted float-right">
Expand Down

0 comments on commit 8e2de2d

Please sign in to comment.