Skip to content

Commit

Permalink
Add option to provide log location via ?url
Browse files Browse the repository at this point in the history
Fix links for order to be included in URL and updated via
changeOrder function.
  • Loading branch information
petr-balogh committed Oct 2, 2023
1 parent 1b9103a commit e0634c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ No server side code is required - it's all just static
files - and all modern web servers support Range (tested lighttpd, cherokee,
apache). Tested (briefly) in IE, FF, Chrome.

Usage: symlink the log to /log, or alter the url in logtail.js. Other settings
available in logtail.js including poll frequency. Then browse to index.html
Usage: symlink the log to /log, provide ?url=http://my.custom.path/log, or alter
the url in logtail.js. Other settings available in logtail.js including poll
frequency. Then browse to index.html

License is GNU GPL 3; see http://www.gnu.org/licenses/

Expand Down
4 changes: 2 additions & 2 deletions logtail.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<body>
<div id="header">
js-logtail.
<a href="./">Reversed</a> or
<a href="./?noreverse">chronological</a> view.
<a href="#" id="reversedOrder">Reversed</a> or
<a href="#" id="chronologicalOrder"">chronological</a> view.
<a id="pause" href='#'>Pause</a>.
</div>
<pre id="data">Loading...</pre>
Expand Down
35 changes: 29 additions & 6 deletions logtail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@

var dataelem = "#data";
var pausetoggle = "#pause";
var reversedLink = "#reversedOrder";
var chronologicalLink = "#chronologicalOrder";
var scrollelems = ["html", "body"];

var url = "log";
var urlString = window.location.href;
var urlObject = new URL(urlString);
var urlParam = urlObject.searchParams.get("url");
var orderParam = urlObject.searchParams.get("order");
var order = orderParam ?? "reversed"
var url = urlParam ?? "log"
var fix_rn = true;
var load = 30 * 1024; /* 30KB */
var poll = 1000; /* 1s */
Expand Down Expand Up @@ -146,7 +153,7 @@ function show_log() {
if (reverse) {
var t_a = t.split(/\n/g);
t_a.reverse();
if (t_a[0] == "")
if (t_a[0] == "")
t_a.shift();
t = t_a.join("\n");
}
Expand All @@ -163,21 +170,37 @@ function error(what) {
kill = true;

$(dataelem).text("An error occured :-(.\r\n" +
"Reloading may help; no promises.\r\n" +
"Reloading may help; no promises.\r\n" +
what);
scroll(0);

return false;
}

function changeOrder(how) {
var searchParams = new URLSearchParams(window.location.search)
searchParams.set("order", how)
window.location.search = searchParams.toString()
const originalURL = new URL("http://my.app/index.html?order=reverse");
const updatedURL = addParameterToURL(originalURL, "newParam", "someValue");
}

$(document).ready(function () {
window.onerror = error;

/* If URL is /logtail/?noreverse display in chronological order */
var hash = location.search.replace(/^\?/, "");
if (hash == "noreverse")
/* If URL is /logtail/?order=chronological we display in chronological order */
if (order == "chronological") {
reverse = false;
} else {
reverse = true;
}

$(reversedLink).click(function (e) {
changeOrder("reversed");
});
$(chronologicalLink).click(function (e) {
changeOrder("chronological");
});
/* Add pause toggle */
$(pausetoggle).click(function (e) {
pause = !pause;
Expand Down

0 comments on commit e0634c5

Please sign in to comment.