diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-03-07 21:49:46 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-03-07 21:49:46 +0100 |
commit | 9908adb320171c0a12fa7d78964b5ddc3527f9fd (patch) | |
tree | 06544ba73bced1ddc104cb2bf87e3c7672c026ad /lib/log.php | |
parent | faf6055baa224fbf4248a70d28ae4416c9c7eb1c (diff) | |
parent | d8cfe77ba5348d29a9e2b046e2c7efc1dd4758cb (diff) | |
download | nextcloud-server-9908adb320171c0a12fa7d78964b5ddc3527f9fd.tar.gz nextcloud-server-9908adb320171c0a12fa7d78964b5ddc3527f9fd.zip |
Merge branch 'master' into vcategories
Conflicts:
apps/contacts/lib/vcard.php
Diffstat (limited to 'lib/log.php')
-rw-r--r-- | lib/log.php | 26 |
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; } } |