blob: 6e5bf171ba2580d0da1031fc46f3ac42a06a6bc6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<?php
class FreshRSS_LogDAO {
private static function logPath(): string {
return USERS_PATH . '/' . (Minz_User::name() ?? Minz_User::INTERNAL_USER) . '/' . LOG_FILENAME;
}
/** @return array<FreshRSS_Log> */
public static function lines(): array {
$logs = array();
$handle = @fopen(self::logPath(), 'r');
if ($handle) {
while (($line = fgets($handle)) !== false) {
if (preg_match('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) {
$myLog = new FreshRSS_Log ();
$myLog->_date($matches[1]);
$myLog->_level($matches[2]);
$myLog->_info($matches[3]);
$logs[] = $myLog;
}
}
fclose($handle);
}
return array_reverse($logs);
}
public static function truncate(): void {
file_put_contents(self::logPath(), '');
if (FreshRSS_Auth::hasAccess('admin')) {
file_put_contents(ADMIN_LOG, '');
file_put_contents(API_LOG, '');
file_put_contents(PSHB_LOG, '');
}
}
}
|