mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 18:59:00 +00:00
New console output formatting
This commit is contained in:
parent
ac2bcf7e30
commit
7cf5df7e46
@ -84,4 +84,8 @@ abstract class Thread extends \Thread{
|
|||||||
|
|
||||||
ThreadManager::getInstance()->remove($this);
|
ThreadManager::getInstance()->remove($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThreadName(){
|
||||||
|
return (new \ReflectionClass($this))->getShortName();
|
||||||
|
}
|
||||||
}
|
}
|
@ -85,4 +85,8 @@ abstract class Worker extends \Worker{
|
|||||||
|
|
||||||
ThreadManager::getInstance()->remove($this);
|
ThreadManager::getInstance()->remove($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThreadName(){
|
||||||
|
return (new \ReflectionClass($this))->getShortName();
|
||||||
|
}
|
||||||
}
|
}
|
@ -29,9 +29,6 @@ class CommandReader extends Thread{
|
|||||||
/** @var \Threaded */
|
/** @var \Threaded */
|
||||||
protected $buffer;
|
protected $buffer;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Threaded $threaded
|
|
||||||
*/
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
$this->buffer = \ThreadedFactory::create();
|
$this->buffer = \ThreadedFactory::create();
|
||||||
$this->start();
|
$this->start();
|
||||||
@ -82,4 +79,8 @@ class CommandReader extends Thread{
|
|||||||
$lastLine = microtime(true);
|
$lastLine = microtime(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThreadName(){
|
||||||
|
return "Console";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,4 +178,8 @@ class RCONInstance extends Thread{
|
|||||||
unset($this->socket, $this->cmd, $this->response, $this->stop);
|
unset($this->socket, $this->cmd, $this->response, $this->stop);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThreadName(){
|
||||||
|
return "RCON";
|
||||||
|
}
|
||||||
}
|
}
|
@ -38,4 +38,8 @@ class AsyncWorker extends Worker{
|
|||||||
public function start($options = PTHREADS_INHERIT_NONE){
|
public function start($options = PTHREADS_INHERIT_NONE){
|
||||||
parent::start(PTHREADS_INHERIT_CONSTANTS | PTHREADS_INHERIT_FUNCTIONS);
|
parent::start(PTHREADS_INHERIT_CONSTANTS | PTHREADS_INHERIT_FUNCTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThreadName(){
|
||||||
|
return "Asynchronous Worker";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
namespace pocketmine\utils;
|
namespace pocketmine\utils;
|
||||||
|
|
||||||
use LogLevel;
|
use LogLevel;
|
||||||
|
use pocketmine\Thread;
|
||||||
|
use pocketmine\Worker;
|
||||||
|
|
||||||
class MainLogger extends \AttachableThreadedLogger{
|
class MainLogger extends \AttachableThreadedLogger{
|
||||||
protected $logFile;
|
protected $logFile;
|
||||||
@ -58,38 +60,38 @@ class MainLogger extends \AttachableThreadedLogger{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function emergency($message){
|
public function emergency($message){
|
||||||
$this->send(TextFormat::RED . "[EMERGENCY] " . $message, \LogLevel::EMERGENCY);
|
$this->send($message, \LogLevel::EMERGENCY, "EMERGENCY", TextFormat::RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alert($message){
|
public function alert($message){
|
||||||
$this->send(TextFormat::RED . "[ALERT] " . $message, \LogLevel::ALERT);
|
$this->send($message, \LogLevel::ALERT, "ALERT", TextFormat::RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function critical($message){
|
public function critical($message){
|
||||||
$this->send(TextFormat::RED . "[CRITICAL] " . $message, \LogLevel::CRITICAL);
|
$this->send($message, \LogLevel::CRITICAL, "CRITICAL", TextFormat::RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function error($message){
|
public function error($message){
|
||||||
$this->send(TextFormat::DARK_RED . "[ERROR] " . $message, \LogLevel::ERROR);
|
$this->send($message, \LogLevel::ERROR, "ERROR", TextFormat::DARK_RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function warning($message){
|
public function warning($message){
|
||||||
$this->send(TextFormat::YELLOW . "[WARNING] " . $message, \LogLevel::WARNING);
|
$this->send($message, \LogLevel::WARNING, "WARNING", TextFormat::YELLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notice($message){
|
public function notice($message){
|
||||||
$this->send(TextFormat::AQUA . "[NOTICE] " . $message, \LogLevel::NOTICE);
|
$this->send($message, \LogLevel::NOTICE, "NOTICE", TextFormat::AQUA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function info($message){
|
public function info($message){
|
||||||
$this->send(TextFormat::WHITE . "[INFO] " . $message, \LogLevel::INFO);
|
$this->send($message, \LogLevel::INFO, "INFO", TextFormat::WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function debug($message){
|
public function debug($message){
|
||||||
if($this->logDebug === false){
|
if($this->logDebug === false){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->send(TextFormat::GRAY . "[DEBUG] " . $message, \LogLevel::DEBUG);
|
$this->send($message, \LogLevel::DEBUG, "DEBUG", TextFormat::GRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,9 +177,19 @@ class MainLogger extends \AttachableThreadedLogger{
|
|||||||
$this->shutdown = true;
|
$this->shutdown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function send($message, $level = -1){
|
protected function send($message, $level, $prefix, $color){
|
||||||
$now = time();
|
$now = time();
|
||||||
$message = TextFormat::toANSI(TextFormat::AQUA . date("H:i:s", $now) . TextFormat::RESET . " " . $message . TextFormat::RESET);
|
|
||||||
|
$thread = \Thread::getCurrentThread();
|
||||||
|
if($thread === null){
|
||||||
|
$threadName = "Server thread";
|
||||||
|
}elseif($thread instanceof Thread or $thread instanceof Worker){
|
||||||
|
$threadName = $thread->getThreadName() . " thread";
|
||||||
|
}else{
|
||||||
|
$threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s", $now) . "] ". TextFormat::RESET . $color ."[" . $threadName . "/" . $prefix . "]:" . " " . $message . TextFormat::RESET);
|
||||||
$cleanMessage = TextFormat::clean($message);
|
$cleanMessage = TextFormat::clean($message);
|
||||||
|
|
||||||
if(!Terminal::hasFormattingCodes()){
|
if(!Terminal::hasFormattingCodes()){
|
||||||
|
@ -30,4 +30,8 @@ class ServerKiller extends Thread{
|
|||||||
echo "\nTook to long to stop, server was killed forcefully!\n";
|
echo "\nTook to long to stop, server was killed forcefully!\n";
|
||||||
@\pocketmine\kill(getmypid());
|
@\pocketmine\kill(getmypid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThreadName(){
|
||||||
|
return "Server Killer";
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user