Skip to content
Snippets Groups Projects
Commit 845bf103 authored by alvaro's avatar alvaro
Browse files

improved logging

parent b92b9d20
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ LODSPeaKr
author: Alvaro Graves (alvaro@graves.cl)
version: 20130215
version: 20130513
[LODSPeaKr](http://lodspeakr.org) is a framework for creating Linked Data applications in a simple and easy way. You can see [several applications](http://alangrafu.github.com/lodspeakr/applications.html) created using LODSPeaKr.
......
......@@ -14,8 +14,27 @@ class Logging{
}
sort($logs);
$alogs = "";
$list = array();
foreach($logs as $v){
$alogs .= "<p><a href='#lodspeakr/cache/$v'>$v</a></p>";
$newtokens = array( ".", "/");
$oldtokens = array("___DOT___", "___SLASH___");
$label = str_replace($oldtokens, $newtokens, $v);
$x = explode("_", $label);
$y = array_shift($x);
array_shift($x);
if(!isset($list[$y])){
$list[$y] = array();
}
$list[$y][] = array("name" => implode("_", $x), "url" => $v);
//$alogs .= "<p><a href='#lodspeakr/cache/$v'>$label</a></p>";
}
ksort($list);
foreach($list as $k => $v){
$alogs .= "<li>".date("H:i:s", $k)."<ul>\n";
foreach($v as $w){
$alogs .= " <li><a href='#lodspeakr/cache/".$w['url']."'>".$w['name']."</a></li>\n";
}
$alogs .="</ul></li>";
}
echo "
<!DOCTYPE html>
......@@ -28,6 +47,10 @@ class Logging{
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
.bold{
font-weight: bold;
font-size: 120%;
}
</style>
<link href='css/bootstrap-responsive.min.css' rel='stylesheet' type='text/css' media='screen' />
<script type='text/javascript' src='js/jquery.js'></script>
......@@ -54,13 +77,25 @@ class Logging{
<div class='row'>
<div class='span4 well'>
<h3>Logs</h3>
<!--div>
<select id='level'>
<option value='0'>All</option>
<option value='1'>Notice</option>
<option value='2'>Error</option>
</select>
</div-->
<ul>
$alogs
</ul>
</div>
<div class='span8' id='log'>
</div>
</div>
<script>
$('a').on('click', function(){
$('a').on('click', function(e){
$('a').removeClass('bold');
$(e.target).addClass('bold');
var link = $(this).attr('href').replace('#', '');
$.ajax({
url: link,
......@@ -68,7 +103,14 @@ class Logging{
success: function(data){
var pres = '';
$.each(data.logs, function(i, item){
pres += '<h4>'+item.timestamp+'</h4><pre>'+item.message+'</pre>';
var date = new Date(item.timestamp * 1000),
dateFormatted = date.getFullYear()+'/'+
(date.getMonth()+1)+'/'+
date.getDate()+' '+
date.getHours()+':'+
date.getMinutes()+':'+
date.getSeconds();
pres += '<h4>On '+dateFormatted+'</h4><pre>'+item.message+'</pre>';
});
$('#log').html(pres);
}
......@@ -86,4 +128,18 @@ class Logging{
fwrite($conf['logfile'], ", ".json_encode($log));
}
}
public static function createLogFile($url){
$oldtokens = array( ".", "/");
$newtokens = array("___DOT___", "___SLASH___");
$filename = str_replace($oldtokens, $newtokens, $url);
$logfile = fopen("cache/".time()."_".rand()."_".$filename.".log", "w");
if($logfile === FALSE){
die("Can't create log file. Check permissions in <tt>cache/</tt> directory.");
}
$initialmsg = array('timestamp' => time(), 'message' => "Starting log for ".$url);
fwrite($logfile, "{ \"logs\": [".json_encode($initialmsg));
return $logfile;
}
}
<?php
$conf['version'] = '20130215';
$conf['version'] = '20130513';
$conf['output']['select'] = 'json';
$conf['output']['ask'] = 'json';
$conf['output']['describe'] = 'rdf';
......
......@@ -24,16 +24,7 @@ if($conf['debug']){
Logging::init();
exit(0);
}else{
$oldtokens = array( ".", "/");
$newtokens = array("_", "_");
$filename = str_replace($oldtokens, $newtokens, $_GET['q']);
$conf['logfile'] = fopen("cache/".$filename."_".time().rand().".log", "w");
if($conf['logfile'] === FALSE){
die("Can't create log file. Check permissions in <tt>cache/</tt> directory.");
}
$initialmsg = array('timestamp' => time(), 'message' => "Log for ".$_GET['q']);
fwrite($conf['logfile'], "{ \"logs\": [".json_encode($initialmsg));
$conf['logfile'] = Logging::createLogFile($_GET['q']);
//error_reporting(E_ALL);
}
}else{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment