PHPackages                             regho/monolog-colored-line-formatter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. regho/monolog-colored-line-formatter

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

regho/monolog-colored-line-formatter
====================================

Colored Line Formatter for Monolog

v0.0.1(3y ago)09MITPHPPHP ^8.1

Since Dec 16Pushed 3y agoCompare

[ Source](https://github.com/regho/monolog-colored-line-formatter)[ Packagist](https://packagist.org/packages/regho/monolog-colored-line-formatter)[ RSS](/packages/regho-monolog-colored-line-formatter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Monolog Colored Line Formatter
==============================

[](#monolog-colored-line-formatter)

[![Build Status](https://github.com/Regho/monolog-colored-line-formatter/workflows/CI/badge.svg)](https://github.com/Regho/monolog-colored-line-formatter/actions) [![Source](https://camo.githubusercontent.com/05030cf0da87858dbc446eb059540c9021a9d17a6bd9f745cfec5b386250b4ab/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d526567686f2f6d6f6e6f6c6f672d2d636f6c6f7265642d2d6c696e652d2d666f726d61747465722d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Regho/monolog-colored-line-formatter) [![Supported PHP Versions](https://camo.githubusercontent.com/b70aff7b9eed3b765a7851119b4602344f0c284db4b267817028e2ed34daf5d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f526567686f2f6d6f6e6f6c6f672d636f6c6f7265642d6c696e652d666f726d6174746572)](https://github.com/Regho/monolog-colored-line-formatter) [![Version](https://camo.githubusercontent.com/d1f92b00c2d1023483822054dd6970fb21eceed09d6652dcd1180da5a3bb0bfa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f526567686f2f6d6f6e6f6c6f672d636f6c6f7265642d6c696e652d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Regho/monolog-colored-line-formatter) [![Downloads](https://camo.githubusercontent.com/bd3f48b74edc0a7e6932eb2f569ca4c150e61dce78765d8c3639e316258ac5f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f526567686f2f6d6f6e6f6c6f672d636f6c6f7265642d6c696e652d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Regho/monolog-colored-line-formatter/stats) [![License](https://camo.githubusercontent.com/4f63111d941a842020e58f610834fe04c72c88f14f3b487da78def250b3dd7af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f526567686f2f6d6f6e6f6c6f672d636f6c6f7265642d6c696e652d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/Regho/monolog-colored-line-formatter/blob/master/LICENSE.txt)

A Formatter for Monolog with color support Built by Regho! -

About
-----

[](#about)

`Regho/monolog-colored-line-formatter` is a formatter for use with [Monolog](https://github.com/Seldaek/monolog). It augments the [Monolog LineFormatter](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php) by adding color support. To achieve this `Regho/monolog-colored-line-formatter` uses ANSI Escape Sequences – [provided by `Regho/ansi-php`](https://github.com/Regho/ansi-php) – which makes it perfect for usage on text based terminals (viz. the shell).

`Regho/monolog-colored-line-formatter` ships with a default color scheme, yet it can be adjusted to fit your own needs.

Prerequisites/Requirements
--------------------------

[](#prerequisitesrequirements)

- PHP 7.2 or greater
- Monolog 2.0 or greater

*Looking for a version compatible with Monolog 1.x? Check out the `monolog-1.x` branch then. The version of `monolog-colored-line-formatter` that is compatible with Monolog 1.x, is `monolog-colored-line-formatter` version `~2.0`*

Installation
------------

[](#installation)

Installation is possible using Composer.

Install `monolog-colored-line-formatter`, compatible with Monolog 2.x:

```
composer require Regho/monolog-colored-line-formatter ~3.0
```

Install `monolog-colored-line-formatter`, compatible with Monolog 1.x:

```
composer require Regho/monolog-colored-line-formatter ~2.0
```

Usage
-----

[](#usage)

Create an instance of `\Regho\Monolog\Formatter\ColoredLineFormatter` 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 \Regho\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.');
```

Color Schemes
-------------

[](#color-schemes)

### Available Color Schemes

[](#available-color-schemes)

#### Color Scheme: DefaultScheme

[](#color-scheme-defaultscheme)

[![Monolog Colored Line Formatter](https://user-images.githubusercontent.com/11269635/28756233-c9f63abe-756a-11e7-883f-a084f35c55e7.gif)](https://user-images.githubusercontent.com/11269635/28756233-c9f63abe-756a-11e7-883f-a084f35c55e7.gif)

#### Color Scheme: TrafficLight

[](#color-scheme-trafficlight)

[![Monolog Colored Line Formatter](https://user-images.githubusercontent.com/11269635/28756238-df0a5598-756a-11e7-929a-201bef89e6a2.gif)](https://user-images.githubusercontent.com/11269635/28756238-df0a5598-756a-11e7-929a-201bef89e6a2.gif)

### Activating a Color Scheme

[](#activating-a-color-scheme)

Color Schemes are defined as classes. If you do not provide any color scheme the default one will be used.

To activate a color scheme pass it as the first argument of the `ColoredLineFormatter` Constructor. All successive arguments are the ones as required by the `\Monolog\Formatter\LineFormatter` class.

```
use \Monolog\Logger;
use \Monolog\Handler\StreamHandler;
use \Regho\Monolog\Formatter\ColoredLineFormatter;
use \Regho\Monolog\Formatter\ColorSchemes\TrafficLight;

$log = new Logger('DEMO');
$handler = new StreamHandler('php://stdout', Logger::WARNING);
$handler->setFormatter(new ColoredLineFormatter(new TrafficLight()));
$log->pushHandler($handler);
```

Alternatively it's also possible to activate it using the `setColorScheme()` method of a `ColoredLineFormatter` instance.

### Creating your own Custom Color Scheme

[](#creating-your-own-custom-color-scheme)

To define your own color scheme make a class that implements the `\Regho\Monolog\Formatter\ColorSchemes\ColorSchemeInterface` interface. To make things more easy a trait `ColorSchemeTrait` is defined.

```
namespace Regho\Monolog\Formatter\ColorSchemes;

use Monolog\Logger;
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(
            Logger::DEBUG => $this->ansi->color(SGR::COLOR_FG_WHITE)->get(),
            Logger::INFO => $this->ansi->color(SGR::COLOR_FG_GREEN)->get(),
            Logger::NOTICE => $this->ansi->color(SGR::COLOR_FG_CYAN)->get(),
            Logger::WARNING => $this->ansi->color(SGR::COLOR_FG_YELLOW)->get(),
            Logger::ERROR => $this->ansi->color(SGR::COLOR_FG_RED)->get(),
            Logger::CRITICAL => $this->ansi->color(SGR::COLOR_FG_RED)->underline()->get(),
            Logger::ALERT => $this->ansi->color(array(SGR::COLOR_FG_WHITE, SGR::COLOR_BG_RED_BRIGHT))->get(),
            Logger::EMERGENCY => $this->ansi->color(SGR::COLOR_BG_RED_BRIGHT)->blink()->color(SGR::COLOR_FG_WHITE)->get(),
        ));
    }
}
```

Please refer to [the `Regho/ansi-php` documentation](https://github.com/Regho/ansi-php) to define your own styles and colors.

Unit Testing
------------

[](#unit-testing)

`Regho/monolog-colored-line-formatter` ships with unit tests using [PHPUnit](https://github.com/sebastianbergmann/phpunit/).

- If PHPUnit is installed globally run `phpunit` to run the tests.
- If PHPUnit is not installed globally, install it locally through composer by running `composer install --dev`. Run the tests themselves by calling `vendor/bin/phpunit`.

Unit tests are also automatically run [on GitHub Actions](https://github.com/Regho/monolog-colored-line-formatter/actions?query=workflow%3ACI)

License
-------

[](#license)

`Regho/monolog-colored-line-formatter` is released under the MIT public license. See the enclosed `LICENSE.txt` for details.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1244d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/67935860101008aa8170e3f3ec87d10c1517c13bc9fab800c144acaeef9f972f?d=identicon)[Apkahym](/maintainers/Apkahym)

---

Top Contributors

[![bramus](https://avatars.githubusercontent.com/u/213073?v=4)](https://github.com/bramus "bramus (65 commits)")[![LeSuisse](https://avatars.githubusercontent.com/u/737767?v=4)](https://github.com/LeSuisse "LeSuisse (2 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (2 commits)")[![Apkahym](https://avatars.githubusercontent.com/u/2273827?v=4)](https://github.com/Apkahym "Apkahym (2 commits)")[![lbausch](https://avatars.githubusercontent.com/u/5747127?v=4)](https://github.com/lbausch "lbausch (1 commits)")[![Firewall](https://avatars.githubusercontent.com/u/505000?v=4)](https://github.com/Firewall "Firewall (1 commits)")[![loyating](https://avatars.githubusercontent.com/u/5088390?v=4)](https://github.com/loyating "loyating (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/regho-monolog-colored-line-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/regho-monolog-colored-line-formatter/health.svg)](https://phpackages.com/packages/regho-monolog-colored-line-formatter)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[bramus/monolog-colored-line-formatter

Colored Line Formatter for Monolog

1406.9M46](/packages/bramus-monolog-colored-line-formatter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
