improve log browsing

This commit is contained in:
Robin Appelman 2012-02-25 21:19:32 +01:00
parent a7d7597d55
commit 797e921b9a
9 changed files with 126 additions and 47 deletions

View file

@ -444,4 +444,37 @@ $.fn.filterAttr = function(attr_name, attr_value) {
return this.filter(function() { return $(this).attr(attr_name) === attr_value; });
};
function humanFileSize(bytes){
if( bytes < 1024 ){
return bytes+' B';
}
bytes = Math.round(bytes / 1024, 1 );
if( bytes < 1024 ){
return bytes+' kB';
}
bytes = Math.round( bytes / 1024, 1 );
if( bytes < 1024 ){
return bytes+' MB';
}
// Wow, heavy duty for owncloud
bytes = Math.round( bytes / 1024, 1 );
return bytes+' GB';
}
function simpleFileSize(bytes) {
mbytes = Math.round(bytes/(1024*1024/10))/10;
if(bytes == 0) { return '0'; }
else if(mbytes < 0.1) { return '< 0.1'; }
else if(mbytes > 1000) { return '> 1000'; }
else { return mbytes.toFixed(1); }
}
function formatDate(date){
if(typeof date=='number'){
date=new Date(date);
}
var monthNames = [ t('files','January'), t('files','February'), t('files','March'), t('files','April'), t('files','May'), t('files','June'),
t('files','July'), t('files','August'), t('files','September'), t('files','October'), t('files','November'), t('files','December') ];
return monthNames[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear()+', '+((date.getHours()<10)?'0':'')+date.getHours()+':'+date.getMinutes();
}

View file

@ -387,39 +387,6 @@ function updateBreadcrumb(breadcrumbHtml) {
$('p.nav').empty().html(breadcrumbHtml);
}
function humanFileSize(bytes){
if( bytes < 1024 ){
return bytes+' B';
}
bytes = Math.round(bytes / 1024, 1 );
if( bytes < 1024 ){
return bytes+' kB';
}
bytes = Math.round( bytes / 1024, 1 );
if( bytes < 1024 ){
return bytes+' MB';
}
// Wow, heavy duty for owncloud
bytes = Math.round( bytes / 1024, 1 );
return bytes+' GB';
}
function simpleFileSize(bytes) {
mbytes = Math.round(bytes/(1024*1024/10))/10;
if(bytes == 0) { return '0'; }
else if(mbytes < 0.1) { return '< 0.1'; }
else if(mbytes > 1000) { return '> 1000'; }
else { return mbytes.toFixed(1); }
}
function formatDate(date){
var monthNames = [ t('files','January'), t('files','February'), t('files','March'), t('files','April'), t('files','May'), t('files','June'),
t('files','July'), t('files','August'), t('files','September'), t('files','October'), t('files','November'), t('files','December') ];
return monthNames[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear()+', '+((date.getHours()<10)?'0':'')+date.getHours()+':'+date.getMinutes();
}
//options for file drag/dropp
var dragOptions={
distance: 20, revert: 'invalid', opacity: 0.7,

View file

@ -3,7 +3,7 @@
* ownCloud
*
* @author Robin Appelman
* @copyright 2011 Robin Appelman icewind1991@gmail.com
* @copyright 2012 Robin Appelman icewind1991@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -50,25 +50,29 @@ class OC_Log{
fclose($fh);
}
}
public static function getEntries(){
/**
* get entries from the log in reverse chronological order
* @param int limit
* @param int offset
* @return array
*/
public static function getEntries($limit=50,$offset=0){
$datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' );
$logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' );
$entries=array();
if(!file_exists($logFile)){
return array();
}
$fh=fopen($logFile,'r');
if($fh === false){ // Unable to read log file!
$contents=file($logFile);
if(!$contents){//error while reading log
return array();
}
while(!feof($fh)){
$line=fgets($fh);
if($line){
$entries[]=json_decode($line);
}
$end=max(count($contents)-$offset-1,0);
$start=max($end-$limit,0);
for($i=$end;$i>$start;$i--){
$entries[]=json_decode($contents[$i]);
}
fclose($fh);
return $entries;
}
}

17
settings/ajax/getlog.php Normal file
View file

@ -0,0 +1,17 @@
<?php
/**
* Copyright (c) 2012, Robin Appelman <icewind1991@gmail.com>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
// Init owncloud
require_once('../../lib/base.php');
OC_JSON::checkAdminUser();
$count=(isset($_GET['count']))?$_GET['count']:50;
$offset=(isset($_GET['offset']))?$_GET['offset']:0;
$entries=OC_Log::getEntries($count,$offset);
OC_JSON::success(array("data" => $entries));

View file

@ -1,4 +1,9 @@
<?php
/**
* Copyright (c) 2012, Robin Appelman <icewind1991@gmail.com>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
// Init owncloud
require_once('../../lib/base.php');

View file

@ -40,3 +40,6 @@ select.quota.active { background: #fff; }
li { color:#888; }
li.active { color:#000; }
span.version { margin-left:3em; color:#ddd; }
/* LOF */
#log { white-space:normal; }

46
settings/js/log.js Normal file
View file

@ -0,0 +1,46 @@
/**
* Copyright (c) 2012, Robin Appelman <icewind1991@gmail.com>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
OC.Log={
levels:['Debug','Info','Warning','Error','Fatal'],
loaded:50,//are initially loaded
getMore:function(){
$.get(OC.filePath('settings','ajax','getlog.php'),{offset:OC.Log.loaded},function(result){
if(result.status=='success'){
OC.Log.addEntries(result.data);
}
});
OC.Log.loaded+=50;
},
addEntries:function(entries){
for(var i=0;i<entries.length;i++){
var entry=entries[i];
var row=$('<tr/>');
var levelTd=$('<td/>');
levelTd.text(OC.Log.levels[entry.level]);
row.append(levelTd);
var appTd=$('<td/>');
appTd.text(entry.app);
row.append(appTd);
var messageTd=$('<td/>');
messageTd.text(entry.message);
row.append(messageTd);
var timeTd=$('<td/>');
timeTd.text(formatDate(entry.time));
row.append(timeTd);
$('#log').append(row);
}
}
}
$(document).ready(function(){
$('#moreLog').click(function(){
OC.Log.getMore();
})
});

View file

@ -3,7 +3,7 @@
* ownCloud
*
* @author Robin Appelman
* @copyright 2011 Robin Appelman icewind1991@gmail.com
* @copyright 2012 Robin Appelman icewind1991@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -30,6 +30,9 @@ OC_App::setActiveNavigationEntry( "core_log" );
$entries=OC_Log::getEntries();
OC_Util::addScript('settings','log');
OC_Util::addStyle('settings','settings');
function compareEntries($a,$b){
return $b->time - $a->time;
}

View file

@ -9,7 +9,7 @@ $levels=array('Debug','Info','Warning','Error','Fatal');
<div id="controls">
</div>
<table>
<table id='log'>
<?php foreach($_['entries'] as $entry):?>
<tr>
<td>
@ -26,4 +26,5 @@ $levels=array('Debug','Info','Warning','Error','Fatal');
</td>
</tr>
<?php endforeach;?>
</table>
</table>
<input id='moreLog' type='button' value='<?php echo $l->t('More');?>...'></input>