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.
This commit is contained in:
Dylan K. Taylor 2019-06-23 19:39:40 +01:00
parent 197a56e3e1
commit 181cfef731
2 changed files with 5 additions and 51 deletions

View File

@ -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;

View File

@ -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);
}