0

Here's the use case: A user clicks on a link that opens a window displaying the contents of a text log. Easy enough. But is there a way of using POST, to open that text log to a certain location (i.e., search for a particular timestamp given in the post, and show the file at that specific location)?

(Assume I can't put html tags inside the text log -- it's a raw file).

Template of log:

+++ 2009/06/19 10:47:12.264 ACTION +++
+++ 2009/06/19 10:49:12.111 ACTION +++

So I want the page to load a specific timestamp.

Thanks,
Michael

Dirk
  • 6,774
  • 14
  • 51
  • 73
  • Is the log file a raw `.txt` file? – Sasha Chedygov Jul 14 '09 at 21:03
  • it's a .log file that displays well in chrome / firefox / ie (text isn't jumbled together – Dirk Jul 14 '09 at 21:09
  • can you provide us with a small portion of that log file for download and viewing, maybe there are tools out there to parse it and display in a table manner with search functionality. – balexandre Jul 14 '09 at 21:13
  • have parsed it and broken it down to store in a table, but my clients want to be able to link directly to the original file for data analysis. The log is something like this: Time: Event: Action: Information Time: Event: Action: Information I want to have the log appear at a specific Time, but also keep the rest of the data in place. – Dirk Jul 14 '09 at 21:17
  • http://www.karakas-online.de/EN-Book/include-plain-text-file-in-module.html is useful for the plaintext jumble – Dirk Jul 15 '09 at 00:05

7 Answers7

3

Why can't you just have a php or perl or simlar script that processes the log file on the spot, and sticks in html anchors and calls it a day?

Doing on the spot processing would also allow you display a trimmed down copy of the log thats only relevant to the timespan around the event in question.

whatsisname
  • 5,872
  • 2
  • 20
  • 27
  • It's a large log file, and there would be a lot of anchors (each timestamp would have to be an anchor) – Dirk Jul 14 '09 at 21:09
  • If you want to only go to a specific spot, just throw an anchor in for that specific one. Or only have anchors once per minute/hour in the timestamps, etc. – whatsisname Jul 14 '09 at 21:12
  • The issue with trimming down the file is there is no definitive start and end point. I'm looking for a specific point in the log, then checking the actions before and after it to find a sequence of actions. – Dirk Jul 14 '09 at 21:15
  • I understand that, but 'trimming down' is proportional to the duration of the log file vs the duration of the event. As an example, if you have a log that is switched out once per day, and you are looking for an event that only lasts a few minutes, if you show what happened an hour before and after will probably do the job 95% of the time. For those other rare cases, then just bite the bullet and download the whole file and do a find for the timestamp in question. – whatsisname Jul 14 '09 at 21:20
2

Since you can't modify the file, the only way would be to wrap it in a <frame> or an <iframe> and drive the searching and scrolling from JavaScript in the neighbouring/containing page.

Here's an example, which you can try out online at http://entrian.com/so-container.html

<html><head><script>
function go() {
    // "line" is the <input> for which line to jump to; see the HTML.
    var line = document.getElementById('line').value;
    if (document.body.createTextRange) {  // This is IE
        var range = frames['log'].document.body.createTextRange();
        if (range.findText(line)) {
            range.select(); // Scroll the match into view and highlight it.
        }
    } else {  // Non-IE.  Tested in Firefox; YMMV on other browsers.
        frames['log'].find(line); // Scroll the match into view and highlight it.
    }
}
</script></head><body>
<input type='text' size='5' name='line' id='line' value='10'>
<button onclick='go()'>Go</button><br>
<iframe name='log' width='100' height='50' src='so-data.txt'>
<!-- so-data.txt contains the numbers 01-20 on separate lines -->
</body></html>

I've tested that in IE7 and FF3; I'd be surprised if it worked elsewhere without edits, but you never know your luck!

Obviously in your case you'd be driving the scrolling programmatically rather than via an <input> box, but you can see how it would work for you.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • Yes, but there would be no accurate way to scroll to a specific area in a text file. Different users may have different fonts or font sizes, etc etc, and it would scroll to a different location for each. – Sasha Chedygov Jul 14 '09 at 21:04
  • Michael said "search for a particular timestamp given in the post" - the JavaScript can do that search, measure the distance to the top of the document, and scroll to that location. I've done exactly this before. – RichieHindle Jul 14 '09 at 21:10
  • Can you provide me some details? – Dirk Jul 14 '09 at 21:12
  • Yes, I know it can do that with *HTML*, but can you make those measurements in a raw text file? – Sasha Chedygov Jul 14 '09 at 21:12
  • How do you make the measurements with HTML? – Dirk Jul 14 '09 at 21:36
  • @musicfreak, @Michael: In fact there's no need to measure anything - you can simply find the matching entry and get the browser to do the measure-and-scroll for you. See my updated answer. – RichieHindle Jul 14 '09 at 21:42
0

If you could put some tags around the file's text, then you could probably insert some javascript that would scroll the window after loading it.

cube
  • 3,867
  • 7
  • 32
  • 52
0

Yes, but passing your parameters via a querystring would be a whole lot simpler.

To scroll to a certain position in the text file you will need to user javascript (overly complicated in my opinion) or add an html anchor tag.

If you were planning to post the raw text log in a window, you will also run into some difficulty as HTML will not recognize the newlines and run the log together into one blob.

Chris Van Opstal
  • 36,423
  • 9
  • 73
  • 90
  • It seems like my log file does not appear as a blob when displayed in html. Basically, I want to emulate this behavior: If you search for a word that occurs at the bottom of a webpage, your browser jumps down to that instance. What's the way to do it with javascript? – Dirk Jul 14 '09 at 21:08
0

have you tried

window.open ('log.txt');
window.scrollTo (0, window.scrollMaxY);

? From mozilla reference : https://developer.mozilla.org/en/DOM/window.scrollMaxY

Vlagged
  • 503
  • 5
  • 17
  • See my comment on @RichieHindle's answer; there is no accurate way to scroll to a specific point in a text file because different users may have different fonts, font sizes, etc. – Sasha Chedygov Jul 14 '09 at 21:05
0

Keep a 'living copy' of the log file that has been translated to HTML - every time the original file is modified (or simply every X seconds), check for and append the newest lines with HTML anchors applied to the HTML version.

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
0

A new feature was added to Chromium waaaaay back in 2020 that allows you to link to ANY location on any webpage.

At the time of this writing, it works for sure in Chrome and Opera but not yet in Firefox, Safari or Brave browser.

The trick is to add:

/#:~:text=

and follow the equal sign with the desired search text, replacing any spaces with %20. Example:

<a href="https://newz.icu/#:~:text=Dr.%20Sahin%20is%20the%20CEO" target="_blank">There is no ID near this location on the page</a>
<div>IMPORTANT: Use Opera or Chrome to open above link</div>

For more information:

Linking to a specific part of a web page

cssyphus
  • 37,875
  • 18
  • 96
  • 111