Application Logger
To use this feature, enable the PimcoreApplicationLoggerBundle in your bundle.php file
and install it:
bin/console pimcore:bundle:install PimcoreApplicationLoggerBundle
General
The Application Logger bundle lets developers log events and errors within a Pimcore application.
View and search logs in Pimcore Studio under System -> Application Logger:
Configuration
Configure the Application Logger in your project's YAML configuration under the pimcore.applicationlog key.
Full Configuration Reference
pimcore:
applicationlog:
loggers:
db:
# Minimum log level or a list of specific levels to capture
# Default: 'debug'
min_level_or_list: 'debug' # or ['debug', 'info'] for specific levels
# Maximum log level to capture
# Default: 'emergency'
max_level: 'emergency'
mail_notification:
# Enable email summaries of log entries
# Default: false
send_log_summary: false
# Minimum priority for entries included in the email summary.
# Use the level name or its numeric value:
# 8 (debug), 7 (info), 6 (notice), 5 (warning),
# 4 (error), 3 (critical), 2 (alert), 1 (emerg)
# Higher values are more inclusive.
# Default: null (all levels)
filter_priority: null
# Email addresses for log summaries, separated by ; or ,
mail_receiver: 'admin@example.com; ops@example.com'
# Number of days before log entries are moved to archive tables
# Default: 30
archive_treshold: 30
# Optional separate database for archive tables.
# Recommended for high-volume logging.
# Default: '' (same database)
archive_alternative_database: ''
# Storage engine for archive tables (e.g. ARCHIVE, InnoDB, Aria, MyISAM).
# When set to 'archive', auto-detects the best available engine.
# Default: 'archive'
archive_db_table_storage_engine: 'archive'
# Number of months before archive tables are deleted
# Default: 6
delete_archive_threshold: 6
Log Level Filtering
Log all messages with level debug or info only:
pimcore:
applicationlog:
loggers:
db:
min_level_or_list: ['debug', 'info']
Log all messages from level info through emergency:
pimcore:
applicationlog:
loggers:
db:
min_level_or_list: 'info'
max_level: 'emergency'
Mail Notifications
When send_log_summary is enabled, the defined receivers receive log entries by email
during the regular Pimcore maintenance cycle (see Maintenance Tasks).
The filter_priority controls which log messages are included (e.g. only errors and above).
Entries are sent in batches of at most 100 entries per email.
Note that every maintenance run flags all existing log entries as processed, regardless of
whether mail notifications are enabled. When you enable send_log_summary, you therefore
only receive entries logged since the last maintenance run — older entries are not emailed.
Log Archival
The archive function automatically creates database tables (application_logs_archive_YYYY_MM)
for log entry archival. In the example above, log entries move to archive tables after 30 days.
Archive tables are automatically deleted after the delete_archive_threshold (default: 6 months).
When log entries are moved to the archive tables, their referenced file objects
(see File Object Storage) are deleted from storage at the same
time. The archived database rows keep the file object path, but the file itself no longer
exists — file object attachments are therefore only available for archive_treshold days,
not for the lifetime of the archive tables.
Maintenance Tasks
Log archival, the deletion of old archive tables and file objects, and the mail
notifications are all executed as
maintenance tasks.
None of these run unless the Pimcore maintenance command (pimcore:maintenance)
is executed regularly, e.g. via cron job. The command only dispatches the tasks as messages
to the pimcore_maintenance Messenger transport, so a worker consuming that transport
(bin/console messenger:consume pimcore_maintenance) must be running as well.
File Object Storage
While log entries themselves are stored in the database, attached file objects
(see Special Context Variables) are stored on a
Flysystem storage named
pimcore.application_log.storage. Files are written to a date-based path within
the storage (/Y/m/d/fileobject_<uniqueId>), unless a custom filename is passed
as second constructor argument to FileObject.
If writing a file to the storage fails, the failure is ignored — only a warning is written to the system log, and the log entry is still created with a file object path that does not exist. Such a failed write therefore does not surface as an error when logging, but as a file object that cannot be opened in the log viewer. Errors while initializing the storage itself (e.g. a directory that cannot be created or a missing client service) are not caught and can be thrown to the code that logs.
By default, the storage points to a local directory:
flysystem:
storages:
pimcore.application_log.storage:
adapter: 'local'
visibility: private
options:
directory: "%kernel.project_dir%/var/application-logger"
When running Pimcore on multiple application servers (e.g. in a High Availability cluster), the default local storage does not work: each server writes file objects to its own local directory, so a server handling the request to view a log entry's file object cannot read files that were written by another server, resulting in errors in the log viewer.
In such setups, configure pimcore.application_log.storage to use a storage location
shared by all servers — either a shared/network filesystem mounted on every server or a
remote Flysystem adapter such as S3 (requires league/flysystem-aws-s3-v3 and an
S3 client service, here my_aws_s3_client_service):
flysystem:
storages:
pimcore.application_log.storage:
adapter: 'aws'
visibility: private
options:
client: 'my_aws_s3_client_service'
bucket: 'application-log'
How to Create Log Entries
The Application Logger is a PSR-3 compatible component available as service
Pimcore\Bundle\ApplicationLoggerBundle\ApplicationLogger.
Basic Usage - Example
Controller / Action
<?php
namespace App\Controller;
use Pimcore\Bundle\ApplicationLoggerBundle\ApplicationLogger;
use Pimcore\Controller\FrontendController;
class TestController extends FrontendController
{
// injected as action argument (controller needs to be registered as service)
public function testAction(ApplicationLogger $logger): void
{
$logger->error('Your error message');
$logger->alert('Your alert');
$logger->debug('Your debug message', ['foo' => 'bar']); // additional context information
}
public function anotherAction(): void
{
// fetched from container
$logger = $this->get(ApplicationLogger::class);
$logger->error('Your error message');
}
}
Dependency Injection
App\YourService:
calls:
- [setLogger, ['@Pimcore\Bundle\ApplicationLoggerBundle\ApplicationLogger']]
Or use autowiring:
services:
_defaults:
autowire: true
App\YourService: ~
<?php
namespace App;
use Pimcore\Bundle\ApplicationLoggerBundle\ApplicationLogger;
class YourService
{
/**
* @var ApplicationLogger
*/
private $logger;
public function __construct(ApplicationLogger $logger)
{
$this->logger = $logger;
$logger->debug('Hello from YourService');
}
}
Usage as Monolog Handler
Instead of using the ApplicationLogger class directly, configure Monolog
to use the Application Logger as a Monolog handler.
Pimcore provides the ApplicationLoggerDb handler, preconfigured as a service:
monolog:
handlers:
# monolog allows us to register custom handlers via type: service
# note that the only supported extra option besides type and id is channels
application_logger_db:
type: service
id: Pimcore\Bundle\ApplicationLoggerBundle\Handler\ApplicationLoggerDb
channels: ["application_logger"]
The channel(s) must exist. Create them by configuring them manually or by using DI tags to select the logger for the target channel. When using DI tags, Monolog creates the channel implicitly.
IMPORTANT: The
ApplicationLoggerDbhandler depends on the database connection. Exclude channels logging database queries (typically thedoctrinechannel) to avoid infinite loops. Either specify an allowlist of supported channels (as shown above) or exclude thedoctrinechannel by setting channels to["!doctrine"].
As the type: service handler config does not support filtering by log level,
use the filter handler type to wrap the Application Logger:
monolog:
handlers:
# The filter handler can be used to filter for a given log level.
# Note that the supported channels are now configured on the filter
# handler. To filter by level you can set accepted_levels or min_level and max_level.
# See https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/Configuration.php#L97
# for details.
application_logger_filter:
type: filter
channels: ["application_logger"]
handler: application_logger_db
min_level: ERROR
application_logger_db:
type: service
id: Pimcore\Bundle\ApplicationLoggerBundle\Handler\ApplicationLoggerDb
Combine this handler with other log handlers such as the Fingers Crossed Handler. See the Symfony Logging documentation for details.
Once the handler is configured, use it like any other Monolog logger by specifying a DI tag for the target channel:
<?php
namespace App\Controller;
use Psr\Log\LoggerInterface;
// we take a controller as example here, but this can be any service
// no need to extend a base controller here as we inject our dependencies
// via DI
class TestController
{
private LoggerInterface $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function testAction(): void
{
$this->logger->error('Your error message');
}
}
The service definition adds a DI tag to specify which logger to inject:
services:
App\Controller\TestController:
arguments:
$logger: '@logger'
tags:
- { name: monolog.logger, channel: application_logger }
Autowire the logger channel by naming the argument as (channel name in camel case) + Logger.
Example for channel foo_bar:
public function __construct(LoggerInterface $fooBarLogger)
{
$this->logger = $fooBarLogger;
}
More details on Logging Channel Handlers.
Special Context Variables
Three context variables have special functionality: fileObject, relatedObject, component.
<?php
namespace App\Controller;
use Pimcore\Bundle\ApplicationLoggerBundle\ApplicationLogger;
use Pimcore\Bundle\ApplicationLoggerBundle\FileObject;
use Pimcore\Model\DataObject\AbstractObject;
use Symfony\Component\HttpFoundation\Response;
class TestController
{
public function testAction(ApplicationLogger $logger): Response
{
$fileObject = new FileObject('some interesting data');
$myObject = DataObject::getById(73);
$logger->error('my error message', [
'fileObject' => $fileObject,
'relatedObject' => $myObject,
'component' => 'different component',
'source' => 'Stack trace or context-relevant information' // optional, if empty, gets automatically filled with class:method:line from where the log got executed
]);
// ...
}
}
In the Application Logger grid, the new row appears as my error message with a related object.
Click the row to navigate to the object editor via the Related object edit icon in the popup.
The fileObject context variable accepts either a FileObject instance (which writes
the given data to the file object storage) or a string path
pointing to an already existing file on that storage:
$logger->error('my error message', [
'fileObject' => 'path/to/existing-file.txt', // path on the application log storage
]);
A referenced file is deleted from the storage when the log entry is archived, also when it was passed as a string path and is used by other entries (see Log Archival).
Logging Exceptions
The Application Logger provides a helper method to log exceptions
and implicitly create a FileObject from the exception:
<?php
use Pimcore\Bundle\ApplicationLoggerBundle\ApplicationLogger;
$exception = new \RuntimeException('failed :(');
// 1) When directly using the application logger (see basic usage above). Given your
// logger is an instance of `ApplicationLogger`:
/** @var ApplicationLogger $appLogger */
$appLogger->logException('Oh no!', $exception, 'alert', $relatedObject, $component);
// 2) When using as monolog handler (see above). Given your logger is any PSR-3 compatible logger, you
// can use a static helper to generate a log entry with the same file object as the logging call
// above.
/** @var \Psr\Log\LoggerInterface $logger */
ApplicationLogger::logExceptionObject($logger, 'Oh no!', $exception, 'alert', $relatedObject);
Setting an Individual Logger Level
Add a console logger and set the minimum logging level to INFO (overwrites the log level in Pimcore configuration):
$logger = \Pimcore\Bundle\ApplicationLoggerBundle\ApplicationLogger::getInstance("SAP_exporter", true);
// returns a PSR-3 compatible logger, registers a custom app logger as `pimcore.app_logger.SAP_exporter` on the service container
$logger->addWriter(new \Monolog\Handler\StreamHandler('php://output', \Monolog\Level::Info));

