Giter VIP home page Giter VIP logo

monologextrabundle's Introduction

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 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.

monologextrabundle's People

Contributors

notfloran avatar nclshart avatar jeromemacias avatar

Stargazers

Malte avatar  avatar  avatar

Watchers

Arnaud Lecat avatar  avatar James Cloos avatar  avatar

Forkers

jeromemacias

monologextrabundle's Issues

Clean SymfonySessionIdProvider constructor

Related to @nclsHart comment :

public function __construct(bool $startSession = false, SessionInterface $session)

This is not directly related to this PR, but arguments with default value should be at end of arguments list.

gelf optionnal

TODO :

  • suggest graylog2/gelf-php instead of required
  • Add option to enable Gelf publisher
  • Check that graylog2/gelf-php exist when gelf publisher is enabled

Add type hinting

The 2.0 version will support only php > 7 so we can use type hinting

Error if HttpFoundation is not present

In a project without web :

In DefinitionErrorExceptionPass.php line 37:

  Cannot autowire service "Hexanet\Common\MonologExtraBundle\Provider\Session
  \SymfonySessionIdProvider": argument "$session" of method "__construct()" r
  eferences interface "Symfony\Component\HttpFoundation\Session\SessionInterf
  ace" but no such service exists. It cannot be auto-registered because it is
   from a different root namespace.


Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception


  [RuntimeException]
  An error occurred when executing the "'cache:clear --no-warmup'" command:




  In DefinitionErrorExceptionPass.php line 37:

    Cannot autowire service "Hexanet\Common\MonologExtraBundle\Provider\Session
    \SymfonySessionIdProvider": argument "$session" of method "__construct()" r
    eferences interface "Symfony\Component\HttpFoundation\Session\SessionInterf
    ace" but no such service exists. It cannot be auto-registered because it is
     from a different root namespace.

ConsoleExceptionListener - command can be null

$ sf hexaenet:doctor

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getName() on null in /Users/floranbrutel/dev/si/applications/citadel/vendor/hexanet/monolog-extra-bundle/src/EventListener/ConsoleExceptionListener.php:42
Stack trace:
#0 [internal function]: Hexanet\Common\MonologExtraBundle\EventListener\ConsoleExceptionListener->onConsoleException(Object(Symfony\Component\Console\Event\ConsoleErrorEvent), 'console.error', Object(Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher))
#1 /Users/floranbrutel/dev/si/applications/citadel/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php(104): call_user_func(Array, Object(Symfony\Component\Console\Event\ConsoleErrorEvent), 'console.error', Object(Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher))
#2 /Users/floranbrutel/dev/si/applications/citadel/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(212): Symfony\Component\EventDispatcher\Debug\WrappedListener in /Users/floranbrutel/dev/si/applications/citadel/vendor/hexanet/monolog-extra-bundle/src/EventListener/ConsoleExceptionListener.php on line 42

$event->getCommand(); return Command or null : we need to adapt the ConsoleExceptionListener

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.