Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatically Log Laravel Artisan Console Output
<?php
// @see: https://stackoverflow.com/questions/48167834/how-to-remove-all-formatting-from-the-output-of-a-console-command-written-in-php
use Illuminate\Console\Events\CommandFinished;
use Illuminate\Support\Facades\{Event, Log};
use Symfony\Component\Console\Helper\Helper;
Event::listen(function (CommandFinished $event) {
Log::info(
Helper::removeDecoration(
$event->output->getFormatter(),
$event->output->fetch(),
)
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment