Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created November 5, 2021 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziadoz/67c2829cca5e5670dd5e3c478e1813ca to your computer and use it in GitHub Desktop.
Save ziadoz/67c2829cca5e5670dd5e3c478e1813ca to your computer and use it in GitHub Desktop.
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