mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
Remove MainLogger singleton and remaining MainLogger hard-dependencies
This commit is contained in:
parent
a4b50e57a4
commit
44a205b1cc
@ -223,7 +223,6 @@ namespace pocketmine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$logger = new MainLogger(\pocketmine\DATA . "server.log");
|
$logger = new MainLogger(\pocketmine\DATA . "server.log");
|
||||||
$logger->registerStatic();
|
|
||||||
\GlobalLogger::set($logger);
|
\GlobalLogger::set($logger);
|
||||||
|
|
||||||
if(extension_loaded("xdebug")){
|
if(extension_loaded("xdebug")){
|
||||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\scheduler;
|
namespace pocketmine\scheduler;
|
||||||
|
|
||||||
use pocketmine\thread\Worker;
|
use pocketmine\thread\Worker;
|
||||||
use pocketmine\utils\MainLogger;
|
|
||||||
use function gc_enable;
|
use function gc_enable;
|
||||||
use function ini_set;
|
use function ini_set;
|
||||||
|
|
||||||
@ -46,9 +45,6 @@ class AsyncWorker extends Worker{
|
|||||||
|
|
||||||
protected function onRun() : void{
|
protected function onRun() : void{
|
||||||
\GlobalLogger::set($this->logger);
|
\GlobalLogger::set($this->logger);
|
||||||
if($this->logger instanceof MainLogger){
|
|
||||||
$this->logger->registerStatic();
|
|
||||||
}
|
|
||||||
|
|
||||||
gc_enable();
|
gc_enable();
|
||||||
|
|
||||||
|
@ -48,8 +48,6 @@ class MainLogger extends \AttachableThreadedLogger{
|
|||||||
protected $shutdown;
|
protected $shutdown;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $logDebug;
|
protected $logDebug;
|
||||||
/** @var MainLogger */
|
|
||||||
public static $logger = null;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $syncFlush = false;
|
private $syncFlush = false;
|
||||||
|
|
||||||
@ -70,9 +68,6 @@ class MainLogger extends \AttachableThreadedLogger{
|
|||||||
*/
|
*/
|
||||||
public function __construct(string $logFile, bool $logDebug = false){
|
public function __construct(string $logFile, bool $logDebug = false){
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
if(static::$logger instanceof MainLogger){
|
|
||||||
throw new \RuntimeException("MainLogger has been already created");
|
|
||||||
}
|
|
||||||
touch($logFile);
|
touch($logFile);
|
||||||
$this->logFile = $logFile;
|
$this->logFile = $logFile;
|
||||||
$this->logDebug = $logDebug;
|
$this->logDebug = $logDebug;
|
||||||
@ -85,33 +80,6 @@ class MainLogger extends \AttachableThreadedLogger{
|
|||||||
$this->start(PTHREADS_INHERIT_NONE);
|
$this->start(PTHREADS_INHERIT_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return MainLogger
|
|
||||||
*/
|
|
||||||
public static function getLogger() : MainLogger{
|
|
||||||
return static::$logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether a MainLogger instance is statically registered on this thread.
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isRegisteredStatic() : bool{
|
|
||||||
return static::$logger !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assigns the MainLogger instance to the {@link MainLogger#logger} static property.
|
|
||||||
*
|
|
||||||
* WARNING: Because static properties are thread-local, this MUST be called from the body of every Thread if you
|
|
||||||
* want the logger to be accessible via {@link MainLogger#getLogger}.
|
|
||||||
*/
|
|
||||||
public function registerStatic() : void{
|
|
||||||
if(static::$logger === null){
|
|
||||||
static::$logger = $this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current logger format used for console output.
|
* Returns the current logger format used for console output.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user