Move log level check to logger parent class
* remove duplicate code from child classes
This commit is contained in:
parent
c9921ec127
commit
892b5ceeeb
|
@ -172,7 +172,13 @@ class Log implements ILogger {
|
|||
// interpolate replacement values into the message and return
|
||||
$message = strtr($message, $replace);
|
||||
|
||||
$logger = $this->logger;
|
||||
call_user_func(array($logger, 'write'), $app, $message, $level);
|
||||
$config = \OC::$server->getSystemConfig();
|
||||
|
||||
$minLevel = min($config->getValue('loglevel', \OC_Log::WARN), \OC_Log::ERROR);
|
||||
|
||||
if ($level >= $minLevel) {
|
||||
$logger = $this->logger;
|
||||
call_user_func(array($logger, 'write'), $app, $message, $level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,7 @@ class OC_Log_Errorlog {
|
|||
* @param int $level
|
||||
*/
|
||||
public static function write($app, $message, $level) {
|
||||
$minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
|
||||
if ($level >= $minLevel) {
|
||||
error_log('[owncloud]['.$app.'] '.$message);
|
||||
}
|
||||
error_log('[owncloud]['.$app.']['.$level.'] '.$message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,40 +69,40 @@ class OC_Log_Owncloud {
|
|||
* @param int $level
|
||||
*/
|
||||
public static function write($app, $message, $level) {
|
||||
$minLevel=min(OC_Config::getValue( "loglevel", OC_Log::WARN ), OC_Log::ERROR);
|
||||
if($level>=$minLevel) {
|
||||
// default to ISO8601
|
||||
$format = OC_Config::getValue('logdateformat', 'c');
|
||||
$logtimezone=OC_Config::getValue( "logtimezone", 'UTC' );
|
||||
try {
|
||||
$timezone = new DateTimeZone($logtimezone);
|
||||
} catch (Exception $e) {
|
||||
$timezone = new DateTimeZone('UTC');
|
||||
}
|
||||
$time = new DateTime(null, $timezone);
|
||||
$request = \OC::$server->getRequest();
|
||||
$reqId = $request->getId();
|
||||
$remoteAddr = $request->getRemoteAddress();
|
||||
// remove username/passwords from URLs before writing the to the log file
|
||||
$time = $time->format($format);
|
||||
if($minLevel == OC_Log::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');
|
||||
}
|
||||
$entry = json_encode($entry);
|
||||
$handle = @fopen(self::$logFile, 'a');
|
||||
@chmod(self::$logFile, 0640);
|
||||
if ($handle) {
|
||||
fwrite($handle, $entry."\n");
|
||||
fclose($handle);
|
||||
} else {
|
||||
// Fall back to error_log
|
||||
error_log($entry);
|
||||
}
|
||||
$config = \OC::$server->getSystemConfig();
|
||||
|
||||
// default to ISO8601
|
||||
$format = $config->getValue('logdateformat', 'c');
|
||||
$logtimezone = $config->getValue( "logtimezone", 'UTC' );
|
||||
try {
|
||||
$timezone = new DateTimeZone($logtimezone);
|
||||
} catch (Exception $e) {
|
||||
$timezone = new DateTimeZone('UTC');
|
||||
}
|
||||
$time = new DateTime(null, $timezone);
|
||||
$request = \OC::$server->getRequest();
|
||||
$reqId = $request->getId();
|
||||
$remoteAddr = $request->getRemoteAddress();
|
||||
// remove username/passwords from URLs before writing the to the log file
|
||||
$time = $time->format($format);
|
||||
$minLevel=min($config->getValue( "loglevel", OC_Log::WARN ), OC_Log::ERROR);
|
||||
if($minLevel == OC_Log::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');
|
||||
}
|
||||
$entry = json_encode($entry);
|
||||
$handle = @fopen(self::$logFile, 'a');
|
||||
@chmod(self::$logFile, 0640);
|
||||
if ($handle) {
|
||||
fwrite($handle, $entry."\n");
|
||||
fclose($handle);
|
||||
} else {
|
||||
// Fall back to error_log
|
||||
error_log($entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,10 +47,7 @@ class OC_Log_Syslog {
|
|||
* @param int $level
|
||||
*/
|
||||
public static function write($app, $message, $level) {
|
||||
$minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
|
||||
if ($level >= $minLevel) {
|
||||
$syslog_level = self::$levels[$level];
|
||||
syslog($syslog_level, '{'.$app.'} '.$message);
|
||||
}
|
||||
$syslog_level = self::$levels[$level];
|
||||
syslog($syslog_level, '{'.$app.'} '.$message);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue