@@ -27,75 +27,75 @@ |
||
27 | 27 | |
28 | 28 | abstract class LogDetails { |
29 | 29 | |
30 | - /** @var SystemConfig */ |
|
31 | - private $config; |
|
30 | + /** @var SystemConfig */ |
|
31 | + private $config; |
|
32 | 32 | |
33 | - public function __construct(SystemConfig $config) { |
|
34 | - $this->config = $config; |
|
35 | - } |
|
33 | + public function __construct(SystemConfig $config) { |
|
34 | + $this->config = $config; |
|
35 | + } |
|
36 | 36 | |
37 | - public function logDetails(string $app, $message, int $level): array { |
|
38 | - // default to ISO8601 |
|
39 | - $format = $this->config->getValue('logdateformat', \DateTime::ATOM); |
|
40 | - $logTimeZone = $this->config->getValue('logtimezone', 'UTC'); |
|
41 | - try { |
|
42 | - $timezone = new \DateTimeZone($logTimeZone); |
|
43 | - } catch (\Exception $e) { |
|
44 | - $timezone = new \DateTimeZone('UTC'); |
|
45 | - } |
|
46 | - $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); |
|
47 | - if ($time === false) { |
|
48 | - $time = new \DateTime(null, $timezone); |
|
49 | - } else { |
|
50 | - // apply timezone if $time is created from UNIX timestamp |
|
51 | - $time->setTimezone($timezone); |
|
52 | - } |
|
53 | - $request = \OC::$server->getRequest(); |
|
54 | - $reqId = $request->getId(); |
|
55 | - $remoteAddr = $request->getRemoteAddress(); |
|
56 | - // remove username/passwords from URLs before writing the to the log file |
|
57 | - $time = $time->format($format); |
|
58 | - $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; |
|
59 | - $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; |
|
60 | - if($this->config->getValue('installed', false)) { |
|
61 | - $user = \OC_User::getUser() ? \OC_User::getUser() : '--'; |
|
62 | - } else { |
|
63 | - $user = '--'; |
|
64 | - } |
|
65 | - $userAgent = $request->getHeader('User-Agent'); |
|
66 | - if ($userAgent === '') { |
|
67 | - $userAgent = '--'; |
|
68 | - } |
|
69 | - $version = $this->config->getValue('version', ''); |
|
70 | - $entry = compact( |
|
71 | - 'reqId', |
|
72 | - 'level', |
|
73 | - 'time', |
|
74 | - 'remoteAddr', |
|
75 | - 'user', |
|
76 | - 'app', |
|
77 | - 'method', |
|
78 | - 'url', |
|
79 | - 'message', |
|
80 | - 'userAgent', |
|
81 | - 'version' |
|
82 | - ); |
|
83 | - return $entry; |
|
84 | - } |
|
37 | + public function logDetails(string $app, $message, int $level): array { |
|
38 | + // default to ISO8601 |
|
39 | + $format = $this->config->getValue('logdateformat', \DateTime::ATOM); |
|
40 | + $logTimeZone = $this->config->getValue('logtimezone', 'UTC'); |
|
41 | + try { |
|
42 | + $timezone = new \DateTimeZone($logTimeZone); |
|
43 | + } catch (\Exception $e) { |
|
44 | + $timezone = new \DateTimeZone('UTC'); |
|
45 | + } |
|
46 | + $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); |
|
47 | + if ($time === false) { |
|
48 | + $time = new \DateTime(null, $timezone); |
|
49 | + } else { |
|
50 | + // apply timezone if $time is created from UNIX timestamp |
|
51 | + $time->setTimezone($timezone); |
|
52 | + } |
|
53 | + $request = \OC::$server->getRequest(); |
|
54 | + $reqId = $request->getId(); |
|
55 | + $remoteAddr = $request->getRemoteAddress(); |
|
56 | + // remove username/passwords from URLs before writing the to the log file |
|
57 | + $time = $time->format($format); |
|
58 | + $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; |
|
59 | + $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; |
|
60 | + if($this->config->getValue('installed', false)) { |
|
61 | + $user = \OC_User::getUser() ? \OC_User::getUser() : '--'; |
|
62 | + } else { |
|
63 | + $user = '--'; |
|
64 | + } |
|
65 | + $userAgent = $request->getHeader('User-Agent'); |
|
66 | + if ($userAgent === '') { |
|
67 | + $userAgent = '--'; |
|
68 | + } |
|
69 | + $version = $this->config->getValue('version', ''); |
|
70 | + $entry = compact( |
|
71 | + 'reqId', |
|
72 | + 'level', |
|
73 | + 'time', |
|
74 | + 'remoteAddr', |
|
75 | + 'user', |
|
76 | + 'app', |
|
77 | + 'method', |
|
78 | + 'url', |
|
79 | + 'message', |
|
80 | + 'userAgent', |
|
81 | + 'version' |
|
82 | + ); |
|
83 | + return $entry; |
|
84 | + } |
|
85 | 85 | |
86 | - public function logDetailsAsJSON(string $app, $message, int $level): string { |
|
87 | - $entry = $this->logDetails($app, $message, $level); |
|
88 | - // PHP's json_encode only accept proper UTF-8 strings, loop over all |
|
89 | - // elements to ensure that they are properly UTF-8 compliant or convert |
|
90 | - // them manually. |
|
91 | - foreach($entry as $key => $value) { |
|
92 | - if(is_string($value)) { |
|
93 | - $testEncode = json_encode($value, JSON_UNESCAPED_SLASHES); |
|
94 | - if($testEncode === false) { |
|
95 | - $entry[$key] = utf8_encode($value); |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - return json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES); |
|
100 | - } |
|
86 | + public function logDetailsAsJSON(string $app, $message, int $level): string { |
|
87 | + $entry = $this->logDetails($app, $message, $level); |
|
88 | + // PHP's json_encode only accept proper UTF-8 strings, loop over all |
|
89 | + // elements to ensure that they are properly UTF-8 compliant or convert |
|
90 | + // them manually. |
|
91 | + foreach($entry as $key => $value) { |
|
92 | + if(is_string($value)) { |
|
93 | + $testEncode = json_encode($value, JSON_UNESCAPED_SLASHES); |
|
94 | + if($testEncode === false) { |
|
95 | + $entry[$key] = utf8_encode($value); |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + return json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES); |
|
100 | + } |
|
101 | 101 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $time = $time->format($format); |
58 | 58 | $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; |
59 | 59 | $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; |
60 | - if($this->config->getValue('installed', false)) { |
|
60 | + if ($this->config->getValue('installed', false)) { |
|
61 | 61 | $user = \OC_User::getUser() ? \OC_User::getUser() : '--'; |
62 | 62 | } else { |
63 | 63 | $user = '--'; |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | // PHP's json_encode only accept proper UTF-8 strings, loop over all |
89 | 89 | // elements to ensure that they are properly UTF-8 compliant or convert |
90 | 90 | // them manually. |
91 | - foreach($entry as $key => $value) { |
|
92 | - if(is_string($value)) { |
|
91 | + foreach ($entry as $key => $value) { |
|
92 | + if (is_string($value)) { |
|
93 | 93 | $testEncode = json_encode($value, JSON_UNESCAPED_SLASHES); |
94 | - if($testEncode === false) { |
|
94 | + if ($testEncode === false) { |
|
95 | 95 | $entry[$key] = utf8_encode($value); |
96 | 96 | } |
97 | 97 | } |