PHPackages                             shalvah/clara - 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. shalvah/clara

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

shalvah/clara
=============

🔊 Simple, pretty, testable console output for CLI apps.

3.3.0(7mo ago)2811.8M—5.2%6MITPHPPHP &gt;=7.4

Since Apr 9Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/shalvah/clara)[ Packagist](https://packagist.org/packages/shalvah/clara)[ RSS](/packages/shalvah-clara/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (6)

Clara 🔊
=======

[](#clara-)

[![image](https://camo.githubusercontent.com/6b79ab2ba92d9eabe0522836282c2a16baa19fbdf39a2c07f22077530dfa2c04/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7368616c7661682f636c6172612e7376673f7374796c653d666c6174)](https://packagist.org/packages/shalvah/clara) [![Total Downloads](https://camo.githubusercontent.com/da6696e03438fc387dd472223f01440cd7ee82e1c0ff8db09886c62d66f5f556/68747470733a2f2f706f7365722e707567782e6f72672f7368616c7661682f636c6172612f646f776e6c6f616473)](https://packagist.org/packages/shalvah/clara) [![Build Status](https://camo.githubusercontent.com/547e55a5726279e3df03b24d21494112dc9d9b2ce00ffa6b43c83175287281ab/68747470733a2f2f7472617669732d63692e636f6d2f7368616c7661682f636c6172612e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/shalvah/clara)

Simple, pretty, testable console output for PHP CLI apps. (Used in [Scribe](http://scribe.knuckles.wtf/laravel).)

Features:

- Colours and emoji to distinguish between log types
- Two different output modes, depending on how much colour you want
- Automatically hide/show debug output
- Can capture console output for easy testing—no need for mocks
- Customizable colour palette

[![Icons mode](./screenshot-icons.png)](./screenshot-icons.png)

*Icons mode*

[![Labels mode](./screenshot-labels.png)](./screenshot-labels.png)

*Labels mode*

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

[](#installation)

(PHP 7.4+)

```
composer require shalvah/clara
```

Using Clara
-----------

[](#using-clara)

```
$output = clara('myappname');

$output->info("Installing package");
$output->debug("Attempt 3 of 5");
$output->warn("The file does not exist.");
$output->error("Something went wrong!");
$output->success("Done. Go and be awesome.");
```

### Picking a mode

[](#picking-a-mode)

By default, Clara uses "icons" mode—the output is coloured differently by output type and an emoji is added (as in the first screenshot above). If you prefer, you can switch to "labels" mode:

```
$output = clara('myappname', \Shalvah\Clara\Clara::MODE_LABELS);
// The default
$output = clara('myappname', \Shalvah\Clara\Clara::MODE_ICONS);
```

In labels mode, (the second screenshot above), the emojis are still present, but the output types are written out, and the main output message is not coloured.

### Disabling colours and emojis

[](#disabling-colours-and-emojis)

If you'd like to output a line of text without the extra formatting provided by the functions above, you can use the `->line()` method instead.

### Customising the colour palette

[](#customising-the-colour-palette)

You can also customise the colours Clara uses for each type, by passing in an array as the third argument, containing your preferred colours:

```
$output = clara('myappname', \Shalvah\Clara\Clara::MODE_ICONS, [
    'info' => 'blue',
]);
```

See [the Symfony docs](https://symfony.com/doc/current/console/coloring.html) for details about supported colours.

Toggling debug output
---------------------

[](#toggling-debug-output)

It's common practice to include a verbose flag (`--verbose`) in your CLI app that lets you show additional (debug) output to the user. With Clara, you can easily enable or disable debug logging:

```
$isVerbose = $this->getFlag('verbose');

// If $isVerbose is true,
// Clara won't print or capture any debug logs
$app1 = clara('app1')->showDebugOutput($isVerbose);
$app1->debug("App 1 - Output 1");

// You can also toggle debug output manually
$app1->hideDebugOutput();
$app1->debug("App 1 - Output 2");

$app1->showDebugOutput();
$app1->debug("App 1 - Output 3");
```

Note that by default, Clara will show all output.

Muting output
-------------

[](#muting-output)

Sometimes when running your app's tests, you don't want to clutter your console with the output messages. You can turn off Clara's output by using the `mute()` and `unmute` static methods. To mute or unmute a specific app, pass in the app name.

```
$output1 = clara('myapp1');
$output2 = clara('myapp2');

// Mute only output from "myapp1"
Clara::mute('myapp1');
// Won't be printed.
$output1->info("Installing package");

// Will be printed
$output2->info("Installing package");

Clara::mute(); // Mute all apps
Clara::unmute("myapp1"); // Unmute myapp1
Clara::unmute(); // Unmute all apps
```

Showing only your app's output.
-------------------------------

[](#showing-only-your-apps-output)

Imagine your app includes another app that uses Clara. By default, the output from all apps will be shown. You can turn off output for all apps but yours by calling `->only()`.

```
// SHow only output from mymainapp
$output1 = clara('mymainapp')->only();

// This is equivalent to doing:
Clara::mute();
Clara::unmute('yourappname');
```

Capturing the output
--------------------

[](#capturing-the-output)

Sometimes you need to assert that your app printed what you expect. An easy way is to use output capturing.

```
Clara::startCapturingOutput('myapp1'); // Clara will start capturing output from myapp1
$output1 = clara('myapp1');
$output1->warn("Going to fail");
$output1->error("Failed");

$capturedOutput = Clara::getCapturedOutput('myapp1');
// $capturedOutput = [
//   "⚠ Going to fail",
//   "✖ Failed",
// ]

Clara::stopCapturingOutput('myapp1');
Clara::clearCapturedOutput('myapp1'); // Will empty saved output
```

You can reset the entire state of Clara to default by calling `Clara::reset()`. This will clear captured output, stop capturing for all apps and unmute all apps.

Setting an output channel
-------------------------

[](#setting-an-output-channel)

By default, Clara outputs to the console, but you can actually output to somewhere else. This is helpful if you're writing a Laravel Artisan command and want to use Clara for output while still capturing the output via Artisan's `->output()` method. All you need to do is call `useOutput` with an instance of `Symfony\Component\Console\Output\OutputInterface` (for Artisan classes, it's `$this->output`).

```
$this->clara = clara('myapp'
  ->showDebugOutput($this->option('verbose'))
  ->useOutput($this->output)
  ->only();
```

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance65

Regular maintenance activity

Popularity54

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 97.6% 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 ~144 days

Recently: every ~393 days

Total

15

Last Release

210d ago

Major Versions

1.1.0 → 2.0.02020-04-10

2.6.0 → 3.0.02021-06-30

PHP version history (2 changes)1.0.0PHP &gt;=7.2.5

3.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef367e338eb001771b4d439508b7a355d62dc2712ff94017393913e853816abb?d=identicon)[shalvah](/maintainers/shalvah)

---

Top Contributors

[![shalvah](https://avatars.githubusercontent.com/u/14361073?v=4)](https://github.com/shalvah "shalvah (81 commits)")[![gabrielrbarbosa](https://avatars.githubusercontent.com/u/12158575?v=4)](https://github.com/gabrielrbarbosa "gabrielrbarbosa (1 commits)")[![maks-oleksyuk](https://avatars.githubusercontent.com/u/90793591?v=4)](https://github.com/maks-oleksyuk "maks-oleksyuk (1 commits)")

---

Tags

logclilogging

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shalvah-clara/health.svg)

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

###  Alternatives

[league/tactician-logger

Adds PSR-3 logging support to the Tactician command bus

649.6M9](/packages/league-tactician-logger)[trash-panda/progress-bar-log

Component to display a progress bar and last X logs at the same time

4119.2k](/packages/trash-panda-progress-bar-log)[melihovv/laravel-log-viewer

A Laravel log viewer

1231.5k1](/packages/melihovv-laravel-log-viewer)

PHPackages © 2026

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