7 $colors = array('#F00', '#0C0', '#44F', '#FF0', '#F0F', '#0FF');
9 function render_row ($d, $component, $pid, $level, $msg, $c)
13 if (!$ajax && $level == "DEBUG")
16 list($comp,$peer) = explode (',', preg_replace ('/(.*)-(\d*)/', '\1,\2', $component));
17 $peer = array_key_exists ($peer, $peers) ? $peers[$peer] : $peer;
18 $date = $d ? $d->format('Y-m-d'). $d->format('H:i:s') : "";
19 echo "<tr class=\"$level P-$peer\" id=\"$c\">";
20 echo "<td class=\"date\"><small>$date</td>";
21 echo '<td class="usec"><small>';
22 echo $d ? $d->format('u') : "";
24 echo "<td class=\"comp\">$comp</td><td class=\"peer\">$peer</td>";
25 echo "<td class=\"level\">$level</td><td>$msg </td>";
26 if ($level != "DEBUG")
28 echo '<td><div class="btn-group"><button class="btn btn-xs btn-default btn-showup"><span class="glyphicon glyphicon-chevron-up"></span></button>';
29 echo '<button class="btn btn-xs btn-default btn-showdown"><span class="glyphicon glyphicon-chevron-down"></span></button></div></td>';
37 function render_rows ()
40 foreach ($lines as $line) {
41 render_row ($line[0], $line[1], $line[2], $line[3], $line[4], $line[5]);
45 function process ($line, $c)
49 $a = explode (' ', $line);
52 $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3)));
55 $msg = implode (' ', array_slice ($a, 5));
57 if (FALSE !== strpos($line, "STARTING SERVICE")) {
58 $id = preg_replace ("/.*\[(....)\].*\n/", '\1', $line);
59 $pid = preg_replace ("/.*[a-z-]*-([0-9]*).*\n/", '\1', $line);
63 $lines[] = array ($date, $component, 0, $level, $msg, $c);
66 if (array_key_exists ('a', $_GET)) {
67 $start = (int)$_GET['a'];
74 if (array_key_exists ('z', $_GET)) {
75 $stop = (int)$_GET['z'];
82 $t0 = microtime(true);
83 $handle = @fopen($path, 'r');
86 while (($line = fgets($handle)) !== false) {
87 if (!$start || $c >= $start) {
91 if ($stop && $c > $stop)
95 echo "<div class=\"alert alert-danger\">Error opening file $path.</div>";
98 $t1 = microtime(true);
99 if ($start !== null || $stop !== null) {
109 <meta charset="utf-8">
110 <meta http-equiv="X-UA-Compatible" content="IE=edge">
111 <meta name="viewport" content="width=device-width, initial-scale=1">
113 <title>GNUnet log view</title>
115 <!-- Latest compiled and minified Bootstrap CSS -->
116 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
117 <!-- Optional theme -->
118 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
122 font-family: arial,sans-serif;
125 font-family: courier,sans-serif;
129 border-collapse:collapse;
136 margin: 5% 0 0 -37.5%;
146 background-color:#CCC;
149 background-color:#EB9316;
152 background-color:#D2322D;
157 table.table tbody tr td,
158 table.table tbody th td {
159 padding: 0px 0px 0px 2px;
164 foreach ($peers as $peer) {
165 echo "table.table tbody tr.P-$peer td.peer {\n";
166 echo ' background-color: ' . $colors[$c] . ";\n";
168 echo "#P-$peer { color: " . $colors[$c++] . "}\n";
175 <div class="btn-toolbar" role="toolbar">
176 <div class="btn-group">
177 <button id="ERROR" class="btn btn-danger btn-showlevel"><span class="glyphicon glyphicon-fire"></span> Error</button>
178 <button id="WARNING" class="btn btn-warning btn-showlevel"><span class="glyphicon glyphicon-exclamation-sign"></span> Warning</button>
179 <button id="INFO" class="btn btn-info btn-showlevel active"><span class="glyphicon glyphicon glyphicon-info-sign"></span> Info</button>
180 <button id="DEBUG" class="btn btn-default btn-showlevel"><span class="glyphicon glyphicon glyphicon-wrench"></span> Debug</button>
182 <div class="btn-group">
183 <?php foreach($peers as $pid=>$id): ?>
184 <button id="P-<?php echo $id ?>" class="btn btn-default btn-showpeer active"><?php echo $id ?></button>
186 <button id="btn-showall" class="btn btn-default">All</button>
187 <button id="btn-shownone" class="btn btn-default">None</button>
190 <div id="msg" class="alert alert-success"></div>
191 <table class="table">
198 <th class="level">Level</th>
204 <?php render_rows(); ?>
208 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
209 <!-- Latest compiled and minified Bootstrap JavaScript -->
210 <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
214 var types = ["ERROR", "WARNING", "INFO", "DEBUG"];
215 var peers = {<?php foreach($peers as $pid=>$id) echo "'$pid': '$id', "; ?>};
218 function msg (content)
220 $("#msg").html(content);
221 $("#msg").stop(true);
222 $("#msg").fadeTo(100, 1).fadeTo(3000, 0.90).fadeOut(1000);
225 function showlevel (level)
227 $("tbody > tr").hide();
228 $(".btn-showlevel").removeClass("active");
229 $("#"+level).addClass("active");
230 for (var index = 0; index < types.length; ++index) {
231 $(".btn-showpeer.active").each(function(){
232 $("."+types[index]+"."+this.id).show();
234 if (types[index] == level)
241 $(".btn-showpeer").removeClass("active");
242 $("tbody > tr").hide();
247 $(".btn-showpeer:not(.active)").each(function(){showpeer(this.id)});
250 function showpeer (peer)
252 $("#"+peer).toggleClass("active");
253 if ($("#"+peer).hasClass("active")) {
254 for (var index = 0; index < types.length; ++index) {
255 var className = "." + types[index] + "." + peer;
257 if ($("#"+types[index]).hasClass("active"))
265 function load_debug (btn, up)
267 var tr = $(btn).parents("tr");
269 var pos = parseInt(tr.attr("id"));
272 for (var index = 0; index < types.length; ++index) {
273 if (tr.hasClass(types[index]))
275 level = types[index];
280 if (parseInt(tr.prev().attr("id")) == last) {
281 msg ("Already loaded");
284 first = parseInt(tr.prevAll("."+level).first().attr("id")) + 1;
285 first = isNaN(first) ? 0 : first;
287 if (parseInt(tr.next().attr("id")) == first) {
288 msg ("Already loaded");
291 last = parseInt(tr.nextAll("."+level).first().attr("id")) - 1;
296 url: document.location,
297 data: { a: first, z: last }
298 }).done(function ( resp ) {
299 var loc = $("#"+(first-1));
301 for (var peer in peers) {
302 console.log (peer + "=>" + peers[peer]);
303 trs.filter(".P-"+peer).removeClass('P-'+peer).addClass('P-'+peers[peer]).find("td.peer").html(peers[peer]);
309 $("#"+(last+1)).before(trs);
311 msg("Done loading " + (last-first+1) + " lines.");
313 //tr.nextUntil("."+tr.attr("class")).show();
319 var tr = $(btn).parents("tr");
320 tr.nextUntil("."+tr.attr("class")).hide();
324 $(".btn-showup").on ("click", function(){ load_debug(this, true) });
325 $(".btn-showdown").on ("click", function(){ load_debug(this, false) });
326 $(".btn-showlevel").on ("click", function(){ showlevel(this.id) });
327 $(".btn-showpeer").on ("click", function(){ showpeer(this.id) });
328 $("#btn-showall").on ("click", function(){ showall() });
329 $("#btn-shownone").on ("click", function(){ shownone() });