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) | |
download | gnunet-fb3f9328589ff271a2840a982792522787dde2a4.tar.gz gnunet-fb3f9328589ff271a2840a982792522787dde2a4.zip |
- 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 497e34f4b..6af3e57d4 100644 --- a/contrib/log.php +++ b/contrib/log.php | |||
@@ -1,3 +1,90 @@ | |||
1 | <?php | ||
2 | |||
3 | $path='log'; | ||
4 | $lines = array(); | ||
5 | $ajax = FALSE; | ||
6 | |||
7 | function render_row ($d, $component, $pid, $level, $msg, $c) | ||
8 | { | ||
9 | global $ajax; | ||
10 | if (!$ajax && $level == "DEBUG") | ||
11 | return; | ||
12 | $date = $d ? $d->format('Y-m-d'). '<br />' . $d->format('H:i:s') : ""; | ||
13 | echo "<tr class=\"$level\" id=\"$c\">"; | ||
14 | echo "<td class=\"date\"><small>$date</small></td>"; | ||
15 | echo '<td class="usec">'; | ||
16 | echo $d ? $d->format('u') : ""; | ||
17 | echo '</td>'; | ||
18 | echo "<td class=\"comp\">$component</td><td class=\"level\">$level</td><td>$msg </td>"; | ||
19 | if ($level != "DEBUG") | ||
20 | { | ||
21 | echo '<td><button class="btn btn-xs btn-default btn-showup"><span class="glyphicon glyphicon-chevron-up"></span></button>'; | ||
22 | echo '<button class="btn btn-xs btn-default btn-showdown"><span class="glyphicon glyphicon-chevron-down"></span></button></td></tr>'; | ||
23 | } | ||
24 | else | ||
25 | echo '<td></td></tr>'; | ||
26 | } | ||
27 | |||
28 | function render_rows () | ||
29 | { | ||
30 | global $lines; | ||
31 | foreach ($lines as $line) { | ||
32 | render_row ($line[0], $line[1], $line[2], $line[3], $line[4], $line[5]); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | function process ($line, $c) | ||
37 | { | ||
38 | global $lines; | ||
39 | $a = explode (' ', $line); | ||
40 | if (count($a) < 6) | ||
41 | return; | ||
42 | $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3))); | ||
43 | $component = $a[3]; | ||
44 | $level = $a[4]; | ||
45 | $msg = implode (' ', array_slice ($a, 5)); | ||
46 | |||
47 | $lines[] = array ($date, $component, 0, $level, $msg, $c); | ||
48 | } | ||
49 | |||
50 | if (array_key_exists ('a', $_GET)) { | ||
51 | $start = (int)$_GET['a']; | ||
52 | $ajax= TRUE; | ||
53 | } | ||
54 | else | ||
55 | { | ||
56 | $start = null; | ||
57 | } | ||
58 | if (array_key_exists ('z', $_GET)) { | ||
59 | $stop = (int)$_GET['z']; | ||
60 | $ajax= TRUE; | ||
61 | } | ||
62 | else | ||
63 | { | ||
64 | $stop = null; | ||
65 | } | ||
66 | $t0 = microtime(true); | ||
67 | $handle = @fopen($path, 'r'); | ||
68 | if ($handle) { | ||
69 | $c = 0; | ||
70 | while (($line = fgets($handle)) !== false) { | ||
71 | if ((!$start || $c >= $start) && (!$stop || $c <= $stop)) { | ||
72 | process ($line, $c); | ||
73 | } | ||
74 | $c++; | ||
75 | } | ||
76 | } else { | ||
77 | echo "<div class=\"alert alert-danger\">Error opening file $path.</div>"; | ||
78 | } | ||
79 | |||
80 | $t1 = microtime(true); | ||
81 | if ($start !== null || $stop !== null) { | ||
82 | render_rows(); | ||
83 | die(); | ||
84 | } | ||
85 | // echo $t1-$t0; | ||
86 | |||
87 | ?> | ||
1 | <!DOCTYPE html> | 88 | <!DOCTYPE html> |
2 | <html lang="en"> | 89 | <html lang="en"> |
3 | <head> | 90 | <head> |
@@ -17,14 +104,17 @@ | |||
17 | font-family: arial,sans-serif; | 104 | font-family: arial,sans-serif; |
18 | color:#444; | 105 | color:#444; |
19 | } | 106 | } |
20 | /* a { | ||
21 | text-decoration: none; | ||
22 | color:#000; | ||
23 | }*/ | ||
24 | table { | 107 | table { |
25 | font-size:12px; | 108 | font-size:12px; |
26 | border-collapse:collapse; | 109 | border-collapse:collapse; |
27 | } | 110 | } |
111 | .alert { | ||
112 | display: none; | ||
113 | position: fixed; | ||
114 | width: 75%; | ||
115 | left: 50%; | ||
116 | margin: 0 0 0 -37.5%; | ||
117 | } | ||
28 | .level { | 118 | .level { |
29 | display: none; | 119 | display: none; |
30 | } | 120 | } |
@@ -51,6 +141,7 @@ | |||
51 | <button class="btn btn-default btn-showdebug"><span class="glyphicon glyphicon glyphicon-wrench"></span> Debug</button> | 141 | <button class="btn btn-default btn-showdebug"><span class="glyphicon glyphicon glyphicon-wrench"></span> Debug</button> |
52 | </div> | 142 | </div> |
53 | </div> | 143 | </div> |
144 | <div id="msg" class="alert alert-success"></div> | ||
54 | <table class="table"> | 145 | <table class="table"> |
55 | <thead> | 146 | <thead> |
56 | <tr> | 147 | <tr> |
@@ -63,56 +154,7 @@ | |||
63 | </tr> | 154 | </tr> |
64 | </thead> | 155 | </thead> |
65 | <tbody> | 156 | <tbody> |
66 | <?php | 157 | <?php render_rows(); ?> |
67 | |||
68 | $path='log'; | ||
69 | |||
70 | function render_row ($d, $component, $pid, $level, $msg) | ||
71 | { | ||
72 | $date = $d ? $d->format('Y-m-d'). '<br />' . $d->format('H:i:s') : ""; | ||
73 | echo "<tr class=\"$level\">"; | ||
74 | echo "<td class=\"date\">$date</td>"; | ||
75 | echo '<td class="usec">'; | ||
76 | echo $d ? $d->format('u') : ""; | ||
77 | echo '</td>'; | ||
78 | echo "<td class=\"comp\">$component</td><td class=\"level\">$level</td><td>$msg </td>"; | ||
79 | if ($level != "DEBUG") | ||
80 | { | ||
81 | echo '<td><button class="btn btn-xs btn-default btn-show"><span class="glyphicon glyphicon-plus"></span></button>'; | ||
82 | echo '<button class="btn btn-xs btn-default btn-hide"><span class="glyphicon glyphicon-minus"></span></button></td></tr>'; | ||
83 | } | ||
84 | else | ||
85 | echo '<td></td></tr>'; | ||
86 | $olddate = $date; | ||
87 | } | ||
88 | |||
89 | function process ($line) | ||
90 | { | ||
91 | $a = explode (' ', $line); | ||
92 | if (count($a) < 6) | ||
93 | return; | ||
94 | $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3))); | ||
95 | $component = $a[3]; | ||
96 | $level = $a[4]; | ||
97 | $msg = implode (' ', array_slice ($a, 5)); | ||
98 | |||
99 | if ($level != "DEBUG") | ||
100 | render_row ($date, $component, 0, $level, $msg); | ||
101 | } | ||
102 | |||
103 | $t0 = microtime(true); | ||
104 | $handle = @fopen($path, 'r'); | ||
105 | if ($handle) { | ||
106 | while (($line = fgets($handle)) !== false) { | ||
107 | process ($line); | ||
108 | } | ||
109 | } else { | ||
110 | echo "<div class=\"alert alert-danger\">Error opening file $path.</div>"; | ||
111 | } | ||
112 | $t1 = microtime(true); | ||
113 | // echo $t1-$t0; | ||
114 | |||
115 | ?> | ||
116 | </tbody> | 158 | </tbody> |
117 | </table> | 159 | </table> |
118 | <!-- jQuery --> | 160 | <!-- jQuery --> |
@@ -123,20 +165,62 @@ $t1 = microtime(true); | |||
123 | <script> | 165 | <script> |
124 | 166 | ||
125 | var types = ["ERROR", "WARNING", "INFO", "DEBUG"]; | 167 | var types = ["ERROR", "WARNING", "INFO", "DEBUG"]; |
126 | function showt (level) | 168 | var msg_timeout; |
169 | |||
170 | function msg (content) | ||
171 | { | ||
172 | $("#msg").html(content); | ||
173 | $("#msg").stop(true); | ||
174 | $("#msg").fadeTo(100, 1).fadeTo(3000, 0.90).fadeOut(1000); | ||
175 | } | ||
176 | |||
177 | function showlevel (level) | ||
127 | { | 178 | { |
128 | $("tr").hide(); | 179 | $("tr").hide(); |
129 | for (var index = 0; index < types.length; ++index) { | 180 | for (var index = 0; index < types.length; ++index) { |
130 | $("."+types[index]).show(); | 181 | $("."+types[index]).show(); |
131 | if (types[index] == level) | 182 | if (types[index] == level) |
132 | return; | 183 | return; |
133 | } | 184 | } |
134 | } | 185 | } |
135 | 186 | ||
136 | function show (btn) | 187 | function show (btn, up) |
137 | { | 188 | { |
138 | var tr = $(btn).parents("tr"); | 189 | var tr = $(btn).parents("tr"); |
139 | tr.nextUntil("."+tr.attr("class")).show(); | 190 | var level = tr.attr("class"); |
191 | var pos = parseInt(tr.attr("id")); | ||
192 | var first = pos + 1; | ||
193 | var last = pos - 1; | ||
194 | if (up) { | ||
195 | if (parseInt(tr.prev().attr("id")) == last) { | ||
196 | msg ("Already loaded"); | ||
197 | return; | ||
198 | } | ||
199 | first = parseInt(tr.prevAll("."+level).first().attr("id")) + 1; | ||
200 | first = isNaN(first) ? 0 : first; | ||
201 | } else { | ||
202 | if (parseInt(tr.next().attr("id")) == first) { | ||
203 | msg ("Already loaded"); | ||
204 | return; | ||
205 | } | ||
206 | last = parseInt(tr.nextAll("."+level).first().attr("id")) - 1; | ||
207 | } | ||
208 | if (first > last) | ||
209 | return; | ||
210 | $.ajax({ | ||
211 | url: document.location, | ||
212 | data: { a: first, z: last } | ||
213 | }).done(function ( resp ) { | ||
214 | var loc = $("#"+(first-1)); | ||
215 | if (loc.length > 0) | ||
216 | loc.after(resp); | ||
217 | else { | ||
218 | $("#"+(last+1)).before(resp); | ||
219 | } | ||
220 | msg("Done loading " + (last-first+1) + " lines."); | ||
221 | }); | ||
222 | //tr.nextUntil("."+tr.attr("class")).show(); | ||
223 | |||
140 | } | 224 | } |
141 | 225 | ||
142 | function hide (btn) | 226 | function hide (btn) |
@@ -146,14 +230,12 @@ $t1 = microtime(true); | |||
146 | } | 230 | } |
147 | 231 | ||
148 | $(function() { | 232 | $(function() { |
149 | $(".DEBUG").hide(); | 233 | $(".btn-showup").on ("click", function(){ show(this, true) }); |
150 | $(".btn-show").on ("click", function(){ show(this) }); | 234 | $(".btn-showdown").on ("click", function(){ show(this, false) }); |
151 | $(".btn-hide").on ("click", function(){ hide(this) }); | 235 | $(".btn-showerror").on ("click", function(){ showlevel("ERROR") }); |
152 | $(".btn-showerror").on ("click", function(){ showt("ERROR") }); | 236 | $(".btn-showwarn").on ("click", function(){ showlevel("WARNING") }); |
153 | $(".btn-showwarn").on ("click", function(){ showt("WARNING") }); | 237 | $(".btn-showinfo").on ("click", function(){ showlevel("INFO") }); |
154 | $(".btn-showinfo").on ("click", function(){ showt("INFO") }); | 238 | $(".btn-showdebug").on ("click", function(){ showlevel("DEBUG") }); |
155 | $(".btn-showdebug").on ("click", function(){ showt("DEBUG") }); | ||
156 | console.log( "ready!" ); | ||
157 | }); | 239 | }); |
158 | </script> | 240 | </script> |
159 | </body> | 241 | </body> |