Skip to content
📝 Symfony bundle with extra processors and logger to log request/response
Branch: master
Clone or download
notFloran Merge pull request #20 from TheRedDot/bin-dir
Use vendor/bin instead of bin for vendor binaries
Latest commit 9668509 May 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc fix typos and add final classes May 21, 2019
spec Rename ApacheUniqueIdProvider to ServerRequestIdProvider May 20, 2019
src
.editorconfig Add editorconfig May 17, 2019
.gitattributes
.gitignore Use vendor/bin instead of bin for vendor binaries May 21, 2019
.php_cs.dist Install and configure php-cs-fixer May 20, 2019
.travis.yml Merge pull request #20 from TheRedDot/bin-dir May 21, 2019
CHANGELOG.md fix typos and add final classes May 21, 2019
LICENSE Update name/path/url with hexanet to use TheRedDot Jan 17, 2019
README.md Rename ApacheUniqueIdProvider to ServerRequestIdProvider May 20, 2019
UPGRADE-4.0.md fix typos and add final classes May 21, 2019
composer.json Use vendor/bin instead of bin for vendor binaries May 21, 2019
phpspec.yml.dist Move from Hexanet/Common/ to TheRedDot/ namespace May 20, 2019
phpstan.neon Setup phpstan May 21, 2019

README.md

MonologExtraBundle

Build Status Total Downloads Latest stable Version

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 thereddot/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 thereddot/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 TheRedDot\MonologExtraBundle\TheRedDotMonologExtraBundle(),
        );
        // ...
    }

    // ...
}

Usage

Processors

The bundle provides several processors:

  • User
  • Session id
  • Request id
  • Additions

User

The UserProcessor add data about the current user in each log entry.

the_red_dot_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 TheRedDot\MonologExtraBundle\Provider\User\UserProviderInterface.

the_red_dot_monolog_extra:
    provider:
        user: your_own_provider_service_id

Session id

Add the session id in each log entry.

the_red_dot_monolog_extra:
    processor:
        session_id: true

You can create your own provider by creating a service that implements TheRedDot\MonologExtraBundle\Provider\Session\SessionIdProviderInterface.

the_red_dot_monolog_extra:
    provider:
        session_id: your_own_provider_service_id

Request id

Add the request id for the request in each log entry.

the_red_dot_monolog_extra:
    processor:
        request_id: true

The bundle comes with 2 providers:

  • UniqidProvider (default): use uniqid
  • ServerRequestIdProvider: get from $_SERVER
    • you need to pass the name of a field of $_SERVER, example for mod_unique_id of Apache: UNIQUE_ID.

You can create your own provider by creating a service that implements TheRedDot\MonologExtraBundle\Provider\RequestId\RequestIdProviderInterface.

the_red_dot_monolog_extra:
    provider:
        request_id: your_own_provider_service_id

Additions

Add custom data in each log entry.

the_red_dot_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 request id to response

Add the request id of the previous processor in the response headers.

HTTP/1.1 302 Found
X-Request-ID: 57c5f5e842b10

Configuration reference

Configuration reference for a reference on the available configuration options.

Credits

Forked from Hexanet/MonologExtraBundle.

License

MonologExtraBundle is licensed under the MIT license.

You can’t perform that action at this time.