Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to provide log location via ?url #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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