0

I have a server that runs a number of tasks. Each task has a log file. I have a webserver that lets you see these log files, but it just copies the contents of the file to the browser and the user has to press F5 over & over...

Is there a way to produce a clean scrolling "live" view for a specified log? Similar to "tail -f" in the terminal window.

CaptainCodeman
  • 207
  • 1
  • 7

1 Answers1

1

That's possible, but possibly quite impractical if the logs are filling rapidly. This would require

  • a script that keeps track of a log file.
    • It could check if the file has changed after the last check and possibly how much it has increased.
    • Then it should get the data from the end of the file: the increased bytes or sufficient amount of lines to compare what's new. That depends on whether it's ok to skip some lines here and there or not, and might be a lot trickier than just tail -f.
    • A constantly running tail -f might be a source for the script, but that might be a bad design: the buffer might get huge, or be flushed by other users.
    • The script would output the file in e.g. JSON format.
  • a JavaScript that
    • calls the previous script regularly and
    • adds the new lines into an element on the web page.
    • Possibly adding the lines above the previous lines would be better suitable for web?

There might be such work or part of it done, if you Google for log, tail & AJAX. I don't know of the quality of those projects, and most seem quite old and unmanaged.

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122