summaryrefslogtreecommitdiffstats
path: root/lib/log/owncloud.php
diff options
context:
space:
mode:
authorMichael Gapczynski <GapczynskiM@gmail.com>2012-06-01 14:38:25 -0400
committerMichael Gapczynski <GapczynskiM@gmail.com>2012-06-01 14:42:14 -0400
commit4db5481ad53d37c8b82aeac926a0278a0c5c9e69 (patch)
tree40e128f217b2b285d4c6e496f5a3a2866c14b10d /lib/log/owncloud.php
parent52b3305892ff2100431cdd898914284edc861fd3 (diff)
downloadnextcloud-server-4db5481ad53d37c8b82aeac926a0278a0c5c9e69.tar.gz
nextcloud-server-4db5481ad53d37c8b82aeac926a0278a0c5c9e69.zip
Improve efficiency of retrieving log file entries
Diffstat (limited to 'lib/log/owncloud.php')
-rw-r--r--lib/log/owncloud.php35
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php
index 0b7a231d304..5913d8b5b83 100644
--- a/lib/log/owncloud.php
+++ b/lib/log/owncloud.php
@@ -62,23 +62,26 @@ class OC_Log_Owncloud {
public static function getEntries($limit=50, $offset=0){
self::init();
$minLevel=OC_Config::getValue( "loglevel", OC_Log::WARN );
- $entries=array();
- if(!file_exists(self::$logFile)) {
- return array();
- }
- $contents=file(self::$logFile);
- if(!$contents) {//error while reading log
- return array();
- }
- $end=max(count($contents)-$offset-1, 0);
- $start=max($end-$limit,0);
- $i=$end;
- while($i>$start){
- $entry=json_decode($contents[$i]);
- if($entry->level>=$minLevel){
- $entries[]=$entry;
+ $entries = array();
+ $handle = fopen(self::$logFile, 'r');
+ if ($handle) {
+ // Just a guess to set the file pointer to the right spot
+ $maxLineLength = 150;
+ fseek($handle, -($limit * $maxLineLength + $offset * $maxLineLength), SEEK_END);
+ // Skip first line, because it is most likely a partial line
+ fgets($handle);
+ while (!feof($handle)) {
+ $line = fgets($handle);
+ if (!empty($line)) {
+ $entry = json_decode($line);
+ if ($entry->level >= $minLevel) {
+ $entries[] = $entry;
+ }
+ }
}
- $i--;
+ fclose($handle);
+ // Extract the needed entries and reverse the order
+ $entries = array_reverse(array_slice($entries, -($limit + $offset), $limit));
}
return $entries;
}