Skip to content

Instantly share code, notes, and snippets.

@vuthaihoc
Created October 20, 2020 02:39
Show Gist options
  • Save vuthaihoc/ad5aa8b489a520aedc07cf38fe46fa44 to your computer and use it in GitHub Desktop.
Save vuthaihoc/ad5aa8b489a520aedc07cf38fe46fa44 to your computer and use it in GitHub Desktop.
Prepend timestamp to Artisan Console Output
<?php
/**
* @credit https://stackoverflow.com/questions/33046020/laravel-php-prepend-timestamp-to-artisan-console-output
*/
namespace App\Commands;
trait PrependsTimestamp
{
public function line($string, $style = null, $verbosity = null)
{
parent::line($this->prepend($string), $style, $verbosity);
}
protected function prepend($string)
{
if (method_exists($this, 'getPrependString')) {
return $this->getPrependString($string).$string;
}
return $string;
}
protected function getPrependString($string)
{
return date(property_exists($this, 'outputTimestampFormat') ?
$this->outputTimestampFormat : '[Y-m-d H:i:s]').' ';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment