PHPackages                             alexlcdee/colorcli - 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. alexlcdee/colorcli

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

alexlcdee/colorcli
==================

Console Logger with color highlighted level tags

238PHP

Since Apr 26Pushed 9y agoCompare

[ Source](https://github.com/alexlcdee/colorcli)[ Packagist](https://packagist.org/packages/alexlcdee/colorcli)[ RSS](/packages/alexlcdee-colorcli/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Color CLI
=========

[](#color-cli)

PHP library for rendering colored CLI messages.

Usage
-----

[](#usage)

#### Installation

[](#installation)

```
composer require alexlcdee/colorcli

```

### Logger

[](#logger)

Logger class is a PSR-3 compatible logger. Provides colored log level tags.

Colors can be customised with

```
setBGColor($level, BackgroundColors $bgcolor = null)
```

and

```
setFGColor($level, ForegroundColors $fgcolor = null)
```

By default, Logger passes error-like messages to STDERR and info-like messages to STDOUT. This behavior can be also customised with

```
setOutputStream($level, resource $stream)
```

Logger has support of context param and placeholders in message.

```
$logger->debug('Debug output from {fileName}:{line}', [
    'fileName' => __FILE__,
    'line' => __LINE__
]);
```

Context key 'exception' accepts instance of Exception and renders exception name with message, filename, line and stacktrace right after logged message.

```
// catch an exception and pass it to log as context param
try {
    // your code here
} catch (Exception $e) {
    $logger->alert("I've caught an exception", ['exception' => $e]);
}
```

Messages with newlines will be padded with empty string with length of level tag.

#### Usage

[](#usage-1)

```
require_once dirname(__DIR__) . '/vendor/autoload.php';

$logger = new \ColorCLI\Logger();

$logger->emergency('System is unusable.');
$logger->alert('Action must be taken immediately.');
$logger->critical('Critical conditions.');
$logger->error('Runtime errors that do not require immediate action but should typically');
$logger->warning('Exceptional occurrences that are not errors.');
$logger->notice('Normal but significant events.');
$logger->info('Interesting events.');
$logger->debug('Detailed debug information.');

$logger->debug('Contextual debug output from {fileName}:{line}', [
    'fileName' => __FILE__,
    'line' => __LINE__
]);

$logger->info("Processing
multiline message");

try {
    (new Throwing())->throwException();
} catch (Exception $e) {
    $logger->alert('Caught an exception!', ['exception' => $e]);
}
```

The example above provides the following output: [![Output example](./docs/sample-output1.png)](./docs/sample-output1.png)

### ColorHelper

[](#colorhelper)

Provides static method to color input string

#### Usage

[](#usage-2)

```
// Print string with red font on yellow background
echo ColorHelper::colorString('I am a RED string on YELLOW background', ForegroundColors::RED(), BackgroundColors::YELLOW());
echo PHP_EOL;
```

The example above provides the following output: [![Output example](./docs/sample-output2.png)](./docs/sample-output2.png)

### BackgroundColors and ForegroundColors

[](#backgroundcolors-and-foregroundcolors)

These classes are simply MyCLabs\\Enum\\Enum classes and provides supported colors lists. [Read more](https://github.com/myclabs/php-enum/blob/master/README.md) about MyCLabs\\Enum

Credits
=======

[](#credits)

ColorHelper idea was taken from article [PHP CLI Colors – PHP Class Command Line Colors (bash)](https://www.if-not-true-then-false.com/2010/php-class-for-coloring-php-command-line-cli-scripts-output-php-output-colorizing-using-bash-shell-colors/)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b9a6abafcf6518c0e17dad6853ecd030611d7b4de5b32dbe48f568febce45fd?d=identicon)[alexlcdee](/maintainers/alexlcdee)

---

Top Contributors

[![alexlcdee](https://avatars.githubusercontent.com/u/9890043?v=4)](https://github.com/alexlcdee "alexlcdee (4 commits)")

---

Tags

colorslogloggerphpphp-clipsr-3

### Embed Badge

![Health badge](/badges/alexlcdee-colorcli/health.svg)

```
[![Health](https://phpackages.com/badges/alexlcdee-colorcli/health.svg)](https://phpackages.com/packages/alexlcdee-colorcli)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B10.9k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1938.5M262](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2326.5M315](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)

PHPackages © 2026

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