dafiti / logger-service-provider
An extended Logger Service Provider for Silex
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 8 040
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 5
Forks: 3
Open Issues: 0
Requires
- php: >=5.4.0
- monolog/monolog: ~1.17.1
- silex/silex: ~1.1
Requires (Dev)
- fabpot/php-cs-fixer: @stable
- phpunit/phpunit: @stable
This package is not auto-updated.
Last update: 2021-06-11 23:46:17 UTC
README
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