Log more information by default

This modifies the logger to add the following logging information by default:

- Request Method
- Request URL
- Current user
This commit is contained in:
Lukas Reschke 2016-03-21 15:21:22 +01:00
parent 86581f6626
commit 7adae4476f
1 changed files with 15 additions and 8 deletions

View File

@ -88,14 +88,21 @@ class OC_Log_Owncloud {
$remoteAddr = $request->getRemoteAddress();
// remove username/passwords from URLs before writing the to the log file
$time = $time->format($format);
$minLevel=min($config->getValue( "loglevel", \OCP\Util::WARN ), \OCP\Util::ERROR);
if($minLevel == \OCP\Util::DEBUG) {
$url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '--';
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '--';
$entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time', 'method', 'url');
} else {
$entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time');
}
$url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
$method = is_string($request->getMethod()) ? $request->getMethod() : '--';
$userObj = \OC::$server->getUserSession()->getUser();
$user = !is_null($userObj) ? $userObj->getUID() : '--';
$entry = compact(
'reqId',
'remoteAddr',
'app',
'message',
'level',
'time',
'method',
'url',
'user'
);
$entry = json_encode($entry);
$handle = @fopen(self::$logFile, 'a');
@chmod(self::$logFile, 0640);