diff options
author | Bart Polot <bart@net.in.tum.de> | 2014-02-13 20:18:09 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2014-02-13 20:18:09 +0000 |
commit | fb3f9328589ff271a2840a982792522787dde2a4 (patch) | |
tree | 02ffaf2761951276fe82dc6c600526b3cd18eca9 /contrib | |
parent | 263c4b44b864cce3b7c1864cd9afddbf3b63fc2d (diff) |
- use AJAX to avoid loading DEBUG messages (breaks firefox by multi-MB log files)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/log.php | 218 |
1 files changed, 150 insertions, 68 deletions
diff --git a/contrib/log.php b/contrib/log.php index 497e34f4bb..6af3e57d4a 100644 --- a/contrib/log.php +++ b/contrib/log.php @@ -1,3 +1,90 @@ +<?php + +$path='log'; +$lines = array(); +$ajax = FALSE; + +function render_row ($d, $component, $pid, $level, $msg, $c) +{ + global $ajax; + if (!$ajax && $level == "DEBUG") + return; + $date = $d ? $d->format('Y-m-d'). '<br />' . $d->format('H:i:s') : ""; + echo "<tr class=\"$level\" id=\"$c\">"; + echo "<td class=\"date\"><small>$date</small></td>"; + echo '<td class="usec">'; + echo $d ? $d->format('u') : ""; + echo '</td>'; + echo "<td class=\"comp\">$component</td><td class=\"level\">$level</td><td>$msg </td>"; + if ($level != "DEBUG") + { + echo '<td><button class="btn btn-xs btn-default btn-showup"><span class="glyphicon glyphicon-chevron-up"></span></button>'; + echo '<button class="btn btn-xs btn-default btn-showdown"><span class="glyphicon glyphicon-chevron-down"></span></button></td></tr>'; + } + else + echo '<td></td></tr>'; +} + +function render_rows () +{ + global $lines; + foreach ($lines as $line) { + render_row ($line[0], $line[1], $line[2], $line[3], $line[4], $line[5]); + } +} + +function process ($line, $c) +{ + global $lines; + $a = explode (' ', $line); + if (count($a) < 6) + return; + $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3))); + $component = $a[3]; + $level = $a[4]; + $msg = implode (' ', array_slice ($a, 5)); + + $lines[] = array ($date, $component, 0, $level, $msg, $c); +} + +if (array_key_exists ('a', $_GET)) { + $start = (int)$_GET['a']; + $ajax= TRUE; +} +else +{ + $start = null; +} +if (array_key_exists ('z', $_GET)) { + $stop = (int)$_GET['z']; + $ajax= TRUE; +} +else +{ + $stop = null; +} +$t0 = microtime(true); +$handle = @fopen($path, 'r'); +if ($handle) { + $c = 0; + while (($line = fgets($handle)) !== false) { + if ((!$start || $c >= $start) && (!$stop || $c <= $stop)) { + process ($line, $c); + } + $c++; + } +} else { + echo "<div class=\"alert alert-danger\">Error opening file $path.</div>"; +} + +$t1 = microtime(true); +if ($start !== null || $stop !== null) { + render_rows(); + die(); +} +// echo $t1-$t0; + +?> <!DOCTYPE html> <html lang="en"> <head> @@ -17,14 +104,17 @@ font-family: arial,sans-serif; color:#444; } -/* a { - text-decoration: none; - color:#000; - }*/ table { font-size:12px; border-collapse:collapse; } + .alert { + display: none; + position: fixed; + width: 75%; + left: 50%; + margin: 0 0 0 -37.5%; + } .level { display: none; } @@ -51,6 +141,7 @@ <button class="btn btn-default btn-showdebug"><span class="glyphicon glyphicon glyphicon-wrench"></span> Debug</button> </div> </div> +<div id="msg" class="alert alert-success"></div> <table class="table"> <thead> <tr> @@ -63,56 +154,7 @@ </tr> </thead> <tbody> -<?php - -$path='log'; - -function render_row ($d, $component, $pid, $level, $msg) -{ - $date = $d ? $d->format('Y-m-d'). '<br />' . $d->format('H:i:s') : ""; - echo "<tr class=\"$level\">"; - echo "<td class=\"date\">$date</td>"; - echo '<td class="usec">'; - echo $d ? $d->format('u') : ""; - echo '</td>'; - echo "<td class=\"comp\">$component</td><td class=\"level\">$level</td><td>$msg </td>"; - if ($level != "DEBUG") - { - echo '<td><button class="btn btn-xs btn-default btn-show"><span class="glyphicon glyphicon-plus"></span></button>'; - echo '<button class="btn btn-xs btn-default btn-hide"><span class="glyphicon glyphicon-minus"></span></button></td></tr>'; - } - else - echo '<td></td></tr>'; - $olddate = $date; -} - -function process ($line) -{ - $a = explode (' ', $line); - if (count($a) < 6) - return; - $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3))); - $component = $a[3]; - $level = $a[4]; - $msg = implode (' ', array_slice ($a, 5)); - - if ($level != "DEBUG") - render_row ($date, $component, 0, $level, $msg); -} - -$t0 = microtime(true); -$handle = @fopen($path, 'r'); -if ($handle) { - while (($line = fgets($handle)) !== false) { - process ($line); - } -} else { - echo "<div class=\"alert alert-danger\">Error opening file $path.</div>"; -} -$t1 = microtime(true); -// echo $t1-$t0; - -?> +<?php render_rows(); ?> </tbody> </table> <!-- jQuery --> @@ -123,20 +165,62 @@ $t1 = microtime(true); <script> var types = ["ERROR", "WARNING", "INFO", "DEBUG"]; - function showt (level) + var msg_timeout; + + function msg (content) + { + $("#msg").html(content); + $("#msg").stop(true); + $("#msg").fadeTo(100, 1).fadeTo(3000, 0.90).fadeOut(1000); + } + + function showlevel (level) { $("tr").hide(); for (var index = 0; index < types.length; ++index) { - $("."+types[index]).show(); - if (types[index] == level) - return; + $("."+types[index]).show(); + if (types[index] == level) + return; } } - function show (btn) + function show (btn, up) { var tr = $(btn).parents("tr"); - tr.nextUntil("."+tr.attr("class")).show(); + var level = tr.attr("class"); + var pos = parseInt(tr.attr("id")); + var first = pos + 1; + var last = pos - 1; + if (up) { + if (parseInt(tr.prev().attr("id")) == last) { + msg ("Already loaded"); + return; + } + first = parseInt(tr.prevAll("."+level).first().attr("id")) + 1; + first = isNaN(first) ? 0 : first; + } else { + if (parseInt(tr.next().attr("id")) == first) { + msg ("Already loaded"); + return; + } + last = parseInt(tr.nextAll("."+level).first().attr("id")) - 1; + } + if (first > last) + return; + $.ajax({ + url: document.location, + data: { a: first, z: last } + }).done(function ( resp ) { + var loc = $("#"+(first-1)); + if (loc.length > 0) + loc.after(resp); + else { + $("#"+(last+1)).before(resp); + } + msg("Done loading " + (last-first+1) + " lines."); + }); + //tr.nextUntil("."+tr.attr("class")).show(); + } function hide (btn) @@ -146,14 +230,12 @@ $t1 = microtime(true); } $(function() { - $(".DEBUG").hide(); - $(".btn-show").on ("click", function(){ show(this) }); - $(".btn-hide").on ("click", function(){ hide(this) }); - $(".btn-showerror").on ("click", function(){ showt("ERROR") }); - $(".btn-showwarn").on ("click", function(){ showt("WARNING") }); - $(".btn-showinfo").on ("click", function(){ showt("INFO") }); - $(".btn-showdebug").on ("click", function(){ showt("DEBUG") }); - console.log( "ready!" ); + $(".btn-showup").on ("click", function(){ show(this, true) }); + $(".btn-showdown").on ("click", function(){ show(this, false) }); + $(".btn-showerror").on ("click", function(){ showlevel("ERROR") }); + $(".btn-showwarn").on ("click", function(){ showlevel("WARNING") }); + $(".btn-showinfo").on ("click", function(){ showlevel("INFO") }); + $(".btn-showdebug").on ("click", function(){ showlevel("DEBUG") }); }); </script> </body> |