Logger interface
Last update: May 16, 2023
- Topics:
- Configuration
- Logs
CREATED FOR:
- Experienced
- Admin
- Developer
To start working with a logger, you must create an instance of \Psr\Log\LoggerInterface
. With this interface, you can call the following functions to write data to log files:
One way to do that is explained in the Log database activity example.
Another way follows:
class SomeModel
{
private $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
public function doSomething()
{
try {
//do something
} catch (\Exception $e) {
$this->logger->critical('Error message', ['exception' => $e]);
}
}
}
The preceding example shows that SomeModel
receives a \Psr\Log\LoggerInterface
object using constructor injection. In a method doSomething
, if some error occurred, it is logged to a method critical
($this->logger->critical($e);
).
RFC 5424 defines eight log levels (debug, info, notice, warning, error, critical, alert, and emergency).
Previous pageCustomized logs
Next pageLog database activity
Commerce
- Overview
- General setup
- Deployment
- Cache
- Command Line
- Command-line tool
- Common commands
- Enable logging
- Manage the cache
- Manage indexers
- Configure cron jobs
- Compile code
- Operation mode
- Start message queue consumers
- URN highlighter
- Dependency reports
- Localization
- Configuration management
- Static view
- Create symlinks
- Run unit tests
- Convert layout files
- Generate data for performance testing
- Run support utilities (Commerce only)
- Configuration files
- Configuration paths
- Cron Jobs
- Logs
- Message Queues
- Multiple sites
- Search Engine
- Security
- Storage
- Return to Operational Guides