Created
October 20, 2020 02:39
-
-
Save vuthaihoc/ad5aa8b489a520aedc07cf38fe46fa44 to your computer and use it in GitHub Desktop.
Prepend timestamp to Artisan Console Output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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