johndodev / jlog-bundle
Easy logging.
Installs: 146
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.1
- monolog/monolog: ^3.0
- symfony/console: ^7.1
- symfony/framework-bundle: ^6.4|^7.0
- symfony/http-client: ^6.4|^7.0
- symfony/stopwatch: ^7.1
This package is auto-updated.
Last update: 2025-01-15 15:42:15 UTC
README
Installation
composer require johndodev/jlog-bundle
Configuration
.env
JLOG_API_KEY=your_api_key
config/packages/jlog.yaml
jlog: project_api_key: '%env(JLOG_API_KEY)%' enable_exception_listener: true ignore_exceptions: - Symfony\Component\HttpKernel\Exception\NotFoundHttpException # See chapter about logging commands console_channel: console
monolog.yaml
You need to use the buffer handler en amont.
See https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/Configuration.php#L139
for configuration options.
Ex :
monolog: channels: - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists - command # same name as jlog.console_channel ... handlers: buffer: type: buffer handler: jlog level: debug # or whatever channels: ["app"] # or whatever jlog: type: service id: jlog.monolog_handler
Usage
Logging commands
Extends Johndodev\JlogBundle\Console\LoggableOutputCommand
in your command you want to log.
The start and end of commands will be logged in Jlog, in the channel you configured, with the output as metadata.
Logging exceptions
Unhandled exceptions are already logged (if enabled in config). You can still manually log them as usual, with monolog :
try { // ... } catch (\Exception $e) { $this->logger->error('lorem ipsum...', [ 'exception' => $e->getMessage() ]); }
Logging messages
With monologer, as usual.
It is recommanded to use placeholder, especially for errors which triggers notifications, because the message is used for signature for unique notification.
$this->logger->error('bla bla: {error}', [ 'error' => $e->getMessage() ]);