7 $colors = array('#F00', '#F80', '#FF0',
9 '#22F', '#ADF', '#0FF', '#F0F', '#508', '#FAA',
10 '#FFF', '#AAA', '#666', '#222');
12 function render_row ($d, $component, $pid, $level, $msg, $c)
16 if (!$ajax && $level == "DEBUG")
19 list($comp,$peer) = explode (',', preg_replace ('/(.*)-(\d*)/', '\1,\2', $component));
20 $peer = array_key_exists ($peer, $peers) ? $peers[$peer] : $peer;
21 $date = $d ? $d->format('Y-m-d'). $d->format('H:i:s') : "";
22 echo "<tr class=\"$level P-$peer\" id=\"$c\">";
23 echo "<td class=\"date\"><small>$date</td>";
24 echo '<td class="usec"><small>';
25 echo $d ? $d->format('u') : "";
27 echo "<td class=\"comp\">$comp</td><td class=\"peer\">$peer</td>";
28 echo "<td class=\"level\">$level</td><td><pre>$msg</pre></td>";
29 if ($level != "DEBUG")
31 echo '<td><div class="btn-group"><button class="btn btn-xs btn-default btn-showup"><span class="glyphicon glyphicon-chevron-up"></span></button>';
32 echo '<button class="btn btn-xs btn-default btn-showdown"><span class="glyphicon glyphicon-chevron-down"></span></button></div></td>';
40 function render_rows ()
43 foreach ($lines as $line) {
44 render_row ($line[0], $line[1], $line[2], $line[3], $line[4], $line[5]);
48 function process ($line, $c)
52 $a = explode (' ', $line);
55 $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3)));
58 $msg = implode (' ', array_slice ($a, 5));
60 if (FALSE !== strpos($line, "STARTING SERVICE")) {
61 $id = preg_replace ("/.*\[(....)\].*\n/", '\1', $line);
62 $pid = preg_replace ("/.*[a-z-]*-([0-9]*).*\n/", '\1', $line);
66 $lines[] = array ($date, $component, 0, $level, $msg, $c);
69 if (array_key_exists ('a', $_GET)) {
70 $start = (int)$_GET['a'];
77 if (array_key_exists ('z', $_GET)) {
78 $stop = (int)$_GET['z'];
85 $t0 = microtime(true);
86 $handle = @fopen($path, 'r');
89 while (($line = fgets($handle)) !== false) {
90 if (!$start || $c >= $start) {
94 if ($stop && $c > $stop)
98 echo "<div class=\"alert alert-danger\">Error opening file $path.</div>";
101 $t1 = microtime(true);
102 if ($start !== null || $stop !== null) {
112 <meta charset="utf-8">
113 <meta http-equiv="X-UA-Compatible" content="IE=edge">
114 <meta name="viewport" content="width=device-width, initial-scale=1">
116 <title>GNUnet log view</title>
118 <!-- Latest compiled and minified Bootstrap CSS -->
119 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
120 <!-- Optional theme -->
121 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
125 font-family: arial,sans-serif;
131 border-collapse:collapse;
143 margin: 5% 0 0 -37.5%;
157 background-color:#CCC;
160 background-color:#EB9316;
163 background-color:#D2322D;
168 table.table tbody tr td,
169 table.table tbody th td {
170 padding: 0px 0px 0px 2px;
175 foreach ($peers as $peer) {
176 echo "table.table tbody tr.P-$peer td.peer {\n";
177 echo ' background-color: ' . $colors[$c] . ";\n";
179 echo "#P-$peer { color: " . $colors[$c++] . "}\n";
186 <div class="btn-toolbar" role="toolbar">
187 <div class="btn-group">
188 <button id="ERROR" class="btn btn-danger btn-showlevel"><span class="glyphicon glyphicon-fire"></span> Error</button>
189 <button id="WARNING" class="btn btn-warning btn-showlevel"><span class="glyphicon glyphicon-exclamation-sign"></span> Warning</button>
190 <button id="INFO" class="btn btn-info btn-showlevel active"><span class="glyphicon glyphicon glyphicon-info-sign"></span> Info</button>
191 <button id="DEBUG" class="btn btn-default btn-showlevel"><span class="glyphicon glyphicon glyphicon-wrench"></span> Debug</button>
193 <div class="btn-group">
194 <?php foreach($peers as $pid=>$id): ?>
195 <button id="P-<?php echo $id ?>" class="btn btn-default btn-showpeer active"><?php echo $id ?></button>
197 <button id="btn-showall" class="btn btn-default">All</button>
198 <button id="btn-shownone" class="btn btn-default">None</button>
201 <div id="msg" class="alert alert-success"></div>
202 <table class="table">
209 <th class="level">Level</th>
215 <?php render_rows(); ?>
219 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
220 <!-- Latest compiled and minified Bootstrap JavaScript -->
221 <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
225 var types = ["ERROR", "WARNING", "INFO", "DEBUG"];
226 var peers = {<?php foreach($peers as $pid=>$id) echo "'$pid': '$id', "; ?>};
229 function msg (content)
231 $("#msg").html(content);
232 $("#msg").stop(true);
233 $("#msg").fadeTo(100, 1).fadeTo(3000, 0.90).fadeOut(1000);
236 function showlevel (level)
238 $("tbody > tr").hide();
239 $(".btn-showlevel").removeClass("active");
240 $("#"+level).addClass("active");
241 for (var index = 0; index < types.length; ++index) {
242 $(".btn-showpeer.active").each(function(){
243 $("."+types[index]+"."+this.id).show();
245 if (types[index] == level)
252 $(".btn-showpeer").removeClass("active");
253 $("tbody > tr").hide();
258 $(".btn-showpeer:not(.active)").each(function(){showpeer(this.id)});
261 function showpeer (peer)
263 $("#"+peer).toggleClass("active");
264 if ($("#"+peer).hasClass("active")) {
265 for (var index = 0; index < types.length; ++index) {
266 var className = "." + types[index] + "." + peer;
268 if ($("#"+types[index]).hasClass("active"))
276 function load_debug (btn, up)
278 var tr = $(btn).parents("tr");
280 var pos = parseInt(tr.attr("id"));
283 for (var index = 0; index < types.length; ++index) {
284 if (tr.hasClass(types[index]))
286 level = types[index];
291 if (parseInt(tr.prev().attr("id")) == last) {
292 msg ("Already loaded");
295 first = parseInt(tr.prevAll("."+level).first().attr("id")) + 1;
296 first = isNaN(first) ? 0 : first;
298 if (parseInt(tr.next().attr("id")) == first) {
299 msg ("Already loaded");
302 last = parseInt(tr.nextAll("."+level).first().attr("id")) - 1;
307 url: document.location,
308 data: { a: first, z: last }
309 }).done(function ( resp ) {
310 var loc = $("#"+(first-1));
312 for (var peer in peers) {
313 console.log (peer + "=>" + peers[peer]);
314 trs.filter(".P-"+peer).removeClass('P-'+peer).addClass('P-'+peers[peer]).find("td.peer").html(peers[peer]);
320 $("#"+(last+1)).before(trs);
322 msg("Done loading " + (last-first+1) + " lines.");
324 //tr.nextUntil("."+tr.attr("class")).show();
330 var tr = $(btn).parents("tr");
331 tr.nextUntil("."+tr.attr("class")).hide();
335 $(".btn-showup").on ("click", function(){ load_debug(this, true) });
336 $(".btn-showdown").on ("click", function(){ load_debug(this, false) });
337 $(".btn-showlevel").on ("click", function(){ showlevel(this.id) });
338 $(".btn-showpeer").on ("click", function(){ showpeer(this.id) });
339 $("#btn-showall").on ("click", function(){ showall() });
340 $("#btn-shownone").on ("click", function(){ shownone() });