hexanet / monolog-extra-bundle
Symfony bundle with extra processors and logger to log request/response
Installs: 26 852
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1.0
- symfony/config: ^3.4 || ^4.0
- symfony/dependency-injection: ^3.4 || ^4.0
- symfony/http-foundation: ^3.4 || ^4.0
- symfony/http-kernel: ^3.4 || ^4.0
- symfony/monolog-bundle: ^2.8 || ^3.0
- symfony/security: ^3.4 || ^4.0
Requires (Dev)
- phpspec/phpspec: ^4.3
README
Symfony bundle with extra processors and logger to log request/response.
Installation
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require hexanet/monolog-extra-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require hexanet/monolog-extra-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Hexanet\Common\MonologExtraBundle\HexanetMonologExtraBundle(), ); // ... } // ... }
Usage
Processors
The bundle provides several processors:
- User
- Session ID
- UID
- Additions
User
The UserProcessor add data about the current user in each log entry.
hexanet_monolog_extra: processor: user: true
The default provider returns:
- anonymous when no user is logged
- the username of the current logged user
- cli
You can create your own provider by creating a service that implements Hexanet\Common\MonologExtraBundle\Provider\User\UserProviderInterface.
hexanet_monolog_extra: provider: user: your_own_provider_service_id
Session ID
Add the session id in each log entry.
hexanet_monolog_extra: processor: session_id: true
You can create your own provider by creating a service that implements Hexanet\Common\MonologExtraBundle\Provider\Session\SessionIdProviderInterface.
hexanet_monolog_extra: provider: session_id: your_own_provider_service_id
UID
Add an unique identifier for the request in each log entry.
hexanet_monolog_extra: processor: uid: true
The bundle comes with 2 providers:
- UniqidProvider (default): use
uniqid
- ApacheUniqueIdProvider: get from environment, need mod_unique_id of Apache
You can create your own provider by creating a service that implements Hexanet\Common\MonologExtraBundle\Provider\Uid\UidProviderInterface.
hexanet_monolog_extra: provider: uid: your_own_provider_service_id
Additions
Add custom data in each log entry.
hexanet_monolog_extra: processor: additions: type: symfony application: the best symfony application locale: "%locale%" environment: "%kernel.environment%"
Loggers
On request
Create a log entry with the request data.
On response
Create a log entry with the response data.
On console exception
Create a log entry when an exception occurs in console.
Add UID to response
Add the UID of the previous processor in the response headers.
HTTP/1.1 302 Found
X-UID: 57c5f5e842b10
Configuration reference
Configuration reference for a reference on the available configuration options.
Credits
Developed by Hexanet.
License
MonologExtraBundle is licensed under the MIT license.