Commit 5d3eff1b authored by crell's avatar crell Committed by Benni Mack
Browse files

[TASK] Add a channel column to sys_log

The channel column is a text field intended to suppplant the type column.
For now, all types map over to column based on a lookup table.

Also, repurpose the level column to a string to store the PSR-3 level.

Resolves: #94433
Relates to: #94356
Releases: master
Change-Id: I295df69da7e21ff9650a3c0c2b4d0e70a8ca9566
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69656


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: crell's avatarcrell <larry@garfieldtech.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 3040b9ff
......@@ -414,6 +414,8 @@ class PasswordReset implements LoggerAwareInterface
$fields = [
'userid' => $userId,
'type' => SystemLogType::LOGIN,
'channel' => SystemLogType::toChannel(SystemLogType::LOGIN),
'level' => SystemLogType::toLevel(SystemLogType::LOGIN),
'action' => $action,
'error' => $error,
'details_nr' => 1,
......@@ -435,6 +437,8 @@ class PasswordReset implements LoggerAwareInterface
[
\PDO::PARAM_INT,
\PDO::PARAM_INT,
\PDO::PARAM_STR,
\PDO::PARAM_STR,
\PDO::PARAM_INT,
\PDO::PARAM_INT,
\PDO::PARAM_INT,
......
......@@ -38,6 +38,7 @@ use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\SysLog\Action as SystemLogGenericAction;
use TYPO3\CMS\Core\SysLog\Error as SystemLogErrorClassification;
use TYPO3\CMS\Core\SysLog\Type;
use TYPO3\CMS\Core\SysLog\Type as SystemLogType;
use TYPO3\CMS\Core\Type\Bitmask\BackendGroupMountOption;
use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
......@@ -2154,9 +2155,14 @@ TCAdefaults.sys_note.email = ' . $this->user['email'];
$data['originalUser'] = $backuserid;
}
// @todo Remove this once this method is properly typed.
$type = (int)$type;
$fields = [
'userid' => (int)$userId,
'type' => (int)$type,
'type' => $type,
'channel' => Type::toChannel($type),
'level' => Type::toLevel($type),
'action' => (int)$action,
'error' => (int)$error,
'details_nr' => (int)$details_nr,
......@@ -2178,6 +2184,8 @@ TCAdefaults.sys_note.email = ' . $this->user['email'];
[
\PDO::PARAM_INT,
\PDO::PARAM_INT,
\PDO::PARAM_STR,
\PDO::PARAM_STR,
\PDO::PARAM_INT,
\PDO::PARAM_INT,
\PDO::PARAM_INT,
......
......@@ -156,6 +156,7 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, Si
[
'userid' => $userId,
'type' => SystemLogType::ERROR,
'channel' => SystemLogType::toChannel(SystemLogType::ERROR),
'action' => SystemLogGenericAction::UNDEFINED,
'error' => SystemLogErrorClassification::SYSTEM_ERROR,
'details_nr' => 0,
......
......@@ -249,6 +249,7 @@ class ErrorHandler implements ErrorHandlerInterface, LoggerAwareInterface
[
'userid' => $userId,
'type' => SystemLogType::ERROR,
'channel' => SystemLogType::toChannel(SystemLogType::ERROR),
'action' => SystemLogGenericAction::UNDEFINED,
'error' => SystemLogErrorClassification::SYSTEM_ERROR,
'level' => $severity,
......
......@@ -17,8 +17,12 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\SysLog;
use Psr\Log\LogLevel;
/**
* A class defining possible logging types
* A class defining possible logging types.
*
* @internal The logging type system is moving towards PSR-3-defined log levels and channels, this class might get removed without any further notice from TYPO3 v12.0. on.
*/
class Type
{
......@@ -29,4 +33,50 @@ class Type
public const ERROR = 5;
public const SETTING = 254;
public const LOGIN = 255;
private static array $channelMap = [
self::DB => 'content',
self::FILE => 'file',
self::CACHE => 'default',
self::EXTENSION => 'default',
self::ERROR => 'php',
self::SETTING => 'default',
self::LOGIN => 'user',
];
private static array $levelMap = [
self::DB => LogLevel::WARNING,
self::FILE => LogLevel::INFO,
self::CACHE => LogLevel::INFO,
self::EXTENSION => LogLevel::INFO,
self::ERROR => LogLevel::ERROR,
self::SETTING => LogLevel::INFO,
self::LOGIN => LogLevel::INFO,
];
/**
* @internal
*/
public static function levelMap(): array
{
return static::$levelMap;
}
/**
* @internal
*/
public static function channelMap(): array
{
return static::$channelMap;
}
public static function toChannel(int $type): string
{
return static::$channelMap[$type] ?? 'default';
}
public static function toLevel(int $type): string
{
return static::$levelMap[$type] ?? LogLevel::INFO;
}
}
......@@ -374,6 +374,7 @@ CREATE TABLE sys_log (
error tinyint(4) unsigned DEFAULT '0' NOT NULL,
details text,
type tinyint(3) unsigned DEFAULT '0' NOT NULL,
channel varchar(20) DEFAULT 'default' NOT NULL,
details_nr tinyint(3) DEFAULT '0' NOT NULL,
IP varchar(39) DEFAULT '' NOT NULL,
log_data text,
......@@ -383,7 +384,7 @@ CREATE TABLE sys_log (
request_id varchar(13) DEFAULT '' NOT NULL,
time_micro float DEFAULT '0' NOT NULL,
component varchar(255) DEFAULT '' NOT NULL,
level tinyint(1) unsigned DEFAULT '0' NOT NULL,
level varchar(10) DEFAULT 'info' NOT NULL,
message text,
data text,
KEY event (userid,event_pid),
......
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Install\Updates;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\SysLog\Type;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class SysLogChannel implements UpgradeWizardInterface
{
protected Connection $sysLogTable;
public function __construct()
{
$this->sysLogTable = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_log');
}
/**
* @inheritDoc
*/
public function getIdentifier(): string
{
return 'sysLogChannel';
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Populates a new channel column of the sys_log table.';
}
/**
* @inheritDoc
*/
public function getDescription(): string
{
return <<<END
The logging system is migrating toward string-based channels rather than int-based types. This update populates the new column of existing log entries.
END;
}
/**
* @inheritDoc
*/
public function executeUpdate(): bool
{
$statement = $this->sysLogTable->prepare('UPDATE sys_log SET channel = ? WHERE type = ?');
foreach (Type::channelMap() as $type => $channel) {
$statement->executeQuery([$channel, $type]);
}
$statement = $this->sysLogTable->prepare('UPDATE sys_log SET level = ? WHERE type = ?');
foreach (Type::levelMap() as $type => $level) {
$statement->executeQuery([$level, $type]);
}
return true;
}
/**
* If all log entries have a default channel, assume we've not mapped anything yet.
*/
public function updateNecessary(): bool
{
$result = $this->sysLogTable->executeQuery('SELECT count(channel) FROM sys_log WHERE NOT channel="default"');
return !$result->fetchOne();
}
/**
* @inheritDoc
*/
public function getPrerequisites(): array
{
// we need to make sure the new DB column was already added.
return [
DatabaseUpdatedPrerequisite::class
];
}
}
......@@ -19,6 +19,8 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['legacyCollec
= \TYPO3\CMS\Install\Updates\CollectionsExtractionUpdate::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['backendUserLanguage']
= \TYPO3\CMS\Install\Updates\BackendUserLanguageMigration::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['sysLogChannel']
= \TYPO3\CMS\Install\Updates\SysLogChannel::class;
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
$icons = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment