New console output formatting

This commit is contained in:
Shoghi Cervantes 2015-06-09 14:40:40 +02:00
parent ac2bcf7e30
commit 7cf5df7e46
7 changed files with 46 additions and 13 deletions

View File

@ -84,4 +84,8 @@ abstract class Thread extends \Thread{
ThreadManager::getInstance()->remove($this);
}
public function getThreadName(){
return (new \ReflectionClass($this))->getShortName();
}
}

View File

@ -85,4 +85,8 @@ abstract class Worker extends \Worker{
ThreadManager::getInstance()->remove($this);
}
public function getThreadName(){
return (new \ReflectionClass($this))->getShortName();
}
}

View File

@ -29,9 +29,6 @@ class CommandReader extends Thread{
/** @var \Threaded */
protected $buffer;
/**
* @param \Threaded $threaded
*/
public function __construct(){
$this->buffer = \ThreadedFactory::create();
$this->start();
@ -82,4 +79,8 @@ class CommandReader extends Thread{
$lastLine = microtime(true);
}
}
public function getThreadName(){
return "Console";
}
}

View File

@ -178,4 +178,8 @@ class RCONInstance extends Thread{
unset($this->socket, $this->cmd, $this->response, $this->stop);
exit(0);
}
public function getThreadName(){
return "RCON";
}
}

View File

@ -38,4 +38,8 @@ class AsyncWorker extends Worker{
public function start($options = PTHREADS_INHERIT_NONE){
parent::start(PTHREADS_INHERIT_CONSTANTS | PTHREADS_INHERIT_FUNCTIONS);
}
public function getThreadName(){
return "Asynchronous Worker";
}
}

View File

@ -22,6 +22,8 @@
namespace pocketmine\utils;
use LogLevel;
use pocketmine\Thread;
use pocketmine\Worker;
class MainLogger extends \AttachableThreadedLogger{
protected $logFile;
@ -58,38 +60,38 @@ class MainLogger extends \AttachableThreadedLogger{
}
public function emergency($message){
$this->send(TextFormat::RED . "[EMERGENCY] " . $message, \LogLevel::EMERGENCY);
$this->send($message, \LogLevel::EMERGENCY, "EMERGENCY", TextFormat::RED);
}
public function alert($message){
$this->send(TextFormat::RED . "[ALERT] " . $message, \LogLevel::ALERT);
$this->send($message, \LogLevel::ALERT, "ALERT", TextFormat::RED);
}
public function critical($message){
$this->send(TextFormat::RED . "[CRITICAL] " . $message, \LogLevel::CRITICAL);
$this->send($message, \LogLevel::CRITICAL, "CRITICAL", TextFormat::RED);
}
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){
$this->send(TextFormat::YELLOW . "[WARNING] " . $message, \LogLevel::WARNING);
$this->send($message, \LogLevel::WARNING, "WARNING", TextFormat::YELLOW);
}
public function notice($message){
$this->send(TextFormat::AQUA . "[NOTICE] " . $message, \LogLevel::NOTICE);
$this->send($message, \LogLevel::NOTICE, "NOTICE", TextFormat::AQUA);
}
public function info($message){
$this->send(TextFormat::WHITE . "[INFO] " . $message, \LogLevel::INFO);
$this->send($message, \LogLevel::INFO, "INFO", TextFormat::WHITE);
}
public function debug($message){
if($this->logDebug === false){
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;
}
protected function send($message, $level = -1){
protected function send($message, $level, $prefix, $color){
$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);
if(!Terminal::hasFormattingCodes()){

View File

@ -30,4 +30,8 @@ class ServerKiller extends Thread{
echo "\nTook to long to stop, server was killed forcefully!\n";
@\pocketmine\kill(getmypid());
}
public function getThreadName(){
return "Server Killer";
}
}