mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 11:58:00 +00:00
MainLogger: Require useFormattingCodes as a constructor parameter
this avoids needing to call Terminal::init() before starting a MainLogger. Since it inits the formatting codes anyway when log messages are first recorded, it shouldn't be necessary to pre-initialize it.
This commit is contained in:
@@ -42,7 +42,7 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
|
||||
private $format = TextFormat::AQUA . "[%s] " . TextFormat::RESET . "%s[%s/%s]: %s" . TextFormat::RESET;
|
||||
|
||||
/** @var bool */
|
||||
private $mainThreadHasFormattingCodes = false;
|
||||
private $useFormattingCodes = false;
|
||||
|
||||
/** @var string */
|
||||
private $timezone;
|
||||
@@ -53,12 +53,11 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
|
||||
/**
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct(string $logFile, bool $logDebug = false){
|
||||
public function __construct(string $logFile, bool $useFormattingCodes, bool $logDebug = false){
|
||||
parent::__construct();
|
||||
$this->logDebug = $logDebug;
|
||||
|
||||
//Child threads may not inherit command line arguments, so if there's an override it needs to be recorded here
|
||||
$this->mainThreadHasFormattingCodes = Terminal::hasFormattingCodes();
|
||||
$this->useFormattingCodes = $useFormattingCodes;
|
||||
$this->timezone = Timezone::get();
|
||||
|
||||
$this->logWriterThread = new MainLoggerThread($logFile);
|
||||
@@ -234,7 +233,7 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
|
||||
$message = sprintf($this->format, $time->format("H:i:s.v"), $color, $threadName, $prefix, TextFormat::clean($message, false));
|
||||
|
||||
if(!Terminal::isInit()){
|
||||
Terminal::init($this->mainThreadHasFormattingCodes); //lazy-init colour codes because we don't know if they've been registered on this thread
|
||||
Terminal::init($this->useFormattingCodes); //lazy-init colour codes because we don't know if they've been registered on this thread
|
||||
}
|
||||
|
||||
$this->synchronized(function() use ($message, $level, $time) : void{
|
||||
|
Reference in New Issue
Block a user