diff --git a/src/pocketmine/utils/mainLogger.php b/src/pocketmine/utils/mainLogger.php deleted file mode 100644 index caebcc22d..000000000 --- a/src/pocketmine/utils/mainLogger.php +++ /dev/null @@ -1,175 +0,0 @@ -logFile = $logFile; - $this->hasANSI = (bool) $hasANSI; - $this->logDebug = (bool) $logDebug; - $this->logStream = ""; - $this->start(PTHREADS_INHERIT_NONE); - } - - /** - * @return MainLogger - */ - public static function getLogger(){ - return static::$logger; - } - - public function emergency($message){ - $this->send(TextFormat::RED . "[EMERGENCY] " . $message); - } - - public function alert($message){ - $this->send(TextFormat::RED . "[ALERT] " . $message); - } - - public function critical($message){ - $this->send(TextFormat::RED . "[CRITICAL] " . $message); - } - - public function error($message){ - $this->send(TextFormat::DARK_RED . "[ERROR] " . $message); - } - - public function warning($message){ - $this->send(TextFormat::YELLOW . "[WARNING] " . $message); - } - - public function notice($message){ - $this->send(TextFormat::AQUA . "[NOTICE] " . $message); - } - - public function info($message){ - $this->send(TextFormat::WHITE . "[INFO] " . $message); - } - - public function debug($message){ - if($this->logDebug === false){ - return; - } - $this->send(TextFormat::GRAY . "[DEBUG] " . $message); - } - - /** - * @param bool $logDebug - */ - public function setLogDebug($logDebug){ - $this->logDebug = (bool) $logDebug; - } - - public function log($level, $message){ - switch($level){ - case LogLevel::EMERGENCY: - $this->emergency($message); - break; - case LogLevel::ALERT: - $this->alert($message); - break; - case LogLevel::CRITICAL: - $this->critical($message); - break; - case LogLevel::ERROR: - $this->error($message); - break; - case LogLevel::WARNING: - $this->warning($message); - break; - case LogLevel::NOTICE: - $this->notice($message); - break; - case LogLevel::INFO: - $this->info($message); - break; - case LogLevel::DEBUG: - $this->debug($message); - break; - } - } - - public function shutdown(){ - $this->shutdown = true; - } - - protected function send($message){ - $now = time(); - $message = TextFormat::toANSI(TextFormat::AQUA . date("H:i:s", $now) . TextFormat::RESET . " " . $message . TextFormat::RESET . PHP_EOL); - $cleanMessage = TextFormat::clean(preg_replace('/\x1b\[[0-9;]*m/', "", $message)); - - if(!$this->hasANSI){ - echo $cleanMessage; - }else{ - echo $message; - } - $this->logStream .= date("Y-m-d", $now) . " " . $cleanMessage; - } - - public function run(){ - $this->shutdown = false; - $this->logResource = fopen($this->logFile, "a+b"); - if(!is_resource($this->logResource)){ - throw new \RuntimeException("Couldn't open log file"); - } - - while($this->shutdown === false){ - if(strlen($this->logStream) >= 4096){ - $this->lock(); - $chunks = strlen($this->logStream) >> 12; - $chunk = substr($this->logStream, 0, $chunks << 12); - $this->logStream = substr($this->logStream, $chunks << 12); - $this->unlock(); - fwrite($this->logResource, $chunk); - }else{ - usleep(250000); //sleep for 0.25 seconds - } - } - if(strlen($this->logStream) > 0){ - fwrite($this->logResource, $this->logStream); - } - - fclose($this->logResource); - } -} \ No newline at end of file