PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
PluginLogger.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\plugin;
23 
24 use LogLevel;
26 
27 class PluginLogger implements \AttachableLogger{
28 
29  private $pluginName;
30 
32  private $attachments = [];
33 
34  public function addAttachment(\LoggerAttachment $attachment){
35  $this->attachments[spl_object_hash($attachment)] = $attachment;
36  }
37 
38  public function removeAttachment(\LoggerAttachment $attachment){
39  unset($this->attachments[spl_object_hash($attachment)]);
40  }
41 
42  public function removeAttachments(){
43  $this->attachments = [];
44  }
45 
46  public function getAttachments(){
47  return $this->attachments;
48  }
49 
53  public function __construct(Plugin $context){
54  $prefix = $context->getDescription()->getPrefix();
55  $this->pluginName = $prefix != null ? "[$prefix] " : "[" . $context->getDescription()->getName() . "] ";
56  }
57 
58  public function emergency($message){
59  $this->log(LogLevel::EMERGENCY, $message);
60  }
61 
62  public function alert($message){
63  $this->log(LogLevel::ALERT, $message);
64  }
65 
66  public function critical($message){
67  $this->log(LogLevel::CRITICAL, $message);
68  }
69 
70  public function error($message){
71  $this->log(LogLevel::ERROR, $message);
72  }
73 
74  public function warning($message){
75  $this->log(LogLevel::WARNING, $message);
76  }
77 
78  public function notice($message){
79  $this->log(LogLevel::NOTICE, $message);
80  }
81 
82  public function info($message){
83  $this->log(LogLevel::INFO, $message);
84  }
85 
86  public function debug($message){
87  $this->log(LogLevel::DEBUG, $message);
88  }
89 
90  public function log($level, $message){
91  Server::getInstance()->getLogger()->log($level, $this->pluginName . $message);
92  foreach($this->attachments as $attachment){
93  $attachment->log($level, $message);
94  }
95  }
96 }
static getInstance()
Definition: Server.php:1444