mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 20:14:31 +00:00
Added Logger interface, threaded MainLogger and updated PluginLogger
This commit is contained in:
@@ -24,6 +24,7 @@ namespace pocketmine\plugin;
|
||||
use pocketmine\event\plugin\PluginDisableEvent;
|
||||
use pocketmine\event\plugin\PluginEnableEvent;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\MainLogger;
|
||||
|
||||
/**
|
||||
* Handles different types of plugins
|
||||
@@ -51,7 +52,7 @@ class PharPluginLoader implements PluginLoader{
|
||||
*/
|
||||
public function loadPlugin($file){
|
||||
if(\Phar::isValidPharFilename($file) and ($description = $this->getPluginDescription($file)) instanceof PluginDescription){
|
||||
console("[INFO] Loading " . $description->getFullName());
|
||||
MainLogger::getLogger()->info("Loading " . $description->getFullName());
|
||||
$dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName();
|
||||
if(file_exists($dataFolder) and !is_dir($dataFolder)){
|
||||
throw new \Exception("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory");
|
||||
@@ -121,7 +122,7 @@ class PharPluginLoader implements PluginLoader{
|
||||
*/
|
||||
public function enablePlugin(Plugin $plugin){
|
||||
if($plugin instanceof PluginBase and !$plugin->isEnabled()){
|
||||
console("[INFO] Enabling " . $plugin->getDescription()->getFullName());
|
||||
MainLogger::getLogger()->info("Enabling " . $plugin->getDescription()->getFullName());
|
||||
|
||||
$plugin->setEnabled(true);
|
||||
|
||||
@@ -134,7 +135,7 @@ class PharPluginLoader implements PluginLoader{
|
||||
*/
|
||||
public function disablePlugin(Plugin $plugin){
|
||||
if($plugin instanceof PluginBase and $plugin->isEnabled()){
|
||||
console("[INFO] Disabling " . $plugin->getDescription()->getFullName());
|
||||
MainLogger::getLogger()->info("Disabling " . $plugin->getDescription()->getFullName());
|
||||
|
||||
Server::getInstance()->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
|
||||
|
||||
|
@@ -241,7 +241,7 @@ abstract class PluginBase implements Plugin{
|
||||
|
||||
public function saveConfig(){
|
||||
if($this->getConfig()->save() === false){
|
||||
console("[SEVERE] Could not save config to " . $this->configFile);
|
||||
$this->getLogger()->critical("Could not save config to " . $this->configFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,14 @@
|
||||
|
||||
namespace pocketmine\plugin;
|
||||
|
||||
class PluginLogger{
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\Logger;
|
||||
use pocketmine\utils\LogLevel;
|
||||
use pocketmine\utils\MainLogger;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
class PluginLogger implements Logger{
|
||||
|
||||
private $pluginName;
|
||||
|
||||
@@ -33,12 +40,39 @@ class PluginLogger{
|
||||
$this->pluginName = $prefix != null ? "[$prefix] " : "[" . $context->getDescription()->getName() . "] ";
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message to the console
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function log($message){
|
||||
console($this->pluginName . $message);
|
||||
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 log($level, $message){
|
||||
MainLogger::getLogger()->log($level, $this->pluginName . $message);
|
||||
}
|
||||
}
|
@@ -189,14 +189,14 @@ class PluginManager{
|
||||
if($description instanceof PluginDescription){
|
||||
$name = $description->getName();
|
||||
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
||||
console("[ERROR] Could not load plugin '" . $name . "': restricted name");
|
||||
$this->server->getLogger()->error("Could not load plugin '" . $name . "': restricted name");
|
||||
continue;
|
||||
}elseif(strpos($name, " ") !== false){
|
||||
console("[WARNING] Plugin '" . $name . "' uses spaces in its name, this is discouraged");
|
||||
$this->server->getLogger()->warning("Plugin '" . $name . "' uses spaces in its name, this is discouraged");
|
||||
}
|
||||
|
||||
if(isset($plugins[$name]) or $this->getPlugin($name) instanceof Plugin){
|
||||
console("[ERROR] Could not load duplicate plugin '" . $name . "': plugin exists");
|
||||
$this->server->getLogger()->error("Could not load duplicate plugin '" . $name . "': plugin exists");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ class PluginManager{
|
||||
}
|
||||
|
||||
if($compatible === false){
|
||||
console("[ERROR] Could not load plugin '" . $name . "': API version not compatible");
|
||||
$this->server->getLogger()->error("Could not load plugin '" . $name . "': API version not compatible");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ class PluginManager{
|
||||
if(isset($loadedPlugins[$dependency]) or $this->getPlugin($dependency) instanceof Plugin){
|
||||
unset($dependencies[$name][$key]);
|
||||
}elseif(!isset($plugins[$dependency])){
|
||||
console("[SEVERE] Could not load plugin '" . $name . "': Unknown dependency");
|
||||
$this->server->getLogger()->critical("Could not load plugin '" . $name . "': Unknown dependency");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -277,7 +277,7 @@ class PluginManager{
|
||||
if($plugin = $this->loadPlugin($file) and $plugin instanceof Plugin){
|
||||
$loadedPlugins[$name] = $plugin;
|
||||
}else{
|
||||
console("[SEVERE] Could not load plugin '" . $name . "'");
|
||||
$this->server->getLogger()->critical("Could not load plugin '" . $name . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,7 +291,7 @@ class PluginManager{
|
||||
if($plugin = $this->loadPlugin($file) and $plugin instanceof Plugin){
|
||||
$loadedPlugins[$name] = $plugin;
|
||||
}else{
|
||||
console("[SEVERE] Could not load plugin '" . $name . "'");
|
||||
$this->server->getLogger()->critical("Could not load plugin '" . $name . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,7 +299,7 @@ class PluginManager{
|
||||
//No plugins loaded :(
|
||||
if($missingDependency === true){
|
||||
foreach($plugins as $name => $file){
|
||||
console("[SEVERE] Could not load plugin '" . $name . "': circular dependency detected");
|
||||
$this->server->getLogger()->critical("Could not load plugin '" . $name . "': circular dependency detected");
|
||||
}
|
||||
$plugins = [];
|
||||
}
|
||||
@@ -542,7 +542,7 @@ class PluginManager{
|
||||
|
||||
foreach($plugin->getDescription()->getCommands() as $key => $data){
|
||||
if(strpos($key, ":") !== false){
|
||||
console("[SEVERE] Could not load command " . $key . " for plugin " . $plugin->getDescription()->getName());
|
||||
$this->server->getLogger()->critical("Could not load command " . $key . " for plugin " . $plugin->getDescription()->getName());
|
||||
continue;
|
||||
}
|
||||
if(is_array($data)){
|
||||
@@ -559,7 +559,7 @@ class PluginManager{
|
||||
$aliasList = [];
|
||||
foreach($data["aliases"] as $alias){
|
||||
if(strpos($alias, ":") !== false){
|
||||
console("[SEVERE] Could not load alias " . $alias . " for plugin " . $plugin->getDescription()->getName());
|
||||
$this->server->getLogger()->critical("Could not load alias " . $alias . " for plugin " . $plugin->getDescription()->getName());
|
||||
continue;
|
||||
}
|
||||
$aliasList[] = $alias;
|
||||
|
Reference in New Issue
Block a user