Language: JavaScript
Web Tail javascript
var logTailId = -1; $(document).ready(function () { $('#tail').click(function () { var $tail = $(this); if ($tail.text().indexOf('Stop') >= 0) { $tail.text('Tail...'); clearTimeout(logTailId); } else { $tail.text('[ Stop Tail ]'); getLogData(getNumRows(), getLogFileName(), true); } return false; }); $('#viewLog').click(function () { getLogData(getNumRows(), getLogFileName(), false); return false; }); }); function getLogData(numRows, logFile, isTail) { var proxy = new ServiceProxy("ViewLog.aspx/"); proxy.isWcf = false; proxy.invoke("GetLogTail", { logname: logFile, numrows: numRows }, function (data) { displayLog(logFile, data); if (isTail) { var method = "getLogData(" + getNumRows() + ", '" + getLogFileName() + "', "+ isTail +")"; logTailId = setTimeout(method, getNumSecs()); } }, function (errmsg) { clearTimeout(logTailId); alert(errmsg); }, false); // NOT bare } function clearLog() { $('#logDiv').html(''); } function displayLog(logFile, data) { clearLog(); var now= new Date(); $('#lastUpdate').html( "<span style='font-style:italic'>(" + logFile + ") last update: " + now.format("n-j-y H:i:s ") + "</span>"); var $log = $('#logDiv'); var logStr = ""; for (var property in data) { logStr += formatLine(data[property]); } $log.html(logStr); } function getNumRows() { var numRows = 30; numRows = parseInt($('#<%=tbLines.ClientID %>').val(), 10); if (isNaN(numRows)) { numRows = 45; } return numRows; } function getNumSecs() { var numSecs = 5000; numSecs = parseInt($('#tailsecs').val(), 10); if (isNaN(numSecs)) { numSecs = 1000 * 5; } else { numSecs *= 1000; } return numSecs; } function getLogFileName() { var log = $('#<%=ddlLogFiles.ClientID %>').val(); return log.replace("\\", "/"); } function formatLine(line) { line = line.encodeHtml(); if (line.toLowerCase().indexOf('info') === 0) { return "<span class='info'>" + line + "</span><br/>"; } else if (line.toLowerCase().indexOf('error') === 0) { return "<span class='error'>" + line + "</span><br/>"; } else if (line.toLowerCase().indexOf('warn') === 0) { return "<span class='warn'>" + line + "</span><br/>"; } else if (line.toLowerCase().indexOf('debug') === 0) { return "<span class='debug'>" + line + "</span><br/>"; } return "<span>" + line + "</span><br/>"; }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

