projek-xyz/slim-monolog

Write log file on your Slim 3 application with Monolog logger.

v0.1.6 2016-10-09 23:22 UTC

This package is auto-updated.

Last update: 2024-11-16 22:39:28 UTC


README

LICENSE VERSION Build Status Coveralls Code Climate Code Climate SensioLabs Insight

Write log file on your Slim 3 application with Monolog logger.

Install

Via Composer

$ composer require projek-xyz/slim-monolog --prefer-dist

Requires Slim micro framework 3 and PHP 5.5.0 or newer.

Usage

// Create Slim app
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register Monolog helper:
// Option 1, using MonologProvider
$container->register(new \Projek\Slim\MonologProvider);

// Option 2, using Closure
$container['logger'] = function ($c) {
    $settings = [
        // Path to log directory
        'directory' => 'path/to/logs',
        // Log file name
        'filename' => 'my-app.log',
        // Your timezone
        'timezone' => 'Asia/Jakarta',
        // Log level
        'level' => 'debug',
        // List of Monolog Handlers you wanna use
        'handlers' => [],
    ];

    return new \Projek\Slim\Monolog('slim-app', $settings);
};

// Define a log middleware
$app->add(function ($req, $res, $next) {
    $return = $next($req, $res);

    $this->logger->info('Something happen');

    return $return;
});

// Run app
$app->run();

NOTE:

  • If you are using option 1 please make sure you already have $container['settings']['logger'] in your configuration file.
  • $settings['filename'] only required if you have $settings['directory']
  • Set $settings['directory'] to syslog to use System Log.

Contributing

Please see CONTRIBUTING and CONDUCT for details.

License

This library is open-sourced software licensed under MIT license.