From 89d4f596bdac8cc5792f9910e9e0bc418caaa37d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 4 Jun 2019 14:23:40 +0100 Subject: [PATCH] World: add and use a prefixed logger in some places --- src/pocketmine/network/mcpe/ChunkCache.php | 2 +- src/pocketmine/world/World.php | 14 +++++++++++--- src/pocketmine/world/format/Chunk.php | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/network/mcpe/ChunkCache.php b/src/pocketmine/network/mcpe/ChunkCache.php index 52134e5d0..44776857f 100644 --- a/src/pocketmine/network/mcpe/ChunkCache.php +++ b/src/pocketmine/network/mcpe/ChunkCache.php @@ -99,7 +99,7 @@ class ChunkCache implements ChunkListener{ $this->world->getChunk($chunkX, $chunkZ), $this->caches[$chunkHash], function() use($chunkX, $chunkZ){ - $this->world->getServer()->getLogger()->error("Failed preparing chunk for " . $this->world->getDisplayName() . " chunk $chunkX $chunkZ, retrying"); + $this->world->getLogger()->error("Failed preparing chunk $chunkX $chunkZ, retrying"); $this->restartPendingRequest($chunkX, $chunkZ); } diff --git a/src/pocketmine/world/World.php b/src/pocketmine/world/World.php index 44fecc67b..f826650c1 100644 --- a/src/pocketmine/world/World.php +++ b/src/pocketmine/world/World.php @@ -266,6 +266,9 @@ class World implements ChunkManager, Metadatable{ /** @var SkyLightUpdate|null */ private $skyLightUpdate = null; + /** @var \Logger */ + private $logger; + public static function chunkHash(int $x, int $z) : int{ return (($x & 0xFFFFFFFF) << 32) | ($z & 0xFFFFFFFF); } @@ -352,6 +355,8 @@ class World implements ChunkManager, Metadatable{ $this->provider = $provider; $this->displayName = $this->provider->getWorldData()->getName(); + $this->logger = new \PrefixedLogger($server->getLogger(), "World: $this->displayName"); + $this->worldHeight = $this->provider->getWorldHeight(); $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.level.preparing", [$this->displayName])); @@ -419,6 +424,10 @@ class World implements ChunkManager, Metadatable{ return $this->server; } + public function getLogger() : \Logger{ + return $this->logger; + } + final public function getProvider() : WritableWorldProvider{ return $this->provider; } @@ -2526,8 +2535,7 @@ class World implements ChunkManager, Metadatable{ try{ $chunk = $this->provider->loadChunk($x, $z); }catch(CorruptedChunkException | UnsupportedChunkFormatException $e){ - $logger = $this->server->getLogger(); - $logger->critical("Failed to load chunk x=$x z=$z: " . $e->getMessage()); + $this->logger->critical("Failed to load chunk x=$x z=$z: " . $e->getMessage()); } if($chunk === null and $create){ @@ -2553,7 +2561,7 @@ class World implements ChunkManager, Metadatable{ } if(!$this->isChunkInUse($x, $z)){ - $this->server->getLogger()->debug("Newly loaded chunk $x $z has no loaders registered, will be unloaded at next available opportunity"); + $this->logger->debug("Newly loaded chunk $x $z has no loaders registered, will be unloaded at next available opportunity"); $this->unloadChunkRequest($x, $z); } foreach($this->getChunkListeners($x, $z) as $listener){ diff --git a/src/pocketmine/world/format/Chunk.php b/src/pocketmine/world/format/Chunk.php index 18452a42f..89c0c1eaf 100644 --- a/src/pocketmine/world/format/Chunk.php +++ b/src/pocketmine/world/format/Chunk.php @@ -587,12 +587,12 @@ class Chunk{ try{ $entity = EntityFactory::createFromData($world, $nbt); if(!($entity instanceof Entity)){ - $world->getServer()->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown entity type " . $nbt->getString("id", $nbt->getString("identifier", "", true), true)); + $world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown entity type " . $nbt->getString("id", $nbt->getString("identifier", "", true), true)); $changed = true; continue; } }catch(\Exception $t){ //TODO: this shouldn't be here - $world->getServer()->getLogger()->logException($t); + $world->getLogger()->logException($t); $changed = true; continue; } @@ -606,7 +606,7 @@ class Chunk{ if(($tile = TileFactory::createFromData($world, $nbt)) !== null){ $world->addTile($tile); }else{ - $world->getServer()->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown tile entity type " . $nbt->getString("id", "", true)); + $world->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown tile entity type " . $nbt->getString("id", "", true)); $changed = true; continue; }