8 function render_row ($d, $component, $pid, $level, $msg, $c)
12 if (!$ajax && $level == "DEBUG")
15 list($comp,$peer) = explode (',', preg_replace ('/(.*)-(\d*)/', '\1,\2', $component));
16 $peer = array_key_exists ($peer, $peers) ? $peers[$peer] : $peer;
17 $date = $d ? $d->format('Y-m-d'). $d->format('H:i:s') : "";
18 echo "<tr class=\"$level $peer\" id=\"$c\">";
19 echo "<td class=\"date\"><small>$date</td>";
20 echo '<td class="usec"><small>';
21 echo $d ? $d->format('u') : "";
23 echo "<td class=\"comp\">$comp</td><td class=\"peer\">$peer</td>";
24 echo "<td class=\"level\">$level</td><td>$msg </td>";
25 if ($level != "DEBUG")
27 echo '<td><div class="btn-group"><button class="btn btn-xs btn-default btn-showup"><span class="glyphicon glyphicon-chevron-up"></span></button>';
28 echo '<button class="btn btn-xs btn-default btn-showdown"><span class="glyphicon glyphicon-chevron-down"></span></button></div></td>';
36 function render_rows ()
39 foreach ($lines as $line) {
40 render_row ($line[0], $line[1], $line[2], $line[3], $line[4], $line[5]);
44 function process ($line, $c)
48 $a = explode (' ', $line);
51 $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3)));
54 $msg = implode (' ', array_slice ($a, 5));
56 if (FALSE !== strpos($line, "STARTING SERVICE")) {
57 $id = preg_replace ("/.*\[(....)\].*\n/", '\1', $line);
58 $pid = preg_replace ("/.*[a-z-]*-([0-9]*).*\n/", '\1', $line);
62 $lines[] = array ($date, $component, 0, $level, $msg, $c);
65 if (array_key_exists ('a', $_GET)) {
66 $start = (int)$_GET['a'];
73 if (array_key_exists ('z', $_GET)) {
74 $stop = (int)$_GET['z'];
81 $t0 = microtime(true);
82 $handle = @fopen($path, 'r');
85 while (($line = fgets($handle)) !== false) {
86 if (!$start || $c >= $start) {
90 if ($stop && $c > $stop)
94 echo "<div class=\"alert alert-danger\">Error opening file $path.</div>";
97 $t1 = microtime(true);
98 if ($start !== null || $stop !== null) {
108 <meta charset="utf-8">
109 <meta http-equiv="X-UA-Compatible" content="IE=edge">
110 <meta name="viewport" content="width=device-width, initial-scale=1">
112 <title>GNUnet log view</title>
114 <!-- Latest compiled and minified Bootstrap CSS -->
115 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
116 <!-- Optional theme -->
117 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
121 font-family: arial,sans-serif;
127 border-collapse:collapse;
134 margin: 5% 0 0 -37.5%;
144 background-color:#CCC;
147 background-color:#EB9316;
150 background-color:#D2322D;
155 table.table tbody tr td {
156 padding: 0px 0px 0px 4px;
164 <div class="btn-toolbar" role="toolbar">
165 <div class="btn-group">
166 <button id="ERROR" class="btn btn-danger btn-showlevel"><span class="glyphicon glyphicon-fire"></span> Error</button>
167 <button id="WARNING" class="btn btn-warning btn-showlevel"><span class="glyphicon glyphicon-exclamation-sign"></span> Warning</button>
168 <button id="INFO" class="btn btn-info btn-showlevel active"><span class="glyphicon glyphicon glyphicon-info-sign"></span> Info</button>
169 <button id="DEBUG" class="btn btn-default btn-showlevel"><span class="glyphicon glyphicon glyphicon-wrench"></span> Debug</button>
171 <div class="btn-group">
172 <?php foreach($peers as $pid=>$id): ?>
173 <button id="<?php echo $id ?>" class="btn btn-default btn-showpeer active"><?php echo $id ?></button>
175 <button id="all" class="btn btn-default btn-showpeer">All</button>
176 <button id="none" class="btn btn-default btn-showpeer">None</button>
179 <div id="msg" class="alert alert-success"></div>
180 <table class="table">
187 <th class="level">Level</th>
193 <?php render_rows(); ?>
197 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
198 <!-- Latest compiled and minified Bootstrap JavaScript -->
199 <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
203 var types = ["ERROR", "WARNING", "INFO", "DEBUG"];
206 function msg (content)
208 $("#msg").html(content);
209 $("#msg").stop(true);
210 $("#msg").fadeTo(100, 1).fadeTo(3000, 0.90).fadeOut(1000);
213 function showlevel (level)
215 $("tbody > tr").hide();
216 $(".btn-showlevel").removeClass("active");
217 $("#"+level).addClass("active");
218 for (var index = 0; index < types.length; ++index) {
219 $("."+types[index]).show();
220 if (types[index] == level)
225 function showpeer (peer)
227 $("#"+peer).toggleClass("active");
228 if ($("#"+peer).hasClass("active")) {
235 function load_debug (btn, up)
237 var tr = $(btn).parents("tr");
239 var pos = parseInt(tr.attr("id"));
242 for (var index = 0; index < types.length; ++index) {
243 if (tr.hasClass(types[index]))
245 level = types[index];
250 if (parseInt(tr.prev().attr("id")) == last) {
251 msg ("Already loaded");
254 first = parseInt(tr.prevAll("."+level).first().attr("id")) + 1;
255 first = isNaN(first) ? 0 : first;
257 if (parseInt(tr.next().attr("id")) == first) {
258 msg ("Already loaded");
261 last = parseInt(tr.nextAll("."+level).first().attr("id")) - 1;
266 url: document.location,
267 data: { a: first, z: last }
268 }).done(function ( resp ) {
269 var loc = $("#"+(first-1));
273 $("#"+(last+1)).before(resp);
275 msg("Done loading " + (last-first+1) + " lines.");
277 //tr.nextUntil("."+tr.attr("class")).show();
283 var tr = $(btn).parents("tr");
284 tr.nextUntil("."+tr.attr("class")).hide();
288 $(".btn-showup").on ("click", function(){ load_debug(this, true) });
289 $(".btn-showdown").on ("click", function(){ load_debug(this, false) });
290 $(".btn-showlevel").on ("click", function(){ showlevel(this.id) });
291 $(".btn-showpeer").on ("click", function(){ showpeer(this.id) });