From 181cfef73161ef68db91d71cc18a484c6f2ad3cd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 23 Jun 2019 19:39:40 +0100 Subject: [PATCH] Remove a whole bunch of useless crap from PluginLogger this is pretty much just an implementation of a NTS attachable logger now. It should probably be converted into a trait. --- src/pocketmine/plugin/PluginBase.php | 4 +- src/pocketmine/plugin/PluginLogger.php | 52 +------------------------- 2 files changed, 5 insertions(+), 51 deletions(-) diff --git a/src/pocketmine/plugin/PluginBase.php b/src/pocketmine/plugin/PluginBase.php index 4068599ef..1f04c5b61 100644 --- a/src/pocketmine/plugin/PluginBase.php +++ b/src/pocketmine/plugin/PluginBase.php @@ -87,7 +87,9 @@ abstract class PluginBase implements Plugin, CommandExecutor{ //TODO: this is accessed externally via reflection, not unused $this->file = rtrim($file, "\\/") . "/"; $this->configFile = $this->dataFolder . "config.yml"; - $this->logger = new PluginLogger($this); + + $prefix = $this->getDescription()->getPrefix(); + $this->logger = new PluginLogger($server->getLogger(), $prefix !== "" ? $prefix : $this->getName()); $this->scheduler = new TaskScheduler($this->getFullName()); $this->resourceProvider = $resourceProvider; diff --git a/src/pocketmine/plugin/PluginLogger.php b/src/pocketmine/plugin/PluginLogger.php index 944533dcd..ba310563b 100644 --- a/src/pocketmine/plugin/PluginLogger.php +++ b/src/pocketmine/plugin/PluginLogger.php @@ -23,13 +23,9 @@ declare(strict_types=1); namespace pocketmine\plugin; -use LogLevel; -use pocketmine\Server; use function spl_object_id; -class PluginLogger implements \AttachableLogger{ - - private $pluginName; +class PluginLogger extends \PrefixedLogger implements \AttachableLogger{ /** @var \LoggerAttachment[] */ private $attachments = []; @@ -50,52 +46,8 @@ class PluginLogger implements \AttachableLogger{ return $this->attachments; } - /** - * @param Plugin $context - */ - public function __construct(Plugin $context){ - $prefix = $context->getDescription()->getPrefix(); - $this->pluginName = $prefix != null ? "[$prefix] " : "[" . $context->getDescription()->getName() . "] "; - } - - public function emergency($message){ - $this->log(LogLevel::EMERGENCY, $message); - } - - public function alert($message){ - $this->log(LogLevel::ALERT, $message); - } - - public function critical($message){ - $this->log(LogLevel::CRITICAL, $message); - } - - public function error($message){ - $this->log(LogLevel::ERROR, $message); - } - - public function warning($message){ - $this->log(LogLevel::WARNING, $message); - } - - public function notice($message){ - $this->log(LogLevel::NOTICE, $message); - } - - public function info($message){ - $this->log(LogLevel::INFO, $message); - } - - public function debug($message){ - $this->log(LogLevel::DEBUG, $message); - } - - public function logException(\Throwable $e, $trace = null){ - Server::getInstance()->getLogger()->logException($e, $trace); - } - public function log($level, $message){ - Server::getInstance()->getLogger()->log($level, $this->pluginName . $message); + parent::log($level, $message); foreach($this->attachments as $attachment){ $attachment->log($level, $message); }