aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Log
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Log')
-rw-r--r--lib/private/Log/ErrorHandler.php32
-rw-r--r--lib/private/Log/Errorlog.php29
-rw-r--r--lib/private/Log/ExceptionSerializer.php75
-rw-r--r--lib/private/Log/File.php45
-rw-r--r--lib/private/Log/LogDetails.php35
-rw-r--r--lib/private/Log/LogFactory.php32
-rw-r--r--lib/private/Log/PsrLoggerAdapter.php171
-rw-r--r--lib/private/Log/Rotate.php49
-rw-r--r--lib/private/Log/Syslog.php34
-rw-r--r--lib/private/Log/Systemdlog.php29
10 files changed, 158 insertions, 373 deletions
diff --git a/lib/private/Log/ErrorHandler.php b/lib/private/Log/ErrorHandler.php
index e5e04182cd0..6597274a868 100644
--- a/lib/private/Log/ErrorHandler.php
+++ b/lib/private/Log/ErrorHandler.php
@@ -1,32 +1,10 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Log;
@@ -94,9 +72,9 @@ class ErrorHandler {
private static function errnoToLogLevel(int $errno): int {
return match ($errno) {
- E_USER_WARNING => ILogger::WARN,
+ E_WARNING, E_USER_WARNING => ILogger::WARN,
E_DEPRECATED, E_USER_DEPRECATED => ILogger::DEBUG,
- E_USER_NOTICE => ILogger::INFO,
+ E_NOTICE, E_USER_NOTICE => ILogger::INFO,
default => ILogger::ERROR,
};
}
diff --git a/lib/private/Log/Errorlog.php b/lib/private/Log/Errorlog.php
index aaea8234f27..6188bb70fd5 100644
--- a/lib/private/Log/Errorlog.php
+++ b/lib/private/Log/Errorlog.php
@@ -1,31 +1,12 @@
<?php
declare(strict_types=1);
-
/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Christian Kampka <christian@kampka.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-FileCopyrightText: 2014 Christian Kampka <christian@kampka.net>
+ * SPDX-License-Identifier: MIT
*/
-
namespace OC\Log;
use OC\SystemConfig;
@@ -45,6 +26,6 @@ class Errorlog extends LogDetails implements IWriter {
* @param string|array $message
*/
public function write(string $app, $message, int $level): void {
- error_log('[' . $this->tag . ']['.$app.']['.$level.'] '.$this->logDetailsAsJSON($app, $message, $level));
+ error_log('[' . $this->tag . '][' . $app . '][' . $level . '] ' . $this->logDetailsAsJSON($app, $message, $level));
}
}
diff --git a/lib/private/Log/ExceptionSerializer.php b/lib/private/Log/ExceptionSerializer.php
index 8b895bcb6be..af7c9e48435 100644
--- a/lib/private/Log/ExceptionSerializer.php
+++ b/lib/private/Log/ExceptionSerializer.php
@@ -1,34 +1,13 @@
<?php
+
/**
- * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Log;
use OC\Core\Controller\SetupController;
+use OC\Http\Client\Client;
use OC\Security\IdentityProof\Key;
use OC\Setup;
use OC\SystemConfig;
@@ -36,8 +15,9 @@ use OCA\Encryption\Controller\RecoveryController;
use OCA\Encryption\Controller\SettingsController;
use OCA\Encryption\Crypto\Crypt;
use OCA\Encryption\Crypto\Encryption;
-use OCA\Encryption\Hooks\UserHooks;
use OCA\Encryption\KeyManager;
+use OCA\Encryption\Listeners\UserEventsListener;
+use OCA\Encryption\Services\PassphraseService;
use OCA\Encryption\Session;
use OCP\HintException;
@@ -55,6 +35,7 @@ class ExceptionSerializer {
'validateUserPass',
'loginWithToken',
'{closure}',
+ '{closure:*',
'createSessionToken',
// Provisioning
@@ -129,6 +110,22 @@ class ExceptionSerializer {
Key::class => [
'__construct'
],
+ Client::class => [
+ 'request',
+ 'delete',
+ 'deleteAsync',
+ 'get',
+ 'getAsync',
+ 'head',
+ 'headAsync',
+ 'options',
+ 'optionsAsync',
+ 'patch',
+ 'post',
+ 'postAsync',
+ 'put',
+ 'putAsync',
+ ],
\Redis::class => [
'auth'
],
@@ -175,14 +172,16 @@ class ExceptionSerializer {
\OCA\Encryption\Users\Setup::class => [
'setupUser',
],
- UserHooks::class => [
- 'login',
- 'postCreateUser',
- 'postDeleteUser',
- 'prePasswordReset',
- 'postPasswordReset',
- 'preSetPassphrase',
- 'setPassphrase',
+ UserEventsListener::class => [
+ 'handle',
+ 'onUserCreated',
+ 'onUserLogin',
+ 'onBeforePasswordUpdated',
+ 'onPasswordUpdated',
+ 'onPasswordReset',
+ ],
+ PassphraseService::class => [
+ 'setPassphraseForUser',
],
];
@@ -203,7 +202,9 @@ class ExceptionSerializer {
return $this->editTrace($sensitiveValues, $traceLine);
}
foreach (self::methodsWithSensitiveParameters as $sensitiveMethod) {
- if (str_contains($traceLine['function'], $sensitiveMethod)) {
+ if (str_contains($traceLine['function'], $sensitiveMethod)
+ || (str_ends_with($sensitiveMethod, '*')
+ && str_starts_with($traceLine['function'], substr($sensitiveMethod, 0, -1)))) {
return $this->editTrace($sensitiveValues, $traceLine);
}
}
@@ -219,13 +220,13 @@ class ExceptionSerializer {
private function removeValuesFromArgs($args, $values): array {
$workArgs = [];
- foreach ($args as $arg) {
+ foreach ($args as $key => $arg) {
if (in_array($arg, $values, true)) {
$arg = self::SENSITIVE_VALUE_PLACEHOLDER;
} elseif (is_array($arg)) {
$arg = $this->removeValuesFromArgs($arg, $values);
}
- $workArgs[] = $arg;
+ $workArgs[$key] = $arg;
}
return $workArgs;
}
diff --git a/lib/private/Log/File.php b/lib/private/Log/File.php
index 328b0346985..ba428ba185b 100644
--- a/lib/private/Log/File.php
+++ b/lib/private/Log/File.php
@@ -1,38 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author duritong <peter.meier+github@immerda.ch>
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author J0WI <J0WI@users.noreply.github.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Michael Gapczynski <GapczynskiM@gmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Roland Tapken <roland@bitarbeiter.net>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Thomas Pulzer <t.pulzer@kniel.de>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Log;
@@ -84,7 +55,7 @@ class File extends LogDetails implements IWriter, IFileBased {
@chmod($this->logFile, $this->logFileMode);
}
if ($handle) {
- fwrite($handle, $entry."\n");
+ fwrite($handle, $entry . "\n");
fclose($handle);
} else {
// Fall back to error_log
@@ -102,7 +73,7 @@ class File extends LogDetails implements IWriter, IFileBased {
* get entries from the log in reverse chronological order
*/
public function getEntries(int $limit = 50, int $offset = 0): array {
- $minLevel = $this->config->getValue("loglevel", ILogger::WARN);
+ $minLevel = $this->config->getValue('loglevel', ILogger::WARN);
$entries = [];
$handle = @fopen($this->logFile, 'rb');
if ($handle) {
@@ -120,7 +91,7 @@ class File extends LogDetails implements IWriter, IFileBased {
// Add the first character if at the start of the file,
// because it doesn't hit the else in the loop
if ($pos == 0) {
- $line = $ch.$line;
+ $line = $ch . $line;
}
$entry = json_decode($line);
// Add the line as an entry if it is passed the offset and is equal or above the log level
@@ -134,7 +105,7 @@ class File extends LogDetails implements IWriter, IFileBased {
$line = '';
}
} else {
- $line = $ch.$line;
+ $line = $ch . $line;
}
$pos--;
}
diff --git a/lib/private/Log/LogDetails.php b/lib/private/Log/LogDetails.php
index ec88aa767fb..6063b25cef9 100644
--- a/lib/private/Log/LogDetails.php
+++ b/lib/private/Log/LogDetails.php
@@ -1,27 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Thomas Citharel <nextcloud@tcit.fr>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Log;
@@ -42,7 +23,7 @@ abstract class LogDetails {
} catch (\Exception $e) {
$timezone = new \DateTimeZone('UTC');
}
- $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", ""));
+ $time = \DateTime::createFromFormat('U.u', number_format(microtime(true), 4, '.', ''));
if ($time === false) {
$time = new \DateTime('now', $timezone);
} else {
@@ -57,7 +38,7 @@ abstract class LogDetails {
$url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
$method = is_string($request->getMethod()) ? $request->getMethod() : '--';
if ($this->config->getValue('installed', false)) {
- $user = \OC_User::getUser() ? \OC_User::getUser() : '--';
+ $user = \OC_User::getUser() ?: '--';
} else {
$user = '--';
}
@@ -79,6 +60,10 @@ abstract class LogDetails {
'userAgent',
'version'
);
+ $clientReqId = $request->getHeader('X-Request-Id');
+ if ($clientReqId !== '') {
+ $entry['clientReqId'] = $clientReqId;
+ }
if (is_array($message)) {
// Exception messages are extracted and the exception is put into a separate field
@@ -106,7 +91,7 @@ abstract class LogDetails {
if (is_string($value)) {
$testEncode = json_encode($value, JSON_UNESCAPED_SLASHES);
if ($testEncode === false) {
- $entry[$key] = utf8_encode($value);
+ $entry[$key] = mb_convert_encoding($value, 'UTF-8', mb_detect_encoding($value));
}
}
}
diff --git a/lib/private/Log/LogFactory.php b/lib/private/Log/LogFactory.php
index c395c31eb98..ee6054b81f8 100644
--- a/lib/private/Log/LogFactory.php
+++ b/lib/private/Log/LogFactory.php
@@ -1,32 +1,13 @@
<?php
+
/**
- * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Johannes Ernst <jernst@indiecomputing.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Log;
use OC\Log;
use OC\SystemConfig;
-use OCP\ILogger;
use OCP\IServerContainer;
use OCP\Log\ILogFactory;
use OCP\Log\IWriter;
@@ -52,11 +33,6 @@ class LogFactory implements ILogFactory {
};
}
- public function getCustomLogger(string $path): ILogger {
- $log = $this->buildLogFile($path);
- return new Log($log, $this->systemConfig);
- }
-
protected function createNewLogger(string $type, string $tag, string $path): IWriter {
return match (strtolower($type)) {
'errorlog' => new Errorlog($this->systemConfig, $tag),
@@ -74,7 +50,7 @@ class LogFactory implements ILogFactory {
}
protected function buildLogFile(string $logFile = ''): File {
- $defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT.'/data').'/nextcloud.log';
+ $defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log';
if ($logFile === '') {
$logFile = $this->systemConfig->getValue('logfile', $defaultLogFile);
}
diff --git a/lib/private/Log/PsrLoggerAdapter.php b/lib/private/Log/PsrLoggerAdapter.php
index 12254bfc67f..79e9d4d9621 100644
--- a/lib/private/Log/PsrLoggerAdapter.php
+++ b/lib/private/Log/PsrLoggerAdapter.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Log;
@@ -31,6 +14,7 @@ use OCP\ILogger;
use OCP\Log\IDataLogger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface;
+use Psr\Log\LogLevel;
use Throwable;
use function array_key_exists;
use function array_merge;
@@ -41,6 +25,20 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
) {
}
+ public static function logLevelToInt(string $level): int {
+ return match ($level) {
+ LogLevel::ALERT => ILogger::ERROR,
+ LogLevel::CRITICAL => ILogger::ERROR,
+ LogLevel::DEBUG => ILogger::DEBUG,
+ LogLevel::EMERGENCY => ILogger::FATAL,
+ LogLevel::ERROR => ILogger::ERROR,
+ LogLevel::INFO => ILogger::INFO,
+ LogLevel::NOTICE => ILogger::INFO,
+ LogLevel::WARNING => ILogger::WARN,
+ default => throw new InvalidArgumentException('Unsupported custom log level'),
+ };
+ }
+
public function setEventDispatcher(IEventDispatcher $eventDispatcher): void {
$this->logger->setEventDispatcher($eventDispatcher);
}
@@ -52,20 +50,11 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
/**
* System is unusable.
*
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*/
public function emergency($message, array $context = []): void {
- if ($this->containsThrowable($context)) {
- $this->logger->logException($context['exception'], array_merge(
- [
- 'message' => $message,
- 'level' => ILogger::FATAL,
- ],
- $context
- ));
- } else {
- $this->logger->emergency($message, $context);
- }
+ $this->log(LogLevel::EMERGENCY, (string)$message, $context);
}
/**
@@ -74,20 +63,11 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*/
public function alert($message, array $context = []): void {
- if ($this->containsThrowable($context)) {
- $this->logger->logException($context['exception'], array_merge(
- [
- 'message' => $message,
- 'level' => ILogger::ERROR,
- ],
- $context
- ));
- } else {
- $this->logger->alert($message, $context);
- }
+ $this->log(LogLevel::ALERT, (string)$message, $context);
}
/**
@@ -95,40 +75,22 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
*
* Example: Application component unavailable, unexpected exception.
*
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*/
public function critical($message, array $context = []): void {
- if ($this->containsThrowable($context)) {
- $this->logger->logException($context['exception'], array_merge(
- [
- 'message' => $message,
- 'level' => ILogger::ERROR,
- ],
- $context
- ));
- } else {
- $this->logger->critical($message, $context);
- }
+ $this->log(LogLevel::CRITICAL, (string)$message, $context);
}
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*/
public function error($message, array $context = []): void {
- if ($this->containsThrowable($context)) {
- $this->logger->logException($context['exception'], array_merge(
- [
- 'message' => $message,
- 'level' => ILogger::ERROR,
- ],
- $context
- ));
- } else {
- $this->logger->error($message, $context);
- }
+ $this->log(LogLevel::ERROR, (string)$message, $context);
}
/**
@@ -137,39 +99,21 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*/
public function warning($message, array $context = []): void {
- if ($this->containsThrowable($context)) {
- $this->logger->logException($context['exception'], array_merge(
- [
- 'message' => $message,
- 'level' => ILogger::WARN,
- ],
- $context
- ));
- } else {
- $this->logger->warning($message, $context);
- }
+ $this->log(LogLevel::WARNING, (string)$message, $context);
}
/**
* Normal but significant events.
*
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*/
public function notice($message, array $context = []): void {
- if ($this->containsThrowable($context)) {
- $this->logger->logException($context['exception'], array_merge(
- [
- 'message' => $message,
- 'level' => ILogger::INFO,
- ],
- $context
- ));
- } else {
- $this->logger->notice($message, $context);
- }
+ $this->log(LogLevel::NOTICE, (string)$message, $context);
}
/**
@@ -177,63 +121,52 @@ final class PsrLoggerAdapter implements LoggerInterface, IDataLogger {
*
* Example: User logs in, SQL logs.
*
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*/
public function info($message, array $context = []): void {
- if ($this->containsThrowable($context)) {
- $this->logger->logException($context['exception'], array_merge(
- [
- 'message' => $message,
- 'level' => ILogger::INFO,
- ],
- $context
- ));
- } else {
- $this->logger->info($message, $context);
- }
+ $this->log(LogLevel::INFO, (string)$message, $context);
}
/**
* Detailed debug information.
*
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*/
public function debug($message, array $context = []): void {
- if ($this->containsThrowable($context)) {
- $this->logger->logException($context['exception'], array_merge(
- [
- 'message' => $message,
- 'level' => ILogger::DEBUG,
- ],
- $context
- ));
- } else {
- $this->logger->debug($message, $context);
- }
+ $this->log(LogLevel::DEBUG, (string)$message, $context);
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
- * @param string $message
+ * @param $message
+ * @param mixed[] $context
*
* @throws InvalidArgumentException
*/
public function log($level, $message, array $context = []): void {
+ if (is_string($level)) {
+ $level = self::logLevelToInt($level);
+ }
+ if (isset($context['level']) && is_string($context['level'])) {
+ $context['level'] = self::logLevelToInt($context['level']);
+ }
if (!is_int($level) || $level < ILogger::DEBUG || $level > ILogger::FATAL) {
- throw new InvalidArgumentException('Nextcloud allows only integer log levels');
+ throw new InvalidArgumentException('Unsupported custom log level');
}
if ($this->containsThrowable($context)) {
$this->logger->logException($context['exception'], array_merge(
[
- 'message' => $message,
+ 'message' => (string)$message,
'level' => $level,
],
$context
));
} else {
- $this->logger->log($level, $message, $context);
+ $this->logger->log($level, (string)$message, $context);
}
}
diff --git a/lib/private/Log/Rotate.php b/lib/private/Log/Rotate.php
index efe548b7783..ee1593b87ac 100644
--- a/lib/private/Log/Rotate.php
+++ b/lib/private/Log/Rotate.php
@@ -1,30 +1,17 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Log;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
+use OCP\IConfig;
use OCP\Log\RotationTrait;
+use Psr\Log\LoggerInterface;
/**
* This rotates the current logfile to a new name, this way the total log usage
@@ -32,18 +19,24 @@ use OCP\Log\RotationTrait;
* For more professional log management set the 'logfile' config to a different
* location and manage that with your own tools.
*/
-class Rotate extends \OCP\BackgroundJob\Job {
+class Rotate extends TimedJob {
use RotationTrait;
- public function run($dummy): void {
- $systemConfig = \OC::$server->getSystemConfig();
- $this->filePath = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log');
+ public function __construct(ITimeFactory $time) {
+ parent::__construct($time);
+
+ $this->setInterval(3600);
+ }
+
+ public function run($argument): void {
+ $config = \OCP\Server::get(IConfig::class);
+ $this->filePath = $config->getSystemValueString('logfile', $config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log');
- $this->maxSize = \OC::$server->getConfig()->getSystemValueInt('log_rotate_size', 100 * 1024 * 1024);
+ $this->maxSize = $config->getSystemValueInt('log_rotate_size', 100 * 1024 * 1024);
if ($this->shouldRotateBySize()) {
$rotatedFile = $this->rotate();
- $msg = 'Log file "'.$this->filePath.'" was over '.$this->maxSize.' bytes, moved to "'.$rotatedFile.'"';
- \OC::$server->getLogger()->info($msg, ['app' => Rotate::class]);
+ $msg = 'Log file "' . $this->filePath . '" was over ' . $this->maxSize . ' bytes, moved to "' . $rotatedFile . '"';
+ \OCP\Server::get(LoggerInterface::class)->info($msg, ['app' => Rotate::class]);
}
}
}
diff --git a/lib/private/Log/Syslog.php b/lib/private/Log/Syslog.php
index 5f220ee1eb7..46214599eb8 100644
--- a/lib/private/Log/Syslog.php
+++ b/lib/private/Log/Syslog.php
@@ -1,27 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Log;
@@ -38,15 +20,18 @@ class Syslog extends LogDetails implements IWriter {
ILogger::FATAL => LOG_CRIT,
];
+ private string $tag;
+
public function __construct(
SystemConfig $config,
?string $tag = null,
) {
parent::__construct($config);
if ($tag === null) {
- $tag = $config->getValue('syslog_tag', 'Nextcloud');
+ $this->tag = $config->getValue('syslog_tag', 'Nextcloud');
+ } else {
+ $this->tag = $tag;
}
- openlog($tag, LOG_PID | LOG_CONS, LOG_USER);
}
public function __destruct() {
@@ -59,6 +44,7 @@ class Syslog extends LogDetails implements IWriter {
*/
public function write(string $app, $message, int $level): void {
$syslog_level = $this->levels[$level];
+ openlog($this->tag, LOG_PID | LOG_CONS, LOG_USER);
syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level));
}
}
diff --git a/lib/private/Log/Systemdlog.php b/lib/private/Log/Systemdlog.php
index e4b4ce35c12..ffea0511732 100644
--- a/lib/private/Log/Systemdlog.php
+++ b/lib/private/Log/Systemdlog.php
@@ -1,27 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2018, Johannes Ernst
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Johannes Ernst <jernst@indiecomputing.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Log;
@@ -78,8 +59,8 @@ class Systemdlog extends LogDetails implements IWriter {
*/
public function write(string $app, $message, int $level): void {
$journal_level = $this->levels[$level];
- sd_journal_send('PRIORITY='.$journal_level,
- 'SYSLOG_IDENTIFIER='.$this->syslogId,
+ sd_journal_send('PRIORITY=' . $journal_level,
+ 'SYSLOG_IDENTIFIER=' . $this->syslogId,
'MESSAGE=' . $this->logDetailsAsJSON($app, $message, $level));
}
}