projek-xyz / slim-monolog
Write log file on your Slim 3 application with Monolog logger.
Fund package maintenance!
Open Collective
Installs: 15 849
Dependents: 1
Suggesters: 0
Security: 0
Stars: 11
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=5.5.0
- monolog/monolog: ~1.21
- slim/slim: ~3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: ~2.7
This package is auto-updated.
Last update: 2024-10-16 22:33:44 UTC
README
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']
tosyslog
to use System Log.
Contributing
Please see CONTRIBUTING and CONDUCT for details.
License
This library is open-sourced software licensed under MIT license.