Made logging better, plugin loggers can be attached by others

This commit is contained in:
Shoghi Cervantes
2014-07-02 23:33:29 +02:00
parent aa85993634
commit 43635b501a
4 changed files with 40 additions and 21 deletions

View File

@ -25,10 +25,29 @@ use Logger;
use LogLevel;
use pocketmine\utils\MainLogger;
class PluginLogger implements Logger{
class PluginLogger implements \AttachableLogger{
private $pluginName;
/** @var \LoggerAttachment[] */
private $attachments = [];
public function addAttachment(\LoggerAttachment $attachment){
$this->attachments[spl_object_hash($attachment)] = $attachment;
}
public function removeAttachment(\LoggerAttachment $attachment){
unset($this->attachments[spl_object_hash($attachment)]);
}
public function removeAttachments(){
$this->attachments = [];
}
public function getAttachments(){
return $this->attachments;
}
/**
* @param Plugin $context
*/
@ -71,5 +90,8 @@ class PluginLogger implements Logger{
public function log($level, $message){
MainLogger::getLogger()->log($level, $this->pluginName . $message);
foreach($this->attachments as $attachment){
$attachment->log($level, $message);
}
}
}