Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrispappas's avatar

Configure Artisan Console Error Colors?

When using Phpstorm with Darcula theme (or really any console theme with dark background and light text colors), I find it nearly impossible to read the error output when you mess up an artisan command.

This happens on both Ubuntu 16.04.1 and OSX 10.14 or whatever the current version is (work laptop is in my backpack and I'm lazy), in Phpstorm as well as iTerm.

The greyish/white color on the pink background is nearly unreadable and many of my co-workers agree. It would be nice to be able to customize this setting somehow, but I can't find anything about it on the web.

Help me, Laracasts, you're my only hope. :)

0 likes
14 replies
toniperic's avatar
Level 30

@chrispappas, of course that's possible.

In handle() method on your Artisan console class, you can do something along the lines of

public function handle()
{
    $this->output->getFormatter()->setStyle('error', new OutputFormatterStyle('yellow', 'blue'));
    throw new Exception('foo');
}

will yield

result

You could probably find a better place for this, though, such as configure() method.

Greetings to you and your co-workers from Croatia. :)

4 likes
chrispappas's avatar

This would seem to work for one particular command, however I'd like to configure it globally for all commands. Looking into this now, but if you or others have any ideas that would be helpful.

And thank you from Canada

toniperic's avatar

@chrispappas there is a way to do that. There are actually two ways to go, both of them are clean.

The first way

Create an abstract class which every other console command you create will extend, and create the following method in it:

protected function configure()
{
    $this->output->getFormatter()->setStyle('error', new OutputFormatterStyle('yellow', 'blue'));
}

The second way

Even though I admit it's not overly pretty, I think it's a better way to go.

In project root, find artisan file, and locate the following statement:

$status = $kernel->handle(
    $input = new Symfony\Component\Console\Input\ArgvInput,
    new Symfony\Component\Console\Output\ConsoleOutput
);

replace it with

$outputFormatter = new OutputFormatter(false, [
    'error' => new OutputFormatterStyle('yellow', 'blue')
]);

$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $outputFormatter);

$status = $kernel->handle(
    $input = new Symfony\Component\Console\Input\ArgvInput,
    $output
);

Note the second parameter passed when instantiating OutputFormatter - that way you can modify any coloring you like such as info, comment, question or even create custom ones and use them. For example:

$outputFormatter = new OutputFormatter(false, [
    'error' => new OutputFormatterStyle('yellow', 'blue'),
    'foo' => new OutputFormatterStyle('magenta', 'yellow'),
]);

and then use it like:

$this->output->writeln('<foo>bar</foo>');

Hope this helps.

johnshipp's avatar

Another way (not pretty either, but, works) :) ...

In ./artisan.php

Replace

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

$status = $kernel->handle(
    $input = new Symfony\Component\Console\Input\ArgvInput,
    new Symfony\Component\Console\Output\ConsoleOutput
);

with...

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

$output = new Symfony\Component\Console\Output\ConsoleOutput;
$output->getFormatter()->setStyle('error', new \Symfony\Component\Console\Formatter\OutputFormatterStyle('yellow', 'blue'));

$status = $kernel->handle(
    $input = new Symfony\Component\Console\Input\ArgvInput,
    $output
);
2 likes
dsandber's avatar

I couldn't get this working with Laravel 7.1 w/ "artisan tinker".

The formatting seems to be changed in "ShellOutput" rather than "ConsoleOutput".

Anyone know how to get this working other than patching initFormatters() in ShellOutput?

angeloj's avatar

It is not an Artisan issue. Artisan uses ANSI colors. It uses ANSI color red for the error. If it is unreadable (in whatever IDE/terminal you use) you should change the ANSI color red in your IDE/terminal.

In the case of PHPStorm, go to File -> Settings -> Editor -> Color Scheme -> Console Colors. Open ANSI Colors panel, go to Red and change the Foreground color to a red color that suits you.

This is the only solution you have to use to fix this unreadable error output.

3 likes
ddejjavvu's avatar

This is how i do it...

  1. create a file named Command.php in App\Console
  2. in Command.php add
<?php

namespace App\Console;

use Illuminate\Console\Command as IlluminateCommand;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Command extends IlluminateCommand
{
    public function run(InputInterface $input, OutputInterface $output)
    {
        // Set extra colors.
        // The most problem is $output->getFormatter() don't work...
        // So create new formatter to add extra color.

        $formatter = new OutputFormatter($output->isDecorated());
        $formatter->setStyle('red', new OutputFormatterStyle('red', 'black'));
        $formatter->setStyle('green', new OutputFormatterStyle('green', 'black'));
        $formatter->setStyle('yellow', new OutputFormatterStyle('yellow', 'black'));
        $formatter->setStyle('blue', new OutputFormatterStyle('blue', 'black'));
        $formatter->setStyle('magenta', new OutputFormatterStyle('magenta', 'black'));
        $formatter->setStyle('yellow-blue', new OutputFormatterStyle('yellow', 'blue'));
        $output->setFormatter($formatter);

        $result = parent::run($input, $output);
    }

}
  1. now your console command should extend App\Console\Command instead of Illuminate\Console\Command

example Console Command

<?php

namespace App\Console\Commands;

use App\Console\Command;

class PopulateMovies extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'populate:movies';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Populate movies database';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->line("This text is Yellow with Blue background "  , 'yellow-blue');
        $this->line("This text is Yellow"  , 'yellow');
        $this->line("This text is Red"  , 'red');
        $this->line("This text is Green"  , 'green');
        $this->line("This text is White"  , 'white');
    }
}

Symfony console coloring docs https://symfony.com/doc/current/console/coloring.html

Florian's avatar

You could also changed the ANSI color mapping in PHPStorm to achieve a much more readable error output from Artisan commands.

Goto Settings -> Editor -> Color Scheme -> Console Colors

In color entry tree select "ANSI Colors" -> "Gray" and change its foreground value to, let's say, #F6F6F6.

No need to change Artisan dependencies or extending Command class or whatsoever.

3 likes
TxNuno's avatar

Thank you @angeloj. I just changed the ANSI colors in phpstorm and this fixed my issue.

nategg's avatar

I'm a noob, but seems to me changing ansi colors to make it readable, isn't that like saying now black is green? Am I missing something? (Attempting to write/alter handle method for me now would probably land me in a world of hurt.)

Nevertheless, I tried it, changed gray to both white and then black, neither affected the error output. Would I have to restart or something? Tried that. Or maybe the error foreground is not exactly gray so it's not affecting it?

There is a setting Editor>Color Scheme>Console Colors>Error Output that is a very readable bold black A0202 on pink/purple 3638F that somehow is not connected to an error given using tinker. Is that not what that setting is supposed to set? What are the console color settings for if not that?

rvwoens's avatar

The underlying symphony console class also supports a tag in any string to change color:

$this->info("<fg=red>This is red</> this is default color");

or even:

$this->info("<fg=blue;bg=white>important!</>");

Note: You need to close with </> !

nategg's avatar

Thanks for contributing to this. I'm still a noob 8 months later (at least re: phpStorm console colors) . I don't understand why it's oop code that is used to fix the colors. Why is it not phpStorm settings? Also, if I use your code (or anyone's) is it only temporary; do I have to run it each time I open the program, or will it change a permanent setting?

knutle's avatar

I ended up here while trying to solve this same problem, so I figured I would share two other possible solutions.

I ended up configuring the ANSI color White (Gray) in PHPStorm to inherit values from Console -> Standard output. This lets me switch between light and dark mode, while leaving the errors still fairly easy to read in both modes. (Preferences | Editor | Color Scheme | Console Colors)

However, I did also find an alternative solution if you really needed to override some styles on the default formatter for every command that runs in your app.

You can simply extend the handle() method in your App\Console\Kernel class, customize your output however you wish, and let the kernel continue on. This also has the added benefit of affecting commands from packages and Laravel itself as well, without requiring you to edit your artisan file 😅

See the code snippet below for an example for how to override the default color only for the error style.

use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Output\ConsoleOutput;

class Kernel extends ConsoleKernel
{
    // ...

    public function handle($input, $output = null): int
    {
        if ($output instanceof ConsoleOutput) {
            $output->getFormatter()
                   ->setStyle(
                       'error',
                       new OutputFormatterStyle('bright-white', 'red')
                   );
        }

        return parent::handle($input, $output);
    }

    // ...
}

Please or to participate in this conversation.