aboutsummaryrefslogtreecommitdiff
path: root/contrib/log.php
blob: 09de9acf574705155a070abf9065f57bfbbefd33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <title>GNUnet log view</title>

  <!-- Latest compiled and minified Bootstrap CSS -->
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
  <!-- Optional theme -->
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">

  <style>
    body {
      font-family: arial,sans-serif;
      color:#444;
    }
/*    a {
      text-decoration: none;
      color:#000;
    }*/
    table {
      font-size:12px;
      border-collapse:collapse;
    }
    .level {
      display: none;
    }
    .DEBUG {
      background-color:#CCC;
    }

  </style>
</head>


<body>

<table class="table">
  <tr>
    <th>Date Time</th>
    <th>uSec</th>
    <th>Comp</th>
    <th class="level">Level</th>
    <th>Message</th>
    <th></th>
  </tr>
<?php

$path='log';

function render_row ($d, $component, $pid, $level, $msg)
{
  $date = $d->format('Y-m-d'). '<br />' . $d->format('H:i:s');
  echo "<tr class=\"$level\">";
  echo "<td class=\"date\">$date</td>";
  echo '<td class="usec">';
  echo $d->format('u');
  echo '</td>';
  echo "<td class=\"comp\">$component</td><td class=\"level\">$level</td><td>$msg&nbsp;</td>";
  echo '<td><button class="btn btn-xs btn-default btn-show"><span class="glyphicon glyphicon-plus"></span></button>';
  echo '<button class="btn btn-xs btn-default btn-hide"><span class="glyphicon glyphicon-minus"></span></button></td></tr>';
  $olddate = $date;
} 

function process ($line)
{
  $a = explode (' ', $line);
  $date = DateTime::createFromFormat ("M d H:i:s-u", implode (' ', array_slice ($a, 0, 3)));
  $component = $a[3];
  $level = $a[4];
  $msg = implode (' ', array_slice ($a, 5));
  
  render_row ($date, $component, 0, $level, $msg);
}


$handle = @fopen($path, 'r');
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        process ($line);
    }
} else {
   echo "<div class=\"alert alert-danger\">Error opening file $path.</div>";
}

?>

</table>
  <!-- jQuery -->
  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  <!-- Latest compiled and minified Bootstrap JavaScript -->
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>

  <script>

    function show (btn)
    {
      var tr = $(btn).parents("tr");
      tr.nextUntil("."+tr.attr("class")).show();
      return;
    }

    function hide (btn)
    {
      var tr = $(btn).parents("tr");
      tr.nextUntil("."+tr.attr("class")).hide();
      return;
    }

    $(function() {
      $(".DEBUG").hide();
      $(".btn-show").on ("click", function(){ show(this) });
      $(".btn-hide").on ("click", function(){ hide(this) });
      console.log( "ready!" );
    });
  </script>
</body>
</html>