aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-02-25 21:19:32 +0100
committerRobin Appelman <icewind@owncloud.com>2012-02-26 03:10:29 +0100
commit797e921b9aa25f832718a3c44cfcb936f96c49df (patch)
tree890cdbcadc8f15a3fac7c1db53adbd2a1b7fc5ce /lib
parenta7d7597d552ce41aa7f9d77c751b9160224cf96a (diff)
downloadnextcloud-server-797e921b9aa25f832718a3c44cfcb936f96c49df.tar.gz
nextcloud-server-797e921b9aa25f832718a3c44cfcb936f96c49df.zip
improve log browsing
Diffstat (limited to 'lib')
-rw-r--r--lib/log.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/log.php b/lib/log.php
index 446ddd48848..4e450a027f5 100644
--- a/lib/log.php
+++ b/lib/log.php
@@ -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;
}
}