Completed
Push — master ( 08cbd8...4395cf )
by Lukas
16:54 queued 03:37
created
lib/private/Log/File.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -40,150 +40,150 @@
 block discarded – undo
40 40
  */
41 41
 
42 42
 class File {
43
-	static protected $logFile;
43
+    static protected $logFile;
44 44
 
45
-	/**
46
-	 * Init class data
47
-	 */
48
-	public static function init() {
49
-		$systemConfig = \OC::$server->getSystemConfig();
50
-		$defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/nextcloud.log';
51
-		self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile);
45
+    /**
46
+     * Init class data
47
+     */
48
+    public static function init() {
49
+        $systemConfig = \OC::$server->getSystemConfig();
50
+        $defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/nextcloud.log';
51
+        self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile);
52 52
 
53
-		/**
54
-		 * Fall back to default log file if specified logfile does not exist
55
-		 * and can not be created.
56
-		 */
57
-		if (!file_exists(self::$logFile)) {
58
-			if(!is_writable(dirname(self::$logFile))) {
59
-				self::$logFile = $defaultLogFile;
60
-			} else {
61
-				if(!touch(self::$logFile)) {
62
-					self::$logFile = $defaultLogFile;
63
-				}
64
-			}
65
-		}
66
-	}
53
+        /**
54
+         * Fall back to default log file if specified logfile does not exist
55
+         * and can not be created.
56
+         */
57
+        if (!file_exists(self::$logFile)) {
58
+            if(!is_writable(dirname(self::$logFile))) {
59
+                self::$logFile = $defaultLogFile;
60
+            } else {
61
+                if(!touch(self::$logFile)) {
62
+                    self::$logFile = $defaultLogFile;
63
+                }
64
+            }
65
+        }
66
+    }
67 67
 
68
-	/**
69
-	 * write a message in the log
70
-	 * @param string $app
71
-	 * @param string $message
72
-	 * @param int $level
73
-	 */
74
-	public static function write($app, $message, $level) {
75
-		$config = \OC::$server->getSystemConfig();
68
+    /**
69
+     * write a message in the log
70
+     * @param string $app
71
+     * @param string $message
72
+     * @param int $level
73
+     */
74
+    public static function write($app, $message, $level) {
75
+        $config = \OC::$server->getSystemConfig();
76 76
 
77
-		// default to ISO8601
78
-		$format = $config->getValue('logdateformat', \DateTime::ATOM);
79
-		$logTimeZone = $config->getValue('logtimezone', 'UTC');
80
-		try {
81
-			$timezone = new \DateTimeZone($logTimeZone);
82
-		} catch (\Exception $e) {
83
-			$timezone = new \DateTimeZone('UTC');
84
-		}
85
-		$time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", ""));
86
-		if ($time === false) {
87
-			$time = new \DateTime(null, $timezone);
88
-		} else {
89
-			// apply timezone if $time is created from UNIX timestamp
90
-			$time->setTimezone($timezone);
91
-		}
92
-		$request = \OC::$server->getRequest();
93
-		$reqId = $request->getId();
94
-		$remoteAddr = $request->getRemoteAddress();
95
-		// remove username/passwords from URLs before writing the to the log file
96
-		$time = $time->format($format);
97
-		$url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
98
-		$method = is_string($request->getMethod()) ? $request->getMethod() : '--';
99
-		if($config->getValue('installed', false)) {
100
-			$user = (\OC_User::getUser()) ? \OC_User::getUser() : '--';
101
-		} else {
102
-			$user = '--';
103
-		}
104
-		$userAgent = $request->getHeader('User-Agent') ?: '--';
105
-		$version = $config->getValue('version', '');
106
-		$entry = compact(
107
-			'reqId',
108
-			'remoteAddr',
109
-			'app',
110
-			'message',
111
-			'level',
112
-			'time',
113
-			'method',
114
-			'url',
115
-			'user',
116
-			'userAgent',
117
-			'version'
118
-		);
119
-		$entry = json_encode($entry);
120
-		$handle = @fopen(self::$logFile, 'a');
121
-		@chmod(self::$logFile, 0640);
122
-		if ($handle) {
123
-			fwrite($handle, $entry."\n");
124
-			fclose($handle);
125
-		} else {
126
-			// Fall back to error_log
127
-			error_log($entry);
128
-		}
129
-		if (php_sapi_name() === 'cli-server') {
130
-			error_log($message, 4);
131
-		}
132
-	}
77
+        // default to ISO8601
78
+        $format = $config->getValue('logdateformat', \DateTime::ATOM);
79
+        $logTimeZone = $config->getValue('logtimezone', 'UTC');
80
+        try {
81
+            $timezone = new \DateTimeZone($logTimeZone);
82
+        } catch (\Exception $e) {
83
+            $timezone = new \DateTimeZone('UTC');
84
+        }
85
+        $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", ""));
86
+        if ($time === false) {
87
+            $time = new \DateTime(null, $timezone);
88
+        } else {
89
+            // apply timezone if $time is created from UNIX timestamp
90
+            $time->setTimezone($timezone);
91
+        }
92
+        $request = \OC::$server->getRequest();
93
+        $reqId = $request->getId();
94
+        $remoteAddr = $request->getRemoteAddress();
95
+        // remove username/passwords from URLs before writing the to the log file
96
+        $time = $time->format($format);
97
+        $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
98
+        $method = is_string($request->getMethod()) ? $request->getMethod() : '--';
99
+        if($config->getValue('installed', false)) {
100
+            $user = (\OC_User::getUser()) ? \OC_User::getUser() : '--';
101
+        } else {
102
+            $user = '--';
103
+        }
104
+        $userAgent = $request->getHeader('User-Agent') ?: '--';
105
+        $version = $config->getValue('version', '');
106
+        $entry = compact(
107
+            'reqId',
108
+            'remoteAddr',
109
+            'app',
110
+            'message',
111
+            'level',
112
+            'time',
113
+            'method',
114
+            'url',
115
+            'user',
116
+            'userAgent',
117
+            'version'
118
+        );
119
+        $entry = json_encode($entry);
120
+        $handle = @fopen(self::$logFile, 'a');
121
+        @chmod(self::$logFile, 0640);
122
+        if ($handle) {
123
+            fwrite($handle, $entry."\n");
124
+            fclose($handle);
125
+        } else {
126
+            // Fall back to error_log
127
+            error_log($entry);
128
+        }
129
+        if (php_sapi_name() === 'cli-server') {
130
+            error_log($message, 4);
131
+        }
132
+    }
133 133
 
134
-	/**
135
-	 * get entries from the log in reverse chronological order
136
-	 * @param int $limit
137
-	 * @param int $offset
138
-	 * @return array
139
-	 */
140
-	public static function getEntries($limit=50, $offset=0) {
141
-		self::init();
142
-		$minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", \OCP\Util::WARN);
143
-		$entries = array();
144
-		$handle = @fopen(self::$logFile, 'rb');
145
-		if ($handle) {
146
-			fseek($handle, 0, SEEK_END);
147
-			$pos = ftell($handle);
148
-			$line = '';
149
-			$entriesCount = 0;
150
-			$lines = 0;
151
-			// Loop through each character of the file looking for new lines
152
-			while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) {
153
-				fseek($handle, $pos);
154
-				$ch = fgetc($handle);
155
-				if ($ch == "\n" || $pos == 0) {
156
-					if ($line != '') {
157
-						// Add the first character if at the start of the file,
158
-						// because it doesn't hit the else in the loop
159
-						if ($pos == 0) {
160
-							$line = $ch.$line;
161
-						}
162
-						$entry = json_decode($line);
163
-						// Add the line as an entry if it is passed the offset and is equal or above the log level
164
-						if ($entry->level >= $minLevel) {
165
-							$lines++;
166
-							if ($lines > $offset) {
167
-								$entries[] = $entry;
168
-								$entriesCount++;
169
-							}
170
-						}
171
-						$line = '';
172
-					}
173
-				} else {
174
-					$line = $ch.$line;
175
-				}
176
-				$pos--;
177
-			}
178
-			fclose($handle);
179
-		}
180
-		return $entries;
181
-	}
134
+    /**
135
+     * get entries from the log in reverse chronological order
136
+     * @param int $limit
137
+     * @param int $offset
138
+     * @return array
139
+     */
140
+    public static function getEntries($limit=50, $offset=0) {
141
+        self::init();
142
+        $minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", \OCP\Util::WARN);
143
+        $entries = array();
144
+        $handle = @fopen(self::$logFile, 'rb');
145
+        if ($handle) {
146
+            fseek($handle, 0, SEEK_END);
147
+            $pos = ftell($handle);
148
+            $line = '';
149
+            $entriesCount = 0;
150
+            $lines = 0;
151
+            // Loop through each character of the file looking for new lines
152
+            while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) {
153
+                fseek($handle, $pos);
154
+                $ch = fgetc($handle);
155
+                if ($ch == "\n" || $pos == 0) {
156
+                    if ($line != '') {
157
+                        // Add the first character if at the start of the file,
158
+                        // because it doesn't hit the else in the loop
159
+                        if ($pos == 0) {
160
+                            $line = $ch.$line;
161
+                        }
162
+                        $entry = json_decode($line);
163
+                        // Add the line as an entry if it is passed the offset and is equal or above the log level
164
+                        if ($entry->level >= $minLevel) {
165
+                            $lines++;
166
+                            if ($lines > $offset) {
167
+                                $entries[] = $entry;
168
+                                $entriesCount++;
169
+                            }
170
+                        }
171
+                        $line = '';
172
+                    }
173
+                } else {
174
+                    $line = $ch.$line;
175
+                }
176
+                $pos--;
177
+            }
178
+            fclose($handle);
179
+        }
180
+        return $entries;
181
+    }
182 182
 
183
-	/**
184
-	 * @return string
185
-	 */
186
-	public static function getLogFilePath() {
187
-		return self::$logFile;
188
-	}
183
+    /**
184
+     * @return string
185
+     */
186
+    public static function getLogFilePath() {
187
+        return self::$logFile;
188
+    }
189 189
 }
Please login to merge, or discard this patch.