Passed
Push — master ( 4a52d9...223a91 )
by Morris
11:47 queued 10s
created
lib/private/Log/Syslog.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -30,31 +30,31 @@
 block discarded – undo
30 30
 use OCP\Log\IWriter;
31 31
 
32 32
 class Syslog extends LogDetails implements IWriter {
33
-	protected $levels = [
34
-		ILogger::DEBUG => LOG_DEBUG,
35
-		ILogger::INFO => LOG_INFO,
36
-		ILogger::WARN => LOG_WARNING,
37
-		ILogger::ERROR => LOG_ERR,
38
-		ILogger::FATAL => LOG_CRIT,
39
-	];
33
+    protected $levels = [
34
+        ILogger::DEBUG => LOG_DEBUG,
35
+        ILogger::INFO => LOG_INFO,
36
+        ILogger::WARN => LOG_WARNING,
37
+        ILogger::ERROR => LOG_ERR,
38
+        ILogger::FATAL => LOG_CRIT,
39
+    ];
40 40
 
41
-	public function __construct(SystemConfig $config) {
42
-		parent::__construct($config);
43
-		openlog($config->getSystemValue('syslog_tag', 'Nextcloud'), LOG_PID | LOG_CONS, LOG_USER);
44
-	}
41
+    public function __construct(SystemConfig $config) {
42
+        parent::__construct($config);
43
+        openlog($config->getSystemValue('syslog_tag', 'Nextcloud'), LOG_PID | LOG_CONS, LOG_USER);
44
+    }
45 45
 
46
-	public function __destruct() {
47
-		closelog();
48
-	}
46
+    public function __destruct() {
47
+        closelog();
48
+    }
49 49
 
50
-	/**
51
-	 * write a message in the log
52
-	 * @param string $app
53
-	 * @param string $message
54
-	 * @param int $level
55
-	 */
56
-	public function write(string $app, $message, int $level) {
57
-		$syslog_level = $this->levels[$level];
58
-		syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level));
59
-	}
50
+    /**
51
+     * write a message in the log
52
+     * @param string $app
53
+     * @param string $message
54
+     * @param int $level
55
+     */
56
+    public function write(string $app, $message, int $level) {
57
+        $syslog_level = $this->levels[$level];
58
+        syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level));
59
+    }
60 60
 }
Please login to merge, or discard this patch.
lib/private/Log/LogDetails.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -27,75 +27,75 @@
 block discarded – undo
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);
94
-				if($testEncode === false) {
95
-					$entry[$key] = utf8_encode($value);
96
-				}
97
-			}
98
-		}
99
-		return json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR);
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);
94
+                if($testEncode === false) {
95
+                    $entry[$key] = utf8_encode($value);
96
+                }
97
+            }
98
+        }
99
+        return json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR);
100
+    }
101 101
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
94
-				if($testEncode === false) {
94
+				if ($testEncode === false) {
95 95
 					$entry[$key] = utf8_encode($value);
96 96
 				}
97 97
 			}
Please login to merge, or discard this patch.
lib/private/Log/File.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -48,110 +48,110 @@
 block discarded – undo
48 48
  */
49 49
 
50 50
 class File extends LogDetails implements IWriter, IFileBased {
51
-	/** @var string */
52
-	protected $logFile;
53
-	/** @var int */
54
-	protected $logFileMode;
55
-	/** @var SystemConfig */
56
-	private $config;
51
+    /** @var string */
52
+    protected $logFile;
53
+    /** @var int */
54
+    protected $logFileMode;
55
+    /** @var SystemConfig */
56
+    private $config;
57 57
 
58
-	public function __construct(string $path, string $fallbackPath = '', SystemConfig $config) {
59
-		parent::__construct($config);
60
-		$this->logFile = $path;
61
-		if (!file_exists($this->logFile)) {
62
-			if(
63
-				(
64
-					!is_writable(dirname($this->logFile))
65
-					|| !touch($this->logFile)
66
-				)
67
-				&& $fallbackPath !== ''
68
-			) {
69
-				$this->logFile = $fallbackPath;
70
-			}
71
-		}
72
-		$this->config = $config;
73
-		$this->logFileMode = $config->getValue('logfilemode', 0640);
74
-	}
58
+    public function __construct(string $path, string $fallbackPath = '', SystemConfig $config) {
59
+        parent::__construct($config);
60
+        $this->logFile = $path;
61
+        if (!file_exists($this->logFile)) {
62
+            if(
63
+                (
64
+                    !is_writable(dirname($this->logFile))
65
+                    || !touch($this->logFile)
66
+                )
67
+                && $fallbackPath !== ''
68
+            ) {
69
+                $this->logFile = $fallbackPath;
70
+            }
71
+        }
72
+        $this->config = $config;
73
+        $this->logFileMode = $config->getValue('logfilemode', 0640);
74
+    }
75 75
 
76
-	/**
77
-	 * write a message in the log
78
-	 * @param string $app
79
-	 * @param string|array $message
80
-	 * @param int $level
81
-	 */
82
-	public function write(string $app, $message, int $level) {
83
-		$entry = $this->logDetailsAsJSON($app, $message, $level);
84
-		$handle = @fopen($this->logFile, 'a');
85
-		if ($this->logFileMode > 0 && (fileperms($this->logFile) & 0777) != $this->logFileMode) {
86
-			@chmod($this->logFile, $this->logFileMode);
87
-		}
88
-		if ($handle) {
89
-			fwrite($handle, $entry."\n");
90
-			fclose($handle);
91
-		} else {
92
-			// Fall back to error_log
93
-			error_log($entry);
94
-		}
95
-		if (php_sapi_name() === 'cli-server') {
96
-			if (!\is_string($message)) {
97
-				$message = json_encode($message);
98
-			}
99
-			error_log($message, 4);
100
-		}
101
-	}
76
+    /**
77
+     * write a message in the log
78
+     * @param string $app
79
+     * @param string|array $message
80
+     * @param int $level
81
+     */
82
+    public function write(string $app, $message, int $level) {
83
+        $entry = $this->logDetailsAsJSON($app, $message, $level);
84
+        $handle = @fopen($this->logFile, 'a');
85
+        if ($this->logFileMode > 0 && (fileperms($this->logFile) & 0777) != $this->logFileMode) {
86
+            @chmod($this->logFile, $this->logFileMode);
87
+        }
88
+        if ($handle) {
89
+            fwrite($handle, $entry."\n");
90
+            fclose($handle);
91
+        } else {
92
+            // Fall back to error_log
93
+            error_log($entry);
94
+        }
95
+        if (php_sapi_name() === 'cli-server') {
96
+            if (!\is_string($message)) {
97
+                $message = json_encode($message);
98
+            }
99
+            error_log($message, 4);
100
+        }
101
+    }
102 102
 
103
-	/**
104
-	 * get entries from the log in reverse chronological order
105
-	 * @param int $limit
106
-	 * @param int $offset
107
-	 * @return array
108
-	 */
109
-	public function getEntries(int $limit=50, int $offset=0):array {
110
-		$minLevel = $this->config->getValue("loglevel", ILogger::WARN);
111
-		$entries = array();
112
-		$handle = @fopen($this->logFile, 'rb');
113
-		if ($handle) {
114
-			fseek($handle, 0, SEEK_END);
115
-			$pos = ftell($handle);
116
-			$line = '';
117
-			$entriesCount = 0;
118
-			$lines = 0;
119
-			// Loop through each character of the file looking for new lines
120
-			while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) {
121
-				fseek($handle, $pos);
122
-				$ch = fgetc($handle);
123
-				if ($ch == "\n" || $pos == 0) {
124
-					if ($line != '') {
125
-						// Add the first character if at the start of the file,
126
-						// because it doesn't hit the else in the loop
127
-						if ($pos == 0) {
128
-							$line = $ch.$line;
129
-						}
130
-						$entry = json_decode($line);
131
-						// Add the line as an entry if it is passed the offset and is equal or above the log level
132
-						if ($entry->level >= $minLevel) {
133
-							$lines++;
134
-							if ($lines > $offset) {
135
-								$entries[] = $entry;
136
-								$entriesCount++;
137
-							}
138
-						}
139
-						$line = '';
140
-					}
141
-				} else {
142
-					$line = $ch.$line;
143
-				}
144
-				$pos--;
145
-			}
146
-			fclose($handle);
147
-		}
148
-		return $entries;
149
-	}
103
+    /**
104
+     * get entries from the log in reverse chronological order
105
+     * @param int $limit
106
+     * @param int $offset
107
+     * @return array
108
+     */
109
+    public function getEntries(int $limit=50, int $offset=0):array {
110
+        $minLevel = $this->config->getValue("loglevel", ILogger::WARN);
111
+        $entries = array();
112
+        $handle = @fopen($this->logFile, 'rb');
113
+        if ($handle) {
114
+            fseek($handle, 0, SEEK_END);
115
+            $pos = ftell($handle);
116
+            $line = '';
117
+            $entriesCount = 0;
118
+            $lines = 0;
119
+            // Loop through each character of the file looking for new lines
120
+            while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) {
121
+                fseek($handle, $pos);
122
+                $ch = fgetc($handle);
123
+                if ($ch == "\n" || $pos == 0) {
124
+                    if ($line != '') {
125
+                        // Add the first character if at the start of the file,
126
+                        // because it doesn't hit the else in the loop
127
+                        if ($pos == 0) {
128
+                            $line = $ch.$line;
129
+                        }
130
+                        $entry = json_decode($line);
131
+                        // Add the line as an entry if it is passed the offset and is equal or above the log level
132
+                        if ($entry->level >= $minLevel) {
133
+                            $lines++;
134
+                            if ($lines > $offset) {
135
+                                $entries[] = $entry;
136
+                                $entriesCount++;
137
+                            }
138
+                        }
139
+                        $line = '';
140
+                    }
141
+                } else {
142
+                    $line = $ch.$line;
143
+                }
144
+                $pos--;
145
+            }
146
+            fclose($handle);
147
+        }
148
+        return $entries;
149
+    }
150 150
 
151
-	/**
152
-	 * @return string
153
-	 */
154
-	public function getLogFilePath():string {
155
-		return $this->logFile;
156
-	}
151
+    /**
152
+     * @return string
153
+     */
154
+    public function getLogFilePath():string {
155
+        return $this->logFile;
156
+    }
157 157
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		parent::__construct($config);
60 60
 		$this->logFile = $path;
61 61
 		if (!file_exists($this->logFile)) {
62
-			if(
62
+			if (
63 63
 				(
64 64
 					!is_writable(dirname($this->logFile))
65 65
 					|| !touch($this->logFile)
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param int $offset
107 107
 	 * @return array
108 108
 	 */
109
-	public function getEntries(int $limit=50, int $offset=0):array {
109
+	public function getEntries(int $limit = 50, int $offset = 0):array {
110 110
 		$minLevel = $this->config->getValue("loglevel", ILogger::WARN);
111 111
 		$entries = array();
112 112
 		$handle = @fopen($this->logFile, 'rb');
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 			$entriesCount = 0;
118 118
 			$lines = 0;
119 119
 			// Loop through each character of the file looking for new lines
120
-			while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) {
120
+			while ($pos >= 0 && ($limit === null || $entriesCount < $limit)) {
121 121
 				fseek($handle, $pos);
122 122
 				$ch = fgetc($handle);
123 123
 				if ($ch == "\n" || $pos == 0) {
Please login to merge, or discard this patch.
lib/private/Log/Systemdlog.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -44,37 +44,37 @@
 block discarded – undo
44 44
 //     Syslog compatibility fields
45 45
 
46 46
 class Systemdlog extends LogDetails implements IWriter {
47
-	protected $levels = [
48
-		ILogger::DEBUG => 7,
49
-		ILogger::INFO => 6,
50
-		ILogger::WARN => 4,
51
-		ILogger::ERROR => 3,
52
-		ILogger::FATAL => 2,
53
-	];
47
+    protected $levels = [
48
+        ILogger::DEBUG => 7,
49
+        ILogger::INFO => 6,
50
+        ILogger::WARN => 4,
51
+        ILogger::ERROR => 3,
52
+        ILogger::FATAL => 2,
53
+    ];
54 54
 
55
-	protected $syslogId;
55
+    protected $syslogId;
56 56
 
57
-	public function __construct(SystemConfig $config) {
58
-		parent::__construct($config);
59
-		if(!function_exists('sd_journal_send')) {
60
-			throw new HintException(
61
-				'PHP extension php-systemd is not available.',
62
-				'Please install and enable PHP extension systemd if you wish to log to the Systemd journal.');
57
+    public function __construct(SystemConfig $config) {
58
+        parent::__construct($config);
59
+        if(!function_exists('sd_journal_send')) {
60
+            throw new HintException(
61
+                'PHP extension php-systemd is not available.',
62
+                'Please install and enable PHP extension systemd if you wish to log to the Systemd journal.');
63 63
 
64
-		}
65
-		$this->syslogId = $config->getValue('syslog_tag', 'Nextcloud');
66
-	}
64
+        }
65
+        $this->syslogId = $config->getValue('syslog_tag', 'Nextcloud');
66
+    }
67 67
 
68
-	/**
69
-	 * Write a message to the log.
70
-	 * @param string $app
71
-	 * @param string $message
72
-	 * @param int $level
73
-	 */
74
-	public function write(string $app, $message, int $level) {
75
-		$journal_level = $this->levels[$level];
76
-		sd_journal_send('PRIORITY='.$journal_level,
77
-				'SYSLOG_IDENTIFIER='.$this->syslogId,
78
-				'MESSAGE=' . $this->logDetailsAsJSON($app, $message, $level));
79
-	}
68
+    /**
69
+     * Write a message to the log.
70
+     * @param string $app
71
+     * @param string $message
72
+     * @param int $level
73
+     */
74
+    public function write(string $app, $message, int $level) {
75
+        $journal_level = $this->levels[$level];
76
+        sd_journal_send('PRIORITY='.$journal_level,
77
+                'SYSLOG_IDENTIFIER='.$this->syslogId,
78
+                'MESSAGE=' . $this->logDetailsAsJSON($app, $message, $level));
79
+    }
80 80
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 
57 57
 	public function __construct(SystemConfig $config) {
58 58
 		parent::__construct($config);
59
-		if(!function_exists('sd_journal_send')) {
59
+		if (!function_exists('sd_journal_send')) {
60 60
 			throw new HintException(
61 61
 				'PHP extension php-systemd is not available.',
62 62
 				'Please install and enable PHP extension systemd if you wish to log to the Systemd journal.');
@@ -75,6 +75,6 @@  discard block
 block discarded – undo
75 75
 		$journal_level = $this->levels[$level];
76 76
 		sd_journal_send('PRIORITY='.$journal_level,
77 77
 				'SYSLOG_IDENTIFIER='.$this->syslogId,
78
-				'MESSAGE=' . $this->logDetailsAsJSON($app, $message, $level));
78
+				'MESSAGE='.$this->logDetailsAsJSON($app, $message, $level));
79 79
 	}
80 80
 }
Please login to merge, or discard this patch.