dafiti/logger-service-provider

An extended Logger Service Provider for Silex

0.3.0 2015-10-28 19:11 UTC

This package is not auto-updated.

Last update: 2021-02-19 22:17:01 UTC


README

Build Status Scrutinizer Code Quality Code Coverage HHVM Latest Stable Version Total Downloads License

An extended Logger Service Provider for Silex based on Monolog

Instalation

The package is available on Packagist. Autoloading is PSR-4 compatible.

{
    "require": {
        "dafiti/logger-service-provider": "dev-master"
    }
}

Usage

Basic

use Silex\Application;
use Dafiti\Silex\LoggerServiceProvider;

$app = new Application();
$app->register(new LoggerServiceProvider(), [
    'logger.log_folder' => 'data/logs/',
    'logger.level'      => 'debug'
]);

// Create Logger - (StreamHandler default)
$app['logger.create']('app');

Logger with level, handlers and processors

// Create Logger with another handlers
$app['logger.create']('worker', 'info', [
    new FirePHPHandler(),
    new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM)
]);


// Create Logger with processors
$app['logger.create']('worker', 'info', [], [
    new Processor\UidProcessor()
]);

Log example

// Log something
$app['logger.manager']->get('worker')->log('something');
//or
$app['logger.manager']->worker->log('something');

Customer Logger

class Custom extends \Dafiti\Silex\Log\Logger
{
}

$app['logger.manager']->add(new Custom('custom'));

Logger exists

// Check if logger exists
$app['logger.manager']->has('worker'); //boolean

Factory handler

$worker = [
    'class' => '\Monolog\Handler\StreamHandler',
    'params' => [ // class parameters
        'stream'         => '/tmp/worker.log',
        'level'          => 'info',
        'bubble'         => false,
        'filePermission' => null,
        'useLocking'     => true
        
    ]
];
$app['logger.handler']($worker);

Factory multiple loggers

$loggers = [
    'process' => [
        'level' => 'debug',
        'handlers' => [
            [
                'class' => '\Monolog\Handler\StreamHandler',
                'params' => [
                    'stream' => '/tmp/process.log'
                ]
            ],
        ]
    ],
    'mail' => [
        'handlers' => [
            [
                'class'  => '\Monolog\Handler\NativeMailerHandler',
                'params' => [
                    'to' => 'some@some.com',
                    'subject' => 'Wat!',
                    'from' => 'thing@thing.com'
                ]
            ]
        ]
    ]
];

$app['logger.factory']($loggers);

License

MIT License