Logging API¶
Logging in eZ Commerce is based on Monolog. There is no separate logging API definition. For the purpose of persisting logs within a database, the Monolog API implementation has been extended by Doctrine-based classes and an interface.
Important service classes and interfaces of Monolog¶
Psr\Log\LoggerInterface¶
LoggerInterface
is always used as the service for logging.
The list below contains the logging methods (in order of importance).
Use the log()
method only if the log level of a message can only be determined at runtime.
For more information about the PSR logging standard, see the official specification.
1 2 3 4 5 6 7 8 9 |
|
Monolog\Logger¶
Monolog\Logger
implements LoggerInterface
but, for historical reasons, provides its own logging methods (which correspond to the interface, although are named differently).
Note
Although large parts of the shop rely on Monolog\Logger
directly, it's recommended that all new implementations rely on the PSR LoggerInterface
instead of explicitly referring to this class.
Base classes of Doctrine-based logging¶
LogRepositoryInterface¶
To make database logging possible, a specific Doctrine entity class and its respective repository class must exist for every type of log records (email log, ERP log).
LogRepositoryInterface
must be implemented by every repository class in order to work with the Doctrine handler.
createNewLog()¶
The createNewLog()
method instantiates a new log record entity.
It takes the following parameters:
Parameter | Description |
---|---|
$logRecord |
The record, as created by Doctrine loggers |
$persist |
If true , calls save() implicitly |
save()¶
The save()
method persists the given log entity.
It takes the following parameters:
Parameter | Description |
---|---|
$logEntity |
A log entity, created by createNewLog() |
AbstractOrmLogRepository¶
This implementation of LogRepositoryInterface
uses Doctrine's ORM API by deriving from EntityRepository
.
The class is abstract, but implements the complete LogRepositoryInterface
.
It is intended to be extended for concrete entity implementations of AbstractLog
and, therefore, must not be instantiated directly.
It's recommended to extend this class for any ORM-based logging entities.
AbstractLog¶
AbstractLog
is the abstract class for all Log entities.
It cannot be persisted by itself and MUST be derived by, for example, a fully-mapped Doctrine entity class.
The attributes in the class must be considered in any DBMS mapping, as well.
Note
For any deriving class that uses Symfony's annotation-based configuration for object relational mapping, the base attributes must be overridden and enriched with the respective ORM tags in their docblocks.
Monolog extension¶
The classes that extend Monolog by Doctrine-based persistence do not provide a public API. Instead, they implement the public API of Doctrine.
DoctrineFormatter¶
DoctrineFormatter
implements Monolog\Formatter\FormatterInterface
.
This is a Monolog formatter class for the Doctrine handler. It serializes all non-scalar values, so they can be stored in database fields.
Service definition:
1 2 3 4 5 6 |
|
DoctrineHandler¶
DoctrineHandler
extends Monolog\Handler\AbstractProcessingHandler
.
It is a Monolog handler class that writes log records into Doctrine entities.
Service definition:
1 2 3 4 5 6 7 |
|
Handler injection:
1 2 3 4 5 6 7 |
|
RequestDataProcessor¶
RequestDataProcessor
adds the request, session and user ID to log messages.
Service definition:
1 2 3 4 |
|
Processor injection:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|