1

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.

2 Answers 2

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.

1

What you are looking for is a real-time logs browser which is a piece of a simple software that either listens to files with logs or STDIN and prints it to the UI. Depending on the problem you're trying to solve there are a couple of tools that could be used for that purpose. I'm the most advanced on the market currently would be Logdy since you just download a precompiled binary, it can run with ANY input like:

$ tail -f file.log | logdy 

Run it and you'll get all of the contents streamed to a Web UI. It also supports listening to multiple files and can even open a port and listen on TCP socket, check the docs and blog for more use cases.

There are also other similar tools like:

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.