2017 © Pedro Peláez
 

symfony-bundle log-bridge-bundle

SF2 Proxy manager Log

image

m6web/log-bridge-bundle

SF2 Proxy manager Log

  • Monday, February 12, 2018
  • by M6Web
  • Repository
  • 23 Watchers
  • 10 Stars
  • 119,120 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 4 Open issues
  • 46 Versions
  • 6 % Grown

The README.md

LogBridgeBundle Build Status

Symfony Bundle to log Request/Response with Monolog., (*1)

NOTE: The actual version of this bundle support Symfony >= 4.4. If you need support for older versions, please use ~7.0 release., (*2)

Features

  • semantic configuration
  • sf2 event dispatcher integration
  • log request filter

Install

With composer, (*3)

    "require": {
        "m6web/log-bridge-bundle": "~3.0"
    }

Add to your AppKernel, (*4)

    $bundles = [
    // ...
        new M6Web\Bundle\LogBridgeBundle\M6WebLogBridgeBundle(),
    //...
    ];

Usage

# app/config.yml

m6_web_log_bridge:
    active_filters:
        - get_article_error
        - post_article_all
        - all_error
    filters:
            get_article_error:
                route: get_article
                routes: ['get_article']
                method: ['GET']
                status: [422, 500]
                level: 'error'
                options:
                    response_body: true # from add Response body content (with DefaultFormatter)
            post_article_all:
                route: post_article
                routes: ['post_article']
                method: ~ # from all methods
                status: ~ # from all status
            get_article_not_found:
                route: get_article
                routes: ['get_article']
                method: ['GET']
                status: [404]
                level: 'warning'
            edit_category:
                route: get_category
                routes: ['get_category']
                method: ['POST', 'PUT']
                status: [400-422, ^510, !530-550]
                level: 'error'
                options:
                    post_parameters: true # From add post parameters in response content (with DefaultFormatter)
            all_error: # All route, all method in error
                route: ~
                routes: ~
                method: ~
                status: [31*, 4*, 5*]
                level: 'critical'
    content_formatter: m6web_log_bridge.log_content_formatter # Provider service name
    ignore_headers: # key list from mask/ignore header info
        - php-auth-pw
    prefix_key: ~ # define prefix key on log context
    logger: 
        channel: my_channel_to_log # monolog channel, optional, default 'log_bridge'

Routes support multiples formats :, (*5)

routes: ['my_route'] # Add only this route
routes: ['my_route', 'another_route'] # Add multiples routes
routes: ['!excluded_one', '!excluded_two'] # Add all routes except the excluded

By default, level is info, (*6)

You can declare all the options you want. By default, only response_body and post_parameters is supported by the DefaultFormatter, (*7)

Status support multiples formats :, (*8)

status: [401] # Add status 401
status: [^456] # Add status hundred greater than 450 (456, 457, 458, ..., 499)
status: [4*] # Add status hundred (200, 400, 401, 402, ..., 499)
status: [41*] # Add status decade (410, 411, 412, ..., 419)
status: [425-440] # Add range status (425, 426, 427, ..., 440)
status: [2*, 301, !203-210] # Add status (200, 201, 202, 211, ..., 299, 301)

Instead of add can be use ! to exclude status, (*9)

By default, this bundle use a builtin logger with monolog support m6web_log_bridge.logger You can override this configuration by writing your own logger who must implements Psr\Log\LoggerInterface :, (*10)

# app/config.yml

m6_web_log_bridge:
    logger: 
        service: acme.logger
services:
    acme.logger:
        class: Acme\DemoBundle\Logger\logger
        arguments: ["@logger"]
        tags:
            - { name: monolog.logger, channel: log_bridge }

Acme\DemoBundle\Logger\logger must be implement Psr\Log\LoggerInterface, (*11)

Define your Provider from format log content

It is advisable to extend default provider M6Web\Bundle\LogBridgeBundle\Formatter\DefaultFormatter, (*12)

default definition from service provider :, (*13)

    services:
        m6web_log_bridge.log_content_provider:
            class: '%m6web_log_bridge.log_content_provider.class%'
            arguments:
                - '%kernel.environment%'
                - '%m6web_log_bridge.ignore_headers%'
                - '%m6web_log_bridge.prefix_key%'
            calls:
                - [ setTokenStorage, [ '@security.token_storage' ] ]

From override :, (*14)

    services:
        acme.my_log_provider:
            class: Acme\Bundle\MyBundle\Provider\LogContentProvider
            parent: m6web_log_bridge.log_content_formatter

or simply override this parameter : m6web_log_bridge.log_content_formatter.class, (*15)

Log contents example

Request
------------------------
content-type        : 
content-length      : 
host                : domain.tld
x-real-ip           : *********
x-forwarded-for     : *********
x-forwarded-proto   : http
x-forwarded-port    : 80
remote-user         : u_glinel
connection          : close
cache-control       : max-age=0
authorization       : Basic ************
accept              : text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
user-agent          : Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/127.0.0.1 Chrome/127.0.0.1 Safari/537.36
accept-encoding     : gzip,deflate,sdch
accept-language     : fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
cookie              : PHPSESSID=************
php-auth-user       : u_glinel
x-php-ob-level      : 1
------------------------
Response
------------------------
HTTP 1.0 200
Age:           2
Etag:          
Vary:          
Cache-Control: no-cache
Content-Type:  application/json
Date:          dd mm yyyy hh:ii:ss GMT
------------------------
Response body
------------------------
Here response content

Logging exceptions

The bundle allow detailed logging of exceptions. This is ensured by the use of exception.log in the configuration., (*16)

# app/config.yml

m6_web_log_bridge:
    exception: 
        log: true
        request_attribute: LogBridgeException

This switch allows the bundle to register a listener which will save any received exception and passed it within the request under the defined attribute., (*17)

If you use the default formatter, change it using the configuration. The bundle provides another formatter implementation able to log exceptions., (*18)

# app/config.yml

m6_web_log_bridge:
    content_formatter: m6web_log_bridge.log_content_exception_formatter

If you prefer to use your own formatter, you will be able to read exceptions directly from the request under the attribute specified in m6_web_log_bridge.exception.request_attribute., (*19)

Tests

You can run the unit tests with the following command:, (*20)

    php bin/atoum -d src/M6Web/Bundle/LogBridgeBundle/Tests/Units

The Versions

12/02 2018
21/12 2015
23/10 2015

dev-fix/make-symfony-security-bundle-optional

dev-fix/make-symfony-security-bundle-optional

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

03/07 2015

dev-feature/symfony-2.7

dev-feature/symfony-2.7

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

10/02 2015

dev-feature/default-logger

dev-feature/default-logger

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

03/02 2015

dev-feature/add-request-uri

dev-feature/add-request-uri

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

09/10 2014

v2.1.4

2.1.4.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

08/10 2014

v2.1.3

2.1.3.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

03/10 2014

v2.1.2

2.1.2.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

03/10 2014

v2.1.1

2.1.1.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

03/10 2014

v2.1.0

2.1.0.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

01/10 2014

v2.0.0

2.0.0.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

19/08 2014

v1.1.0

1.1.0.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

30/07 2014

dev-feature/response-by-provider

dev-feature/response-by-provider

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

19/05 2014

dev-feature/phpcs

dev-feature/phpcs

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

14/05 2014

v1.0.5

1.0.5.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

14/05 2014

dev-feature/request-url

dev-feature/request-url

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

19/03 2014

1.0.4

1.0.4.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

18/03 2014

v1.0.3

1.0.3.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

13/03 2014

v1.0.0

1.0.0.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires

13/03 2014

v1.0.1

1.0.1.0

SF2 Proxy manager Log

  Sources   Download

The Requires

 

The Development Requires