8 $colors = array('#F00', '#F80', '#FF0',
10 '#22F', '#ADF', '#0FF', '#F0F', '#508', '#FAA',
11 '#FFF', '#AAA', '#666', '#222');
13 function render_row ($d, $component, $pid, $level, $msg, $c)
17 if (!$ajax && $level == "DEBUG")
20 list($comp,$peer) = explode (',', preg_replace ('/(.*)-(\d*)/', '\1,\2', $component));
21 $peer = array_key_exists ($peer, $peers) ? $peers[$peer] : $peer;
22 $date = $d ? $d->format('Y-m-d'). $d->format('H:i:s') : "";
23 echo "<tr class=\"$level P-$peer C-$comp\" id=\"$c\">";
24 echo "<td class=\"date\"><small>$date</td>";
25 echo '<td class="usec"><small>';
26 echo $d ? $d->format('u') : "";
28 echo "<td class=\"comp\">$comp</td><td class=\"peer\">$peer</td>";
29 echo "<td class=\"level\">$level</td><td><pre>$msg</pre></td>";
30 if ($level != "DEBUG")
32 echo '<td><div class="btn-group"><button class="btn btn-xs btn-default btn-showup"><span class="glyphicon glyphicon-chevron-up"></span></button>';
33 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)
53 $a = explode (' ', $line);
56 $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3)));
59 $msg = implode (' ', array_slice ($a, 5));
61 if (FALSE !== strpos($line, "STARTING SERVICE")) {
62 $id = preg_replace ("/.*\[(....)\].*\n/", '\1', $line);
63 $pid = preg_replace ("/.*[a-z-]*-([0-9]*).*\n/", '\1', $line);
67 $lines[] = array ($date, $component, 0, $level, $msg, $c);
68 $comp = preg_replace ('/(.*)-\d*/', '\1', $component);
72 if (array_key_exists ('a', $_GET)) {
73 $start = (int)$_GET['a'];
80 if (array_key_exists ('z', $_GET)) {
81 $stop = (int)$_GET['z'];
88 $t0 = microtime(true);
89 $handle = @fopen($path, 'r');
92 while (($line = fgets($handle)) !== false) {
93 if (!$start || $c >= $start) {
97 if ($stop && $c > $stop)
101 echo "<div class=\"alert alert-danger\">Error opening file $path.</div>";
104 $t1 = microtime(true);
105 /* Ajax request: don't render container HTML, just table rows. */
106 if ($start !== null || $stop !== null) {
116 <meta charset="utf-8">
117 <meta http-equiv="X-UA-Compatible" content="IE=edge">
118 <meta name="viewport" content="width=device-width, initial-scale=1">
120 <title>GNUnet log view</title>
122 <!-- Latest compiled and minified Bootstrap CSS -->
123 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
124 <!-- Optional theme -->
125 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
129 font-family: arial,sans-serif;
135 border-collapse:collapse;
141 background-color: transparent;
148 margin: 5% 0 0 -37.5%;
162 background-color:#CCC;
165 background-color:#EB9316;
168 background-color:#D2322D;
173 table.table tbody tr td,
174 table.table tbody th td {
175 padding: 0px 0px 0px 2px;
180 foreach ($peers as $peer) {
181 echo "table.table tbody tr.P-$peer td.peer {\n";
182 echo ' background-color: ' . $colors[$c] . ";\n";
184 echo "#P-$peer { color: " . $colors[$c++] . "}\n";
191 <div class="btn-toolbar" role="toolbar">
192 <div class="btn-group">
193 <button id="ERROR" class="btn btn-danger btn-showlevel"><span class="glyphicon glyphicon-fire"></span> Error</button>
194 <button id="WARNING" class="btn btn-warning btn-showlevel"><span class="glyphicon glyphicon-exclamation-sign"></span> Warning</button>
195 <button id="INFO" class="btn btn-default btn-showlevel active"><span class="glyphicon glyphicon glyphicon-info-sign"></span> Info</button>
196 <button id="DEBUG" class="btn btn-primary btn-showlevel"><span class="glyphicon glyphicon glyphicon-wrench"></span> Debug</button>
198 <div class="btn-group">
199 <?php foreach($peers as $pid=>$id): ?>
200 <button id="P-<?php echo $id ?>" class="btn btn-default btn-element btn-showpeer active"><?php echo $id ?></button>
202 <button class="btn btn-default btn-showall">All</button>
203 <button class="btn btn-default btn-shownone">None</button>
205 <div class="btn-group">
206 <?php foreach($comps as $c=>$one): ?>
207 <button id="C-<?php echo $c ?>" class="btn btn-default btn-element btn-showcomp active"><?php echo $c ?></button>
209 <button class="btn btn-default btn-showall">All</button>
210 <button class="btn btn-default btn-shownone">None</button>
213 <div id="msg" class="alert alert-success"></div>
214 <table class="table">
221 <th class="level">Level</th>
227 <?php render_rows(); ?>
230 <p>Processed in <?php echo $t1-$t0; ?> seconds.</p>
231 <p>Rendered in <?php echo microtime(true)-$t1; ?> seconds.</p>
233 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
234 <!-- Latest compiled and minified Bootstrap JavaScript -->
235 <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
239 var types = ["ERROR", "WARNING", "INFO", "DEBUG"];
240 var peers = {<?php foreach($peers as $pid=>$id) echo "'$pid': '$id', "; ?>};
243 function msg (content)
245 $("#msg").html(content);
246 $("#msg").stop(true);
247 $("#msg").fadeTo(100, 1).fadeTo(3000, 0.90).fadeOut(1000);
250 function showlevel (level)
252 $("tbody > tr").hide();
253 $(".btn-showlevel").removeClass("active");
254 $("#"+level).addClass("active");
255 for (var index = 0; index < types.length; ++index) {
256 $(".btn-showpeer.active").each(function(){
257 $("."+types[index]+"."+this.id).show();
259 if (types[index] == level)
264 function shownone(btn)
266 $(btn).parents(".btn-group").children(".btn-element.active").each(function(){$(this).click()});
269 function showall(btn)
271 $(btn).parents(".btn-group").children(".btn-element:not(.active)").each(function(){$(this).click()});
274 function showpeer (peer)
276 $("#"+peer).toggleClass("active");
277 if ($("#"+peer).hasClass("active")) {
278 for (var index = 0; index < types.length; ++index) {
279 var className = "." + types[index] + "." + peer;
281 if ($("#"+types[index]).hasClass("active"))
289 function showcomp (comp)
291 $("#"+comp).toggleClass("active");
292 if ($("#"+comp).hasClass("active")) {
293 for (var index = 0; index < types.length; ++index) {
294 var className = "." + types[index] + "." + comp;
296 if ($("#"+types[index]).hasClass("active"))
304 function load_debug (btn, up)
306 var tr = $(btn).parents("tr");
308 var pos = parseInt(tr.attr("id"));
311 for (var index = 0; index < types.length; ++index) {
312 if (tr.hasClass(types[index]))
314 level = types[index];
319 if (parseInt(tr.prev().attr("id")) == last) {
320 msg ("Already loaded");
323 first = parseInt(tr.prevAll("."+level).first().attr("id")) + 1;
324 first = isNaN(first) ? 0 : first;
326 if (parseInt(tr.next().attr("id")) == first) {
327 msg ("Already loaded");
330 last = parseInt(tr.nextAll("."+level).first().attr("id")) - 1;
335 url: document.location,
336 data: { a: first, z: last }
337 }).done(function ( resp ) {
338 var loc = $("#"+(first-1));
340 for (var peer in peers) {
341 console.log (peer + "=>" + peers[peer]);
342 trs.filter(".P-"+peer).removeClass('P-'+peer).addClass('P-'+peers[peer]).find("td.peer").html(peers[peer]);
348 $("#"+(last+1)).before(trs);
350 msg("Done loading " + (last-first+1) + " lines.");
352 //tr.nextUntil("."+tr.attr("class")).show();
358 var tr = $(btn).parents("tr");
359 tr.nextUntil("."+tr.attr("class")).hide();
363 $(".btn-showup").on ("click", function(){ load_debug(this, true) });
364 $(".btn-showdown").on ("click", function(){ load_debug(this, false) });
365 $(".btn-showlevel").on ("click", function(){ showlevel(this.id) });
366 $(".btn-showpeer").on ("click", function(){ showpeer(this.id) });
367 $(".btn-showcomp").on ("click", function(){ showcomp(this.id) });
368 $(".btn-showall").on ("click", function(){ showall(this) });
369 $(".btn-shownone").on ("click", function(){ shownone(this) });