Skip to content

projek-xyz/slim-monolog

Repository files navigation

Monolog Logger Integration for Slim micro framework 3

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.

About

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

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

Packages

No packages published

Languages