Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5/websockets/javascript based real-time logfile viewer?

Im looking for the equivalent of "tail -f" that runs in a browser using html5 or javascript.

A solution would need a client side code written in HTML5/websockets/javascript and a back-end server side application. Im looking for one in c# but i'm willing to rewrite it from php or python.

This is the only thing that i've seen that comes close is

http://commavee.com/2007/04/13/ajax-logfile-tailer-viewer/

However, modern browsers have WebSockets which makes the problem much simpler.

http://www.websocket.org/echo.html

Ideally, I would like to have some of the capabilities of BareTail

http://www.baremetalsoft.com/baretail/

Such as Color Coding of lines, sorting and multi-file tabbing.

I have located a similar posting where someone is looking for windows based log file programs

https://stackoverflow.com/questions/113121/best-tail-log-file-visualization-freeware-tool

Anyone have any suggestions?

like image 361
mbalsam Avatar asked Jul 27 '12 19:07

mbalsam


2 Answers

It is not exactly like tail but the live logs feature of https://log4sure.com does allow you to monitor your client side logs realtime. You would have to setup and do the logs appropriately as you would do for tailing, but you can see all the logs with extra information about your client, example browser, os, country etc. You can also create your own custom logs to log stuff. Checkout the demo on the site to get a better idea.

The setup code is really easy, and the best part is, its free.

// set up 
var _logServer;

(function() {
  var ls = document.createElement('script');
  ls.type = 'text/javascript';
  ls.async = true;
  ls.src = 'https://log4sure.com/ScriptsExt/log4sure-0.1.min.js';
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(ls, s);
  ls.onload = function() {
    // use your token here.
    _logServer = new LogServer("use-your-token-here");
  };
})();

// example for logging text
_logServer.logText("your log message goes here.")

// example for logging error 
divide = function(numerator, divisor) {
    try {
      if (parseFloat(value) && parseFloat(divisor)) {
        throw new TypeError("Invalid input", "myfile.js", 12, {
          value: value,
          divisor: divisor
        });
      } else {
        if (divisor == 0) {
          throw new RangeError("Divide by 0", "myfile.js", 15, {
            value: value,
            divisor: divisor
          });
        }
      }
    } catch (e) {
      _logServer.logError(e.name, e.message, e.stack);

    }
  }
  // another use of logError in window.onerror
  // must be careful with window.onerror as you might be overwriting some one else's window.onerror functionality
  // also someone else can overwrite window.onerror.
window.onerror = function(msg, url, line, column, err) {
  // may want to check if url belongs to your javascript file
  var data = {
    url: url,
    line: line,
    column: column,

  }
  _logServer.logError(err.name, err.message, err.stack, data);

};

//example for custom logs
var foo = "some variable value";
var bar = "another variable value";
var flag = "false";
var temp = "yet another variable value";

_logServer.log(foo, bar, flag, temp);
like image 96
Bhavin Avatar answered Nov 19 '22 17:11

Bhavin


While I wish it had better JSON object prettification for live tailing and historical logs, the following JS client works and supports your server-side requirement also:

https://github.com/logentries/le_js/wiki/API

<html lang="en">
  <head>
    <title>Your page</title>
    <script src="/js/le.min.js"></script>
    <script>
    // Set up le.js
    LE.init('YOUR-LOG-TOKEN');
    </script>
 </head>

.....

<script>
// log something
LE.log("Hello, logger!");
</script>

Personally to get the above code to work however, I've had to add the following line of code just above LE.init('YOUR-LOG-TOKEN'):

window.LEENDPOINT = 'js.logentries.com/v1'

.. Alternatively, Loggly may be a fit as well: https://www.loggly.com/docs/javascript/

like image 29
sean2078 Avatar answered Nov 19 '22 16:11

sean2078