baohan / monolog
A configured monolog for out-of-box
1.0.3
2020-01-03 02:23 UTC
Requires
- php: ^7.3
- ext-json: *
- bramus/monolog-colored-line-formatter: ^3.0
- gmponos/guzzle_logger: ^1.1
- guzzlehttp/guzzle: ^6.3
- monolog/monolog: *
This package is auto-updated.
Last update: 2025-01-19 23:09:12 UTC
README
Monolog is a powerful logger, but need some configures before to use for each projects, even if there are almost same config items. So it provides simplest way to reduce these works, that's why the project born.
Installation
$ composer require "baohan/monolog: 1.*"
Example
use Baohan\Monolog\Logger\AppLogger; use Monolog\Logger; require('./vendor/autoload.php'); $extra = [ 'key1' => 'val1' ]; $log = AppLogger::getLogger('demo', $extra); // or grab http request data as extra // $extra = AppLogger::getExtraFromRequest($request); // AppLogger::setExtra($log, $extra); $log->pushHandler(AppLogger::getConsoleHandler(Logger::DEBUG)); $log->pushHandler(AppLogger::getStreamHandler('debug.log', Logger::DEBUG)); $log->pushHandler(AppLogger::getStreamHandler('error.log', Logger::ERROR)); $log->pushHandler(AppLogger::getBearychatHandler('YOUR_API_KEY', Logger::CRITICAL)); $context = [ 'page' => 'demo.php' ]; $log->debug('The first debug message', $context);
It will output:
$ php demo.php
> [2020-01-02T07:30:02.602905+00:00] demo.DEBUG: The first debug message {"page":"demo.php"} {"key1":"val1"}
That's all.