PHPackages                             bramus/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. bramus/monolog-colored-line-formatter

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

bramus/monolog-colored-line-formatter
=====================================

Colored Line Formatter for Monolog

3.1.2(2y ago)1406.9M—7.2%18[4 issues](https://github.com/bramus/monolog-colored-line-formatter/issues)[1 PRs](https://github.com/bramus/monolog-colored-line-formatter/pulls)20MITPHPPHP ^8.1

Since Dec 17Pushed 2y ago2 watchersCompare

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

READMEChangelogDependencies (3)Versions (25)Used By (20)

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

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

[![Build Status](https://github.com/bramus/monolog-colored-line-formatter/workflows/CI/badge.svg)](https://github.com/bramus/monolog-colored-line-formatter/actions) [![Source](https://camo.githubusercontent.com/fa71d36a254133913208a4af98d106172a051b3eef42a324d9131e2881e3009a/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6272616d75732f6d6f6e6f6c6f672d2d636f6c6f7265642d2d6c696e652d2d666f726d61747465722d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/bramus/monolog-colored-line-formatter) [![Supported PHP Versions](https://camo.githubusercontent.com/bc4b8ec19868f962e1efcecceb0b54ab3935f1b0ab5588e9d955a837e399ff4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6272616d75732f6d6f6e6f6c6f672d636f6c6f7265642d6c696e652d666f726d6174746572)](https://github.com/bramus/monolog-colored-line-formatter) [![Version](https://camo.githubusercontent.com/3a5b913e00a44c722ec34ba3ccfe17267a66d8a621ba281e981bc74f6ec79090/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6272616d75732f6d6f6e6f6c6f672d636f6c6f7265642d6c696e652d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bramus/monolog-colored-line-formatter) [![Downloads](https://camo.githubusercontent.com/4e703850ad49179666d1ef1c948c9f369a988dda970ccddeacc0715532d571ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6272616d75732f6d6f6e6f6c6f672d636f6c6f7265642d6c696e652d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bramus/monolog-colored-line-formatter/stats) [![License](https://camo.githubusercontent.com/10216579598048c0687c60209b1d3cffc5e1abb57315f7bad714742f23d04e19/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6272616d75732f6d6f6e6f6c6f672d636f6c6f7265642d6c696e652d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/bramus/monolog-colored-line-formatter/blob/master/LICENSE.txt)

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

About
-----

[](#about)

`bramus/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 `bramus/monolog-colored-line-formatter` uses ANSI Escape Sequences – [provided by `bramus/ansi-php`](https://github.com/bramus/ansi-php) – which makes it perfect for usage on text based terminals (viz. the shell).

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

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

[](#prerequisitesrequirements)

- PHP 8.1 or greater
- Monolog 3.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`*

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

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

[](#installation)

Installation is possible using Composer.

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

```
composer require bramus/monolog-colored-line-formatter ~3.1
```

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

```
composer require bramus/monolog-colored-line-formatter ~3.0.0
```

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

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

Usage
-----

[](#usage)

Create an instance of `\Bramus\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 \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.');
```

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 \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);
```

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 `\Bramus\Monolog\Formatter\ColorSchemes\ColorSchemeInterface` interface. To make things more easy a trait `ColorSchemeTrait` is defined.

```
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(),
        ));
    }
}
```

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

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

[](#unit-testing)

`bramus/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/bramus/monolog-colored-line-formatter/actions?query=workflow%3ACI)

License
-------

[](#license)

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

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity60

Solid adoption and visibility

Community34

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 85.7% 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

Every ~150 days

Recently: every ~248 days

Total

22

Last Release

1004d ago

Major Versions

1.5 → 2.02015-01-06

2.0.3 → 3.0.02019-02-12

PHP version history (7 changes)1.1PHP &gt;=5.3.3

1.5PHP &gt;=5.4.0

3.0.0PHP ^7.1

3.0.3PHP ^7.2

3.0.5PHP ^7.2|~8.0.0

3.0.6PHP ^7.2|^8.0

3.1.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/213073?v=4)[Bramus](/maintainers/bramus)[@bramus](https://github.com/bramus)

---

Top Contributors

[![bramus](https://avatars.githubusercontent.com/u/213073?v=4)](https://github.com/bramus "bramus (66 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)")[![lbausch](https://avatars.githubusercontent.com/u/5747127?v=4)](https://github.com/lbausch "lbausch (1 commits)")[![loyating](https://avatars.githubusercontent.com/u/5088390?v=4)](https://github.com/loyating "loyating (1 commits)")[![taka-oyama](https://avatars.githubusercontent.com/u/748854?v=4)](https://github.com/taka-oyama "taka-oyama (1 commits)")[![tomsommer](https://avatars.githubusercontent.com/u/149171?v=4)](https://github.com/tomsommer "tomsommer (1 commits)")[![vdauchy](https://avatars.githubusercontent.com/u/26772554?v=4)](https://github.com/vdauchy "vdauchy (1 commits)")[![Firewall](https://avatars.githubusercontent.com/u/505000?v=4)](https://github.com/Firewall "Firewall (1 commits)")[![henry11996](https://avatars.githubusercontent.com/u/51729131?v=4)](https://github.com/henry11996 "henry11996 (1 commits)")

---

Tags

ansicolorloggingmonologphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/monolog-bridge

Provides integration for Monolog with various Symfony components

2.6k189.7M258](/packages/symfony-monolog-bridge)[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[illuminate/log

The Illuminate Log package.

6224.3M518](/packages/illuminate-log)[honeybadger-io/honeybadger-php

Honeybadger PHP library

381.5M4](/packages/honeybadger-io-honeybadger-php)[graycore/magento2-stdlogging

A Magento 2 module that changes all logging handlers to stdout

2382.6k](/packages/graycore-magento2-stdlogging)

PHPackages © 2026

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