Completed
Push — master ( a33877...0f03a8 )
by
unknown
41:16 queued 15s
created
lib/private/Log/LogDetails.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -8,92 +8,92 @@
 block discarded – undo
8 8
 use OC\SystemConfig;
9 9
 
10 10
 abstract class LogDetails {
11
-	public function __construct(
12
-		private SystemConfig $config,
13
-	) {
14
-	}
11
+    public function __construct(
12
+        private SystemConfig $config,
13
+    ) {
14
+    }
15 15
 
16
-	public function logDetails(string $app, $message, int $level): array {
17
-		// default to ISO8601
18
-		$format = $this->config->getValue('logdateformat', \DateTimeInterface::ATOM);
19
-		$logTimeZone = $this->config->getValue('logtimezone', 'UTC');
20
-		try {
21
-			$timezone = new \DateTimeZone($logTimeZone);
22
-		} catch (\Exception $e) {
23
-			$timezone = new \DateTimeZone('UTC');
24
-		}
25
-		$time = \DateTime::createFromFormat('U.u', number_format(microtime(true), 4, '.', ''));
26
-		if ($time === false) {
27
-			$time = new \DateTime('now', $timezone);
28
-		} else {
29
-			// apply timezone if $time is created from UNIX timestamp
30
-			$time->setTimezone($timezone);
31
-		}
32
-		$request = \OC::$server->getRequest();
33
-		$reqId = $request->getId();
34
-		$remoteAddr = $request->getRemoteAddress();
35
-		// remove username/passwords from URLs before writing the to the log file
36
-		$time = $time->format($format);
37
-		$url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
38
-		$method = is_string($request->getMethod()) ? $request->getMethod() : '--';
39
-		if ($this->config->getValue('installed', false)) {
40
-			$user = \OC_User::getUser() ?: '--';
41
-		} else {
42
-			$user = '--';
43
-		}
44
-		$userAgent = $request->getHeader('User-Agent');
45
-		if ($userAgent === '') {
46
-			$userAgent = '--';
47
-		}
48
-		$version = $this->config->getValue('version', '');
49
-		$entry = compact(
50
-			'reqId',
51
-			'level',
52
-			'time',
53
-			'remoteAddr',
54
-			'user',
55
-			'app',
56
-			'method',
57
-			'url',
58
-			'message',
59
-			'userAgent',
60
-			'version'
61
-		);
62
-		$clientReqId = $request->getHeader('X-Request-Id');
63
-		if ($clientReqId !== '') {
64
-			$entry['clientReqId'] = $clientReqId;
65
-		}
16
+    public function logDetails(string $app, $message, int $level): array {
17
+        // default to ISO8601
18
+        $format = $this->config->getValue('logdateformat', \DateTimeInterface::ATOM);
19
+        $logTimeZone = $this->config->getValue('logtimezone', 'UTC');
20
+        try {
21
+            $timezone = new \DateTimeZone($logTimeZone);
22
+        } catch (\Exception $e) {
23
+            $timezone = new \DateTimeZone('UTC');
24
+        }
25
+        $time = \DateTime::createFromFormat('U.u', number_format(microtime(true), 4, '.', ''));
26
+        if ($time === false) {
27
+            $time = new \DateTime('now', $timezone);
28
+        } else {
29
+            // apply timezone if $time is created from UNIX timestamp
30
+            $time->setTimezone($timezone);
31
+        }
32
+        $request = \OC::$server->getRequest();
33
+        $reqId = $request->getId();
34
+        $remoteAddr = $request->getRemoteAddress();
35
+        // remove username/passwords from URLs before writing the to the log file
36
+        $time = $time->format($format);
37
+        $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
38
+        $method = is_string($request->getMethod()) ? $request->getMethod() : '--';
39
+        if ($this->config->getValue('installed', false)) {
40
+            $user = \OC_User::getUser() ?: '--';
41
+        } else {
42
+            $user = '--';
43
+        }
44
+        $userAgent = $request->getHeader('User-Agent');
45
+        if ($userAgent === '') {
46
+            $userAgent = '--';
47
+        }
48
+        $version = $this->config->getValue('version', '');
49
+        $entry = compact(
50
+            'reqId',
51
+            'level',
52
+            'time',
53
+            'remoteAddr',
54
+            'user',
55
+            'app',
56
+            'method',
57
+            'url',
58
+            'message',
59
+            'userAgent',
60
+            'version'
61
+        );
62
+        $clientReqId = $request->getHeader('X-Request-Id');
63
+        if ($clientReqId !== '') {
64
+            $entry['clientReqId'] = $clientReqId;
65
+        }
66 66
 
67
-		if (is_array($message)) {
68
-			// Exception messages are extracted and the exception is put into a separate field
69
-			// anything else modern is split to 'message' (string) and
70
-			// data (array) fields
71
-			if (array_key_exists('Exception', $message)) {
72
-				$entry['exception'] = $message;
73
-				$entry['message'] = $message['CustomMessage'] !== '--' ? $message['CustomMessage'] : $message['Message'];
74
-			} else {
75
-				$entry['message'] = $message['message'] ?? '(no message provided)';
76
-				unset($message['message']);
77
-				$entry['data'] = $message;
78
-			}
79
-		}
67
+        if (is_array($message)) {
68
+            // Exception messages are extracted and the exception is put into a separate field
69
+            // anything else modern is split to 'message' (string) and
70
+            // data (array) fields
71
+            if (array_key_exists('Exception', $message)) {
72
+                $entry['exception'] = $message;
73
+                $entry['message'] = $message['CustomMessage'] !== '--' ? $message['CustomMessage'] : $message['Message'];
74
+            } else {
75
+                $entry['message'] = $message['message'] ?? '(no message provided)';
76
+                unset($message['message']);
77
+                $entry['data'] = $message;
78
+            }
79
+        }
80 80
 
81
-		return $entry;
82
-	}
81
+        return $entry;
82
+    }
83 83
 
84
-	public function logDetailsAsJSON(string $app, $message, int $level): string {
85
-		$entry = $this->logDetails($app, $message, $level);
86
-		// PHP's json_encode only accept proper UTF-8 strings, loop over all
87
-		// elements to ensure that they are properly UTF-8 compliant or convert
88
-		// them manually.
89
-		foreach ($entry as $key => $value) {
90
-			if (is_string($value)) {
91
-				$testEncode = json_encode($value, JSON_UNESCAPED_SLASHES);
92
-				if ($testEncode === false) {
93
-					$entry[$key] = mb_convert_encoding($value, 'UTF-8', mb_detect_encoding($value));
94
-				}
95
-			}
96
-		}
97
-		return json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
98
-	}
84
+    public function logDetailsAsJSON(string $app, $message, int $level): string {
85
+        $entry = $this->logDetails($app, $message, $level);
86
+        // PHP's json_encode only accept proper UTF-8 strings, loop over all
87
+        // elements to ensure that they are properly UTF-8 compliant or convert
88
+        // them manually.
89
+        foreach ($entry as $key => $value) {
90
+            if (is_string($value)) {
91
+                $testEncode = json_encode($value, JSON_UNESCAPED_SLASHES);
92
+                if ($testEncode === false) {
93
+                    $entry[$key] = mb_convert_encoding($value, 'UTF-8', mb_detect_encoding($value));
94
+                }
95
+            }
96
+        }
97
+        return json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
98
+    }
99 99
 }
Please login to merge, or discard this patch.