Giter Site home page Giter Site logo

monologmodule's Introduction

MonologModule

Monolog integration into Zend Framework 2

Build Status Latest Stable Version Total Downloads Coverage Status Dependencies Status

Requirements

Installation

MonologModule must be installed through Composer. For Composer documentation, please refer to getcomposer.org.

You can install the module from command line:

$ php composer.phar require neeckeloo/monolog-module:~0.1

Alternatively, you can also add manually the dependency in your composer.json file:

{
    "require": {
        "neeckeloo/monolog-module": "~0.1"
    }
}

Enable the module by adding MonologModule key in your application.config.php file.

Usage

Configuring a logger

This is the configuration of a logger that can be retrieved with key Log\App in the service manager. A channel name default is also defined to identify to which part of the application a record is related.

return [
    'monolog' => [
        'loggers' => [
            'Log\App' => [
                'name' => 'default',
            ],
        ],
    ],
];

Adding a handler

The logger itself does not know how to handle a record. It delegates it to some handlers. The code above registers two handlers in the stack to allow handling records in two different ways.

return [
    'monolog' => [
        'loggers' => [
            'Log\App' => [
                'name' => 'default',
                'handlers' => [
                    'stream' => [
                        'name' => 'Monolog\Handler\StreamHandler',
                        'options' => [
                            'path'   => 'data/log/application.log',
                            'level'  => \Monolog\Logger::DEBUG,
                        ],
                    ],
                    'fire_php' => [
                        'name' => 'Monolog\Handler\FirePHPHandler',
                    ],
                ],
            ],
        ],
    ],
];

Using processors

If you want to add extra information (tags, user IP, ...) to the records before they are handled, you should add some processors. The code above adds two processors that add an unique identifier and the current request URI, request method and client IP to a log record.

return [
    'monolog' => [
        'loggers' => [
            'Log\App' => [
                'name' => 'default',
                'handlers' => [
                    'default' => [
                        'name' => 'Monolog\Handler\StreamHandler',
                        'options' => [
                            'path'   => 'data/log/application.log',
                            'level'  => \Monolog\Logger::DEBUG,
                        ],
                    ],
                ],
                'processors' => [
                    'Monolog\Processor\UidProcessor',
                    'Monolog\Processor\WebProcessor',
                ],
            ],
        ],
    ],
];

Retrieving a logger

Once the configuration is complete, you can retrieve an instance of the logger as below:

$logger = $serviceManager->get('Log\App');
$logger->debug('debug message');

monologmodule's People

Contributors

neeckeloo avatar

Watchers

James Cloos avatar  avatar

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.