7 function render_row ($d, $component, $pid, $level, $msg, $c)
10 if (!$ajax && $level == "DEBUG")
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') : "";
18 echo "<td class=\"comp\">$component</td><td class=\"level\">$level</td><td>$msg </td>";
19 if ($level != "DEBUG")
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>';
25 echo '<td></td></tr>';
28 function render_rows ()
31 foreach ($lines as $line) {
32 render_row ($line[0], $line[1], $line[2], $line[3], $line[4], $line[5]);
36 function process ($line, $c)
39 $a = explode (' ', $line);
42 $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3)));
45 $msg = implode (' ', array_slice ($a, 5));
47 $lines[] = array ($date, $component, 0, $level, $msg, $c);
50 if (array_key_exists ('a', $_GET)) {
51 $start = (int)$_GET['a'];
58 if (array_key_exists ('z', $_GET)) {
59 $stop = (int)$_GET['z'];
66 $t0 = microtime(true);
67 $handle = @fopen($path, 'r');
70 while (($line = fgets($handle)) !== false) {
71 if ((!$start || $c >= $start) && (!$stop || $c <= $stop)) {
77 echo "<div class=\"alert alert-danger\">Error opening file $path.</div>";
80 $t1 = microtime(true);
81 if ($start !== null || $stop !== null) {
91 <meta charset="utf-8">
92 <meta http-equiv="X-UA-Compatible" content="IE=edge">
93 <meta name="viewport" content="width=device-width, initial-scale=1">
95 <title>GNUnet log view</title>
97 <!-- Latest compiled and minified Bootstrap CSS -->
98 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
99 <!-- Optional theme -->
100 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
104 font-family: arial,sans-serif;
109 border-collapse:collapse;
116 margin: 0 0 0 -37.5%;
122 background-color:#CCC;
125 background-color:#EB9316;
128 background-color:#D2322D;
136 <div class="btn-toolbar" role="toolbar">
137 <div class="btn-group">
138 <button class="btn btn-danger btn-showerror"><span class="glyphicon glyphicon-fire"></span> Error</button>
139 <button class="btn btn-warning btn-showwarn"><span class="glyphicon glyphicon-exclamation-sign"></span> Warning</button>
140 <button class="btn btn-info btn-showinfo"><span class="glyphicon glyphicon glyphicon-info-sign"></span> Info</button>
141 <button class="btn btn-default btn-showdebug"><span class="glyphicon glyphicon glyphicon-wrench"></span> Debug</button>
144 <div id="msg" class="alert alert-success"></div>
145 <table class="table">
151 <th class="level">Level</th>
157 <?php render_rows(); ?>
161 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
162 <!-- Latest compiled and minified Bootstrap JavaScript -->
163 <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
167 var types = ["ERROR", "WARNING", "INFO", "DEBUG"];
170 function msg (content)
172 $("#msg").html(content);
173 $("#msg").stop(true);
174 $("#msg").fadeTo(100, 1).fadeTo(3000, 0.90).fadeOut(1000);
177 function showlevel (level)
180 for (var index = 0; index < types.length; ++index) {
181 $("."+types[index]).show();
182 if (types[index] == level)
187 function show (btn, up)
189 var tr = $(btn).parents("tr");
190 var level = tr.attr("class");
191 var pos = parseInt(tr.attr("id"));
195 if (parseInt(tr.prev().attr("id")) == last) {
196 msg ("Already loaded");
199 first = parseInt(tr.prevAll("."+level).first().attr("id")) + 1;
200 first = isNaN(first) ? 0 : first;
202 if (parseInt(tr.next().attr("id")) == first) {
203 msg ("Already loaded");
206 last = parseInt(tr.nextAll("."+level).first().attr("id")) - 1;
211 url: document.location,
212 data: { a: first, z: last }
213 }).done(function ( resp ) {
214 var loc = $("#"+(first-1));
218 $("#"+(last+1)).before(resp);
220 msg("Done loading " + (last-first+1) + " lines.");
222 //tr.nextUntil("."+tr.attr("class")).show();
228 var tr = $(btn).parents("tr");
229 tr.nextUntil("."+tr.attr("class")).hide();
233 $(".btn-showup").on ("click", function(){ show(this, true) });
234 $(".btn-showdown").on ("click", function(){ show(this, false) });
235 $(".btn-showerror").on ("click", function(){ showlevel("ERROR") });
236 $(".btn-showwarn").on ("click", function(){ showlevel("WARNING") });
237 $(".btn-showinfo").on ("click", function(){ showlevel("INFO") });
238 $(".btn-showdebug").on ("click", function(){ showlevel("DEBUG") });