Over a year ago I quickly whipped up a Colored Line Formatter for use with Monolog. As I’m building colorised output into Mixed Content Scan I – finally – took the time to actually put the darn thing out in the open.
bramus/monolog-colored-line-formatter
is a formatter for use with Monolog. It augments the Monolog LineFormatter by adding color support. To achieve thisbramus/monolog-colored-line-formatter
uses ANSI Escape Sequences which makes it perfect for usage on text based terminals (viz. the shell).
Installation is possible via Composer
composer require bramus/monolog-colored-line-formatter ~1.0
To use it create an instance of it and set it as the formatter for the \Monolog\Handler\StreamHandler
that you use with your \Monolog\Logger
instance.
use \Monolog\Logger;
use \Monolog\Handler\StreamHandler;
use \Bramus\Monolog\Formatter\ColoredLineFormatter;
$log = new Logger('DEMO');
$handler = new StreamHandler('php://stdout', Logger::WARNING);
$handler->setFormatter(new ColoredLineFormatter());
$log->pushHandler($handler);
$log->addError('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
The color scheme can be adjusted if one needs to.