diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index db7537726..f08409453 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -92,7 +92,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ } public function start(){ - $this->rakLib->start(PTHREADS_INHERIT_CONSTANTS | PTHREADS_INHERIT_INI); //HACK: MainLogger needs INI and constants + $this->rakLib->start(PTHREADS_INHERIT_CONSTANTS); //HACK: MainLogger needs constants for exception logging } public function setNetwork(Network $network){ diff --git a/src/pocketmine/network/rcon/RCONInstance.php b/src/pocketmine/network/rcon/RCONInstance.php index 0ea1d771b..78ef36343 100644 --- a/src/pocketmine/network/rcon/RCONInstance.php +++ b/src/pocketmine/network/rcon/RCONInstance.php @@ -68,7 +68,7 @@ class RCONInstance extends Thread{ $this->ipcSocket = $ipcSocket; $this->notifier = $notifier; - $this->start(PTHREADS_INHERIT_INI); //HACK: need INI for timezone (logger) + $this->start(PTHREADS_INHERIT_NONE); } private function writePacket($client, int $requestID, int $packetType, string $payload){ diff --git a/src/pocketmine/utils/MainLogger.php b/src/pocketmine/utils/MainLogger.php index 9836d3cea..7fc850517 100644 --- a/src/pocketmine/utils/MainLogger.php +++ b/src/pocketmine/utils/MainLogger.php @@ -48,6 +48,9 @@ class MainLogger extends \AttachableThreadedLogger{ /** @var bool */ private $mainThreadHasFormattingCodes = false; + /** @var string */ + private $timezone; + /** * @param string $logFile * @param bool $logDebug @@ -66,6 +69,7 @@ class MainLogger extends \AttachableThreadedLogger{ //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->timezone = Timezone::get(); $this->start(PTHREADS_INHERIT_NONE); } @@ -253,7 +257,12 @@ class MainLogger extends \AttachableThreadedLogger{ } protected function send($message, $level, $prefix, $color){ - $now = time(); + /** @var \DateTime|null $time */ + static $time = null; + if($time === null){ //thread-local + $time = new \DateTime('now', new \DateTimeZone($this->timezone)); + } + $time->setTimestamp(time()); $thread = \Thread::getCurrentThread(); if($thread === null){ @@ -264,9 +273,9 @@ class MainLogger extends \AttachableThreadedLogger{ $threadName = (new \ReflectionClass($thread))->getShortName() . " thread"; } - $message = sprintf($this->format, date("H:i:s", $now), $color, $threadName, $prefix, $message); + $message = sprintf($this->format, $time->format("H:i:s"), $color, $threadName, $prefix, $message); - $this->synchronized(function() use ($message, $level, $now) : void{ + $this->synchronized(function() use ($message, $level, $time) : void{ $cleanMessage = TextFormat::clean($message); if($this->mainThreadHasFormattingCodes and Terminal::hasFormattingCodes()){ //hasFormattingCodes() lazy-inits colour codes because we don't know if they've been registered on this thread @@ -279,7 +288,7 @@ class MainLogger extends \AttachableThreadedLogger{ $attachment->call($level, $message); } - $this->logStream[] = date("Y-m-d", $now) . " " . $cleanMessage . PHP_EOL; + $this->logStream[] = $time->format("Y-m-d") . " " . $cleanMessage . PHP_EOL; }); }