PHP code example of bramus / monolog-colored-line-formatter
1. Go to this page and download the library: Download bramus/monolog-colored-line-formatter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bramus / monolog-colored-line-formatter example snippets
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.');
use \Monolog\Logger;
use \Monolog\Handler\StreamHandler;
use \Bramus\Monolog\Formatter\ColoredLineFormatter;
use \Bramus\Monolog\Formatter\ColorSchemes\TrafficLight;
$log = new Logger('DEMO');
$handler = new StreamHandler('php://stdout', Logger::WARNING);
$handler->setFormatter(new ColoredLineFormatter(new TrafficLight()));
$log->pushHandler($handler);
namespace Bramus\Monolog\Formatter\ColorSchemes;
use Monolog\Logger;
use Monolog\Level;
use Bramus\Ansi\Ansi;
use Bramus\Ansi\ControlSequences\EscapeSequences\Enums\SGR;
class TrafficLight implements ColorSchemeInterface
{
/**
* Use the ColorSchemeTrait and alias its constructor
*/
use ColorSchemeTrait {
ColorSchemeTrait::__construct as private __constructTrait;
}
/**
* [__construct description]
*/
public function __construct()
{
// Call Trait Constructor, so that we have $this->ansi available
$this->__constructTrait();
// Our Color Scheme
$this->setColorizeArray(array(
Level::Debug->value => $this->ansi->color([SGR::COLOR_FG_WHITE])->get(),
Level::Info->value => $this->ansi->color([SGR::COLOR_FG_GREEN])->get(),
Level::Notice->value => $this->ansi->color([SGR::COLOR_FG_CYAN])->get(),
Level::Warning->value => $this->ansi->color([SGR::COLOR_FG_YELLOW])->get(),
Level::Error->value => $this->ansi->color([SGR::COLOR_FG_RED])->get(),
Level::Critical->value => $this->ansi->color([SGR::COLOR_FG_RED])->underline()->get(),
Level::Alert->value => $this->ansi->color([SGR::COLOR_FG_WHITE, SGR::COLOR_BG_RED_BRIGHT])->get(),
Level::Emergency->value => $this->ansi->color([SGR::COLOR_BG_RED_BRIGHT])->blink()->color([SGR::COLOR_FG_WHITE])->get(),
));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.