|
| 1 | +:navigation-title: Logging |
| 2 | + |
| 3 | +.. include:: /Includes.rst.txt |
| 4 | +.. _production-logging: |
| 5 | + |
| 6 | +======================================== |
| 7 | +Logging considerations during production |
| 8 | +======================================== |
| 9 | + |
| 10 | +In production environments, improperly configured logging can lead to issues |
| 11 | +such as bloated log files, degraded performance, and even website outages due |
| 12 | +to full disk space. |
| 13 | + |
| 14 | +TYPO3 has several configuration options and tools to keep log files |
| 15 | +manageable, secure, and relevant. This guide covers practical strategies for |
| 16 | +controlling log volume, reducing noise, and monitoring critical events. |
| 17 | + |
| 18 | +.. seealso:: |
| 19 | + |
| 20 | + For an overview of how logging works inside TYPO3 and how to use it in |
| 21 | + custom code or extensions, see the :ref:`logging` chapter in the API section. |
| 22 | + |
| 23 | +.. warning:: |
| 24 | + |
| 25 | + Log files can grow rapidly in production and may eventually exhaust |
| 26 | + available disk space, causing TYPO3 to become unresponsive or inaccessible. |
| 27 | + |
| 28 | +.. contents:: Table of contents |
| 29 | + |
| 30 | +.. _production-logging-level: |
| 31 | + |
| 32 | +Limit the level to be logged |
| 33 | +============================ |
| 34 | + |
| 35 | +Each log entry in TYPO3 is associated with a severity level. For details on |
| 36 | +log levels, refer to the TYPO3 documentation: |
| 37 | +`Log levels <https://docs.typo3.org/permalink/t3coreapi:logging-logger-shortcuts>`_. |
| 38 | + |
| 39 | +During development, it is often useful to log detailed information. In |
| 40 | +production, logging should be limited to important issues—typically messages at |
| 41 | +the `ERROR` level or higher—to reduce disk usage and improve performance. |
| 42 | + |
| 43 | +By default, when the |
| 44 | +`Application Context <https://docs.typo3.org/permalink/t3coreapi:application-context>`_ |
| 45 | +is set to `Production`, only messages with a severity of |
| 46 | +:php-short:`\Psr\Log\LogLevel::ERROR` or higher are logged. |
| 47 | + |
| 48 | +You can also configure different writers for specific log levels. This allows |
| 49 | +you to, for example, write warnings and errors to separate files, or ignore |
| 50 | +lower-severity messages altogether. |
| 51 | + |
| 52 | +The following example demonstrates how to configure log writers per log |
| 53 | +level: |
| 54 | + |
| 55 | +.. literalinclude:: _codesnippets/_loglevels.php |
| 56 | + :caption: config/system/additional.php | typo3conf/system/additional.php |
| 57 | + |
| 58 | +.. _production-logging-monitor: |
| 59 | + |
| 60 | +Monitor the log and address common log entries |
| 61 | +============================================== |
| 62 | + |
| 63 | +Some log messages may appear frequently without indicating a critical or |
| 64 | +harmful issue. For example, an outdated |
| 65 | +`TypoScript condition <https://docs.typo3.org/permalink/t3tsref:typoscript-syntax-conditions-examples>`_ |
| 66 | +written in legacy syntax can trigger log entries every time TypoScript is |
| 67 | +evaluated for a page. |
| 68 | + |
| 69 | +Fixing such recurring issues helps reduce the size of your log files and |
| 70 | +improves the overall quality and maintainability of your code base. |
| 71 | + |
| 72 | +.. _production-logging-rotation: |
| 73 | + |
| 74 | +Use log rotation |
| 75 | +================ |
| 76 | + |
| 77 | +.. versionadded:: 13.0 |
| 78 | + |
| 79 | +Replace :php-short:`\TYPO3\CMS\Core\Log\Writer\FileWriter` |
| 80 | +with :php-short:`\TYPO3\CMS\Core\Log\Writer\RotatingFileWriter`. Define a |
| 81 | +rotation interval and specify how many rotated files should be retained. |
| 82 | + |
| 83 | +.. seealso:: |
| 84 | + |
| 85 | + * `RotatingFileWriter configuration <https://docs.typo3.org/permalink/t3coreapi:logging-writers-rotatingfilewriter>`_ |
| 86 | + |
| 87 | +The following example adds log rotation for the "main" log file: |
| 88 | + |
| 89 | +.. literalinclude:: /ApiOverview/Logging/Writers/_additionalRotationFileWriter.php |
| 90 | + :caption: config/system/additional.php | typo3conf/system/additional.php |
| 91 | + |
| 92 | +If you are using extensions such as |
| 93 | +:composer:`apache-solr-for-typo3/solr` that configure custom log files, |
| 94 | +you also need to switch those log files to use the |
| 95 | +:php-short:`\TYPO3\CMS\Core\Log\Writer\RotatingFileWriter`. |
| 96 | + |
| 97 | +.. _production-logging-system-tools: |
| 98 | + |
| 99 | +Use system-Level log management tools |
| 100 | +===================================== |
| 101 | + |
| 102 | +In addition to TYPO3's internal logging features, it is common practice to |
| 103 | +use server-level tools to manage log files. These tools can rotate, archive, |
| 104 | +compress, and delete log files based on size, age, or other criteria. |
| 105 | + |
| 106 | +On Linux systems, consider using the following tools: |
| 107 | + |
| 108 | +* **logrotate** – A standard utility for automatic log rotation, commonly |
| 109 | + pre-installed on most Linux distributions. It can be configured to manage |
| 110 | + TYPO3 logs and system logs. |
| 111 | + |
| 112 | +* **systemd-journald** – If your server uses systemd, you can use |
| 113 | + journald for logging, with configurable rotation and retention. |
| 114 | + |
| 115 | +* **cron jobs with custom scripts** – For more specific needs, administrators |
| 116 | + can use scheduled scripts to archive or delete logs periodically. |
| 117 | + |
| 118 | +.. tip:: |
| 119 | + |
| 120 | + If using `logrotate`, ensure the log directory (e.g., |
| 121 | + :file:`var/log/`) is included in the configuration, and set appropriate |
| 122 | + permissions so the rotation process can access the files. |
| 123 | + |
| 124 | +.. _production-logging-centralized: |
| 125 | + |
| 126 | +Use centralized error monitoring (e.g., Sentry) |
| 127 | +=============================================== |
| 128 | + |
| 129 | +In many production environments, it is common to offload error tracking to a |
| 130 | +centralized service like `Sentry <https://sentry.io>`_. These tools |
| 131 | +capture unhandled exceptions and application errors with full context, |
| 132 | +including stack traces, request details, and environment variables. |
| 133 | + |
| 134 | +Sentry can often **replace the need for local error log management**, |
| 135 | +especially when it is used as the main tool for observing application behavior |
| 136 | +and alerting failures. However, local logs may still be useful for storing |
| 137 | +lower-level messages, audit trails, or when dealing with infrastructure-related |
| 138 | +issues. |
| 139 | + |
| 140 | +TYPO3 supports Sentry integration via third-party extensions such as: |
| 141 | + |
| 142 | +* :composer:`networkteam/sentry-client` (A Sentry client for TYPO3) |
| 143 | + |
| 144 | +.. tip:: |
| 145 | + |
| 146 | + Sentry is best suited for tracking uncaught exceptions and user-facing |
| 147 | + errors. It is not designed to store full application logs such as debug |
| 148 | + output or access logs. |
| 149 | + |
| 150 | +.. _deprecation-disable-errors: |
| 151 | + |
| 152 | +Disabling the deprecation log on production |
| 153 | +=========================================== |
| 154 | + |
| 155 | +By default, when the |
| 156 | +`Application Context <https://docs.typo3.org/permalink/t3coreapi:application-context>`_ |
| 157 | +is set to `Production`, the deprecation log is disabled. |
| 158 | + |
| 159 | +Check the log directory, for example :path:`/path/to/project/var/log` and ensure |
| 160 | +no logfile has been written with `deprecation` in the name. |
| 161 | + |
| 162 | +As best practice you should only configure |
| 163 | +deprecation logs for `Development` contexts, for example: |
| 164 | + |
| 165 | +.. literalinclude:: /ApiOverview/Deprecation/_additional.php |
| 166 | + :caption: config/system/additional.php | typo3conf/system/additional.php |
| 167 | + |
| 168 | +If the deprecation log is still being written in production, |
| 169 | +you can explicitly disable it by unsetting its configuration: |
| 170 | + |
| 171 | +.. literalinclude:: _codesnippets/_disableDeprecationLog.php |
| 172 | + :caption: config/system/additional.php | typo3conf/system/additional.php |
| 173 | + |
| 174 | +If the deprecation log continues to be written, check the following: |
| 175 | + |
| 176 | +#. **Verify the Application Context** |
| 177 | + |
| 178 | + The current context (e.g., `Production`) is shown in the top bar of the TYPO3 |
| 179 | + backend under the :guilabel:`System Information` module. |
| 180 | + |
| 181 | +#. **Check the resolved configuration** |
| 182 | + |
| 183 | + Use the :guilabel:`System > Configuration` module (requires |
| 184 | + :composer:`typo3/cms-lowlevel`) to inspect the effective value of |
| 185 | + `$GLOBALS['TYPO3_CONF_VARS']['LOG']['TYPO3']['CMS']['deprecations']`. |
| 186 | + |
| 187 | +#. **Look for overrides in extensions** |
| 188 | + |
| 189 | + Some extensions may override logging settings in their |
| 190 | + :file:`ext_localconf.php` or :file:`ext_tables.php`. Check these files |
| 191 | + if your configuration appears to be ignored. |
| 192 | + |
| 193 | +.. _production-logging-security: |
| 194 | + |
| 195 | +Securing TYPO3 logs in production |
| 196 | +================================= |
| 197 | + |
| 198 | +TYPO3 logs may contain sensitive information that could be exploited by an |
| 199 | +attacker to gain information about your system. Logs may also include personal |
| 200 | +data such as IP addresses, which must be handled with care to ensure |
| 201 | +privacy compliance. |
| 202 | + |
| 203 | +**In Composer-based TYPO3 installations**, logs are written to |
| 204 | +:path:`/path/to/project/var/log` by default. Since this directory is |
| 205 | +located *outside* the web server’s document root |
| 206 | +(:path:`/path/to/project/public`), it cannot be accessed directly from the |
| 207 | +internet—providing a level of built-in security. |
| 208 | + |
| 209 | +**In Classic-mode TYPO3 installations**, logs are stored in |
| 210 | +:path:`/path/to/project/typo3conf/var/log`. Because the document root in |
| 211 | +Classic mode typically points to :path:`/path/to/project`, this log |
| 212 | +directory is publicly accessible by default. **Additional precautions must |
| 213 | +be taken** to prevent unauthorized access. |
| 214 | + |
| 215 | +.. seealso:: |
| 216 | + |
| 217 | + * `Secure file permissions (operating system level) <https://docs.typo3.org/permalink/t3coreapi:security-file-directory-permissions>`_ |
| 218 | + * `Restrict HTTP access <https://docs.typo3.org/permalink/t3coreapi:security-restrict-access-server-level>`_ (for Classic mode) |
0 commit comments