vivait / logging-bundle
Logging Bundle
Installs: 16 171
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.2 | ^8.0
- jmikola/wildcard-event-dispatcher-bundle: ^1.0
- monolog/monolog: ^1.22
- symfony/security-core: ^2.8|^3.4|^4.4|^5.0
Requires (Dev)
- phpunit/phpunit: ~7.3
README
This bundle will add a Monolog processor that adds the client IP, user-agent, kernel environment, user and application name to the extra data of each log line.
It also provides an event listener that listens to all events, logging any that implement the LoggableEvent
interface.
Installation
composer require vivait/logging-bundle
Include the bundle in your AppKernel
:
// app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Vivait\LoggingBundle\VivaitLoggingBundle(), ); // ... } }
Add the following configuration to your config.yml
:
vivait_logging: application_name: MyAppName # Alternatively... application_name: '%my_name_parameter%'
Usage
To use the loggable event listener, simply fire any event that implements the LoggableEvent
interface, such as the GenericLogEvent
that is part of this bundle.
To use the extra data, set up a Monolog formatter with the appropriate arguments, or use the provided vivait.logging_bundle.log_formatter
service, e.g.
# config.yml monolog: handlers: main: type: stream path: '%kernel.logs_dir%/%kernel.environment%.log' level: debug formatter: vivait.logging_bundle.log_formatter
which will display logs in the following format:
[%%datetime%%] [%%extra.App%%] [%%extra.Environment%%] [%%extra.User%%] %%channel%%.%%level_name%%: %%message%% [%%extra.IP%%] [%%extra.UA%%] %%context%% %%extra%%