2017 © Pedro Peláez
 

symfony-bundle logger-extra-bundle

Extra logging features for Monolog in a Symfony2 bundle.

image

silpion/logger-extra-bundle

Extra logging features for Monolog in a Symfony2 bundle.

  • Thursday, October 2, 2014
  • by h4cc
  • Repository
  • 3 Watchers
  • 4 Stars
  • 1,955 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 4 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

LoggerExtraBundle

Build Status Latest Stable Version License Scrutinizer Quality Score Code Coverage HHVM Status Dependency Status Project Status, (*1)

Symfony2 Bundle for Logging related functionality. This bundle can give you these features:, (*2)

  • Add a unique RequestId to each message of the current request.
  • Add a unique SessionId to each message dependent on current session id.
  • Add arbitrary "key: value" pairs to each message of the current request.
  • Create a log entry on a MASTER Request.
  • Create a log entry on a Response.

There is also a Stack Middleware for logging Requests and Responses: silpion/stack-logger, (*3)

Installation

Using Composer:, (*4)

php composer.phar require silpion/logger-extra-bundle

Also add SilpionLoggerExtraBundle to your AppKernel:, (*5)

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...
            new Silpion\LoggerExtraBundle\SilpionLoggerExtraBundle(),
        );
        ...
    }
}

Configuration

By default, this bundle will not do anything! Every feature has to be enabled on its own., (*6)

Example configuration:, (*7)

silpion_logger_extra:

    # If a random request_id should be added to the [extra] section of each log message.
    request_id:           true

    # Class of the used request_id provider.
    request_id_provider:  Silpion\LoggerExtraBundle\Logger\Provider\Request\UniqRequestIdProvider

    # If a salted SHA1 of the session_id should be added to the [extra] section of each log message.
    session_id:           true

    # Class of the used session_id provider.
    session_id_provider:  Silpion\LoggerExtraBundle\Logger\Provider\Session\SymfonySessionIdProvider

    # If the current PID of the PHP Interpreter should be added to the [extra] section of each log message.
    process_id:           true

    # If the session should be started, so the session_id will always be available.
    session_start:        false

    # A list of "key: value" entries that will be set in the [extra] section of each log message (Overwrites existing keys!).
    additions:
        server_id: 42

    logger:

        # Will create a log entry on each incoming request.
        on_request:           true

        # Will create a log entry on each outgoing response.
        on_response:          true

Available Providers

RequestIdProvider

Next to the UniqRequestIdProvider, which will generate a simple sha1 hash, there is also the EnrichedRequestIdProvider that will generate MongoDb ObjectId like hashes containing the current timestamp, machineId, processId. The EnrichedRequestIdProvider will generate request_id, that will be sortable by creation time., (*8)

Usage

If you want to use the current RequestId or SessionId somewhere in your application, see this code:, (*9)

$requestId = $this->get('silpion_logger_extra')->getRequestId();
$sessionId = $this->get('silpion_logger_extra')->getSessionId();

References

Funny enough a example for adding a RequestId is in a Symfony2 Cookbook, but not available in a bundle till now., (*10)

The Versions