-
-
Save nguyenhiepvan/740ae8183b66bf860dac79243c6611bb 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