Skip to content

Commit 39c8890

Browse files
committed
Merge pull request #9 from icewind1991/time-reformat
Reformat date from the log if needed
2 parents a401add + 4951883 commit 39c8890

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

controller/logcontroller.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ public function __construct($appName,
4747
$this->config = $config;
4848
}
4949

50+
private function getLogIterator() {
51+
$dateFormat = $this->config->getSystemValue('logdateformat', \DateTime::ISO8601);
52+
$handle = fopen(\OC_Log_Owncloud::getLogFilePath(), 'rb');
53+
return new LogIterator($handle, $dateFormat);
54+
}
55+
5056
/**
5157
* @param int $count
5258
* @param int $offset
5359
* @return TemplateResponse
5460
*/
5561
public function get($count = 50, $offset = 0) {
56-
$iterator = new LogIterator(fopen(\OC_Log_Owncloud::getLogFilePath(), 'rb'));
62+
$iterator = $this->getLogIterator();
5763
return $this->responseFromIterator($iterator, $count, $offset);
5864
}
5965

@@ -64,7 +70,7 @@ public function get($count = 50, $offset = 0) {
6470
* @return TemplateResponse
6571
*/
6672
public function search($query = '', $count = 50, $offset = 0) {
67-
$iterator = new LogIterator(fopen(\OC_Log_Owncloud::getLogFilePath(), 'rb'));
73+
$iterator = $this->getLogIterator();
6874
$iterator = new SearchFilter($iterator, $query);
6975
return $this->responseFromIterator($iterator, $count, $offset);
7076
}

log/logiterator.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ class LogIterator implements \Iterator {
3939

4040
private $currentKey = -1;
4141

42+
/**
43+
* @var string
44+
*/
45+
private $dateFormat;
46+
4247
/**
4348
* @param resource $handle
49+
* @param string $dateFormat
4450
*/
45-
public function __construct($handle) {
51+
public function __construct($handle, $dateFormat) {
4652
$this->handle = $handle;
53+
$this->dateFormat = $dateFormat;
4754
$this->rewind();
4855
$this->next();
4956
}
@@ -55,7 +62,12 @@ function rewind() {
5562
}
5663

5764
function current() {
58-
return json_decode($this->lastLine);
65+
$entry = json_decode($this->lastLine, true);
66+
if ($this->dateFormat !== \DateTime::ISO8601) {
67+
$time = \DateTime::createFromFormat($this->dateFormat, $entry['time']);
68+
$entry['time'] = $time->format(\DateTime::ISO8601);
69+
}
70+
return $entry;
5971
}
6072

6173
function key() {

0 commit comments

Comments
 (0)