LogEntryRepository

Read onlyYes
FinalYes

Repository for writing system log entries to the database.

Provides methods to create log entries in the sys_log table, tracking user actions, errors, and system events.

Internal
Attributes
#[Autoconfigure]
$public: true

Table of Contents

Methods

__construct()  : mixed
writeLogEntry()  : int
Writes an entry to the system log (sys_log table).
writeLogEntryForBackendUser()  : int
Legacy wrapper for `writeLogEntry`, invoked with the current backend user.

Methods

writeLogEntry()

Writes an entry to the system log (sys_log table).

public writeLogEntry(PrincipalContext $principalContext, ProcessingContext $processingContext, int $type, int $action, int $error, string $details, array<string|int, mixed> $data[, string $tableName = '' ][, int|string $recordUid = '' ][, int $eventPid = -1 ][, ServerRequestInterface|null $request = null ]) : int

This method creates a log entry tracking user actions, errors, and system events. The log entry includes context about the principal (user), workspace, and optionally the database record affected by the action.

Parameters
$principalContext : PrincipalContext

The user/principal context that triggered the log entry, including user ID and role

$processingContext : ProcessingContext

The processing context, including workspace ID where the action occurred

$type : int

Type of action that created the log entry. Common types include: 1 (DB) for database operations, 2 (FILE) for file operations, 3 (CACHE) for cache operations, 4 (EXTENSION) for extension actions, 5 (ERROR) for errors, 255 (LOGIN) for login/logout events. See \TYPO3\CMS\Core\SysLog\Type constants.

$action : int

Specific action ID within the type category. The meaning depends on $type. Use 0 when no sub-categorization applies.

$error : int

Severity level: 0 = informational message, 1 = warning (user problem), 2 = system error (should not happen), 3 = security notice (for admins)

$details : string

The log message text. May contain sprintf-style placeholders (%s, %d, etc.) that will be substituted with values from $data array.

$data : array<string|int, mixed>

Additional data for the log entry. If provided, the first 5 elements (keys 0-4) will be used to substitute placeholders in $details via sprintf. Special key 'originalUser' is set automatically when user impersonation is active.

$tableName : string = ''

Database table name of the record affected by this action (used by DataHandler).

$recordUid : int|string = ''

UID of the record affected by this action (used by DataHandler).

$eventPid : int = -1

Page UID where the event occurred. Used to filter log entries by page. Use -1 for global events not tied to a specific page.

$request : ServerRequestInterface|null = null

The request object that triggered the log entry.

Return values
int

The UID of the created log entry.

writeLogEntryForBackendUser()

Legacy wrapper for `writeLogEntry`, invoked with the current backend user.

public writeLogEntryForBackendUser(BackendUserAuthentication $backendUser, int $type, int $action, int $error, string $details, array<string|int, mixed> $data[, string $tableName = '' ][, int|string $recordUid = '' ][, int $eventPid = -1 ]) : int

This method extracts the principal and processing context from the BackendUserAuthentication object and delegates to writeLogEntry(). It automatically handles user impersonation (switch user mode) by including the original user ID in the log data.

Parameters
$backendUser : BackendUserAuthentication
$type : int
$action : int
$error : int
$details : string
$data : array<string|int, mixed>
$tableName : string = ''
$recordUid : int|string = ''
$eventPid : int = -1
Internal

might be removed during TYPO3 v14 development

Return values
int

        
On this page

Search results