---
title: "Quickstart"
manual: "TYPO3 Explained"
version: "11.5"
permalink: "https://docs.typo3.org/permalink/t3coreapi:logging-quickstart@11.5"
source: "ApiOverview/Logging/Quickstart/Index.rst"
rendered: "2026-10-21T15:30:00+00:00"
---

> [!WARNING]
> **Attention**
>
> TYPO3 v11 has reached end-of-life as of October 31th 2024 and
> is no longer being maintained. Use the version switcher on the top
> left of this page to select documentation for a supported version of TYPO3.
>
> Need more time before upgrading?
> You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here:
> [TYPO3 ELTS](https://typo3.com/services/extended-support-elts).

# Quickstart {#logging-quickstart}

## Instantiate a logger for the current class {#logging-quicksart-instantiate-logger}

<!-- TODO: no Markdown rendering for "versionadded" -->

Feature: #95044 - Support autowired LoggerInterface injection

[Constructor injection](https://docs.typo3.org/permalink/t3coreapi:constructor-injection@11.5) can be used to
automatically instantiate the logger:

**EXT:my_extension/Classes/MyClass.php**

```php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension;

use Psr\Log\LoggerInterface;

class MyClass
{
    public function __construct(
        private readonly LoggerInterface $logger,
    ) {
    }
}

```

## Log {#logging-quickstart-log}

Log a simple message (in this example with the log level "warning"):

**EXT:my_extension/Classes/MyClass.php**

```php
$this->logger->warning('Something went awry, check your configuration!');
```

Provide additional context information with the log message (in this example
with the log level "error"):

**EXT:my_extension/Classes/MyClass.php**

```php
$this->logger->error('Passing {value} was unwise.', [
    'value' => $value,
    'other_data' => $foo,
]);
```

Values in the message string that should vary based on the error (such as
specifying an invalid value) should use placeholders, denoted by
`{ }`.  Provide the value for that placeholder in the context array.

`$this->logger->warning()` etc. are only shorthands - you can also call
`$this->logger->log()` directly and pass the severity level:

**EXT:my_extension/Classes/MyClass.php**

```php
// use TYPO3\CMS\Core\Log\LogLevel;

$this->logger->log(LogLevel::CRITICAL, 'This is an utter failure!');
```

## Set logging output {#set-logging-output}

TYPO3 has the [FileWriter](https://docs.typo3.org/permalink/t3coreapi:logging-writers-filewriter@11.5) enabled by default
for warnings (`LogLevel::WARNING`) and higher severity, so all matching log
entries are written to a file.

If the filename is not set, then the file will contain a hash like

**Composer-based installation**

`var/log/typo3_<hash>.log`, for example
`var/log/typo3_7ac500bce5.log`.

**Legacy installation**

`typo3temp/var/log/typo3_<hash>.log`, for example
`typo3temp/var/log/typo3_7ac500bce5.log`.

A sample output looks like this:

```none
Fri, 19 Jul 2023 09:45:00 +0100 [WARNING] request="5139a50bee3a1" component="TYPO3.Examples.Controller.DefaultController": Something went awry, check your configuration!
Fri, 19 Jul 2023 09:45:00 +0100 [ERROR] request="5139a50bee3a1" component="TYPO3.Examples.Controller.DefaultController": Passing someValue was unwise. - {"value":"someValue","other_data":{}}
Fri, 19 Jul 2023 09:45:00 +0100 [CRITICAL] request="5139a50bee3a1" component="TYPO3.Examples.Controller.DefaultController": This is an utter failure!
```
