From 27b1951df74954334e00d47c17c2392637f24ce3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 4 Feb 2021 20:55:50 +0000 Subject: [PATCH] MainLogger: accept main thread name as a constructor parameter --- src/PocketMine.php | 2 +- src/utils/MainLogger.php | 7 +++++-- tests/phpunit/scheduler/AsyncPoolTest.php | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/PocketMine.php b/src/PocketMine.php index daab079ee..160204d35 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -237,7 +237,7 @@ namespace pocketmine { Terminal::init(); } - $logger = new MainLogger($dataPath . "server.log", Terminal::hasFormattingCodes()); + $logger = new MainLogger($dataPath . "server.log", Terminal::hasFormattingCodes(), "Server"); \GlobalLogger::set($logger); emit_performance_warnings($logger); diff --git a/src/utils/MainLogger.php b/src/utils/MainLogger.php index ee30da4b4..f5637dbe9 100644 --- a/src/utils/MainLogger.php +++ b/src/utils/MainLogger.php @@ -44,6 +44,8 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{ /** @var bool */ private $useFormattingCodes = false; + private string $mainThreadName; + /** @var string */ private $timezone; @@ -53,11 +55,12 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{ /** * @throws \RuntimeException */ - public function __construct(string $logFile, bool $useFormattingCodes, bool $logDebug = false){ + public function __construct(string $logFile, bool $useFormattingCodes, string $mainThreadName, bool $logDebug = false){ parent::__construct(); $this->logDebug = $logDebug; $this->useFormattingCodes = $useFormattingCodes; + $this->mainThreadName = $mainThreadName; $this->timezone = Timezone::get(); $this->logWriterThread = new MainLoggerThread($logFile); @@ -223,7 +226,7 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{ $thread = \Thread::getCurrentThread(); if($thread === null){ - $threadName = "Server thread"; + $threadName = $this->mainThreadName . " thread"; }elseif($thread instanceof Thread or $thread instanceof Worker){ $threadName = $thread->getThreadName() . " thread"; }else{ diff --git a/tests/phpunit/scheduler/AsyncPoolTest.php b/tests/phpunit/scheduler/AsyncPoolTest.php index 98cd180b7..9cba443a0 100644 --- a/tests/phpunit/scheduler/AsyncPoolTest.php +++ b/tests/phpunit/scheduler/AsyncPoolTest.php @@ -43,7 +43,7 @@ class AsyncPoolTest extends TestCase{ public function setUp() : void{ @define('pocketmine\\COMPOSER_AUTOLOADER_PATH', dirname(__DIR__, 3) . '/vendor/autoload.php'); - $this->mainLogger = new MainLogger(tempnam(sys_get_temp_dir(), "pmlog"), false); + $this->mainLogger = new MainLogger(tempnam(sys_get_temp_dir(), "pmlog"), false, "Main"); $this->pool = new AsyncPool(2, 1024, new \BaseClassLoader(), $this->mainLogger, new SleeperHandler()); }