mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 18:59:00 +00:00
Register MainLogger on AsyncWorkers to make MainLogger::getLogger() usable in AsyncTasks
Threaded static properties aren't thread-local anymore in pthreads 3.1.7dev
This commit is contained in:
parent
97f6a32557
commit
9c9095060f
@ -174,6 +174,7 @@ namespace pocketmine {
|
|||||||
date_default_timezone_set("UTC");
|
date_default_timezone_set("UTC");
|
||||||
|
|
||||||
$logger = new MainLogger(\pocketmine\DATA . "server.log");
|
$logger = new MainLogger(\pocketmine\DATA . "server.log");
|
||||||
|
$logger->registerStatic();
|
||||||
|
|
||||||
if(!ini_get("date.timezone")){
|
if(!ini_get("date.timezone")){
|
||||||
if(($timezone = detect_system_timezone()) and date_default_timezone_set($timezone)){
|
if(($timezone = detect_system_timezone()) and date_default_timezone_set($timezone)){
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\scheduler;
|
|||||||
|
|
||||||
use pocketmine\Collectable;
|
use pocketmine\Collectable;
|
||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
|
use pocketmine\utils\MainLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used to run async tasks in other threads.
|
* Class used to run async tasks in other threads.
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\scheduler;
|
namespace pocketmine\scheduler;
|
||||||
|
|
||||||
|
use pocketmine\utils\MainLogger;
|
||||||
use pocketmine\Worker;
|
use pocketmine\Worker;
|
||||||
|
|
||||||
class AsyncWorker extends Worker{
|
class AsyncWorker extends Worker{
|
||||||
@ -30,13 +31,17 @@ class AsyncWorker extends Worker{
|
|||||||
private $logger;
|
private $logger;
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
public function __construct(\ThreadedLogger $logger, $id){
|
public function __construct(MainLogger $logger, $id){
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(){
|
public function run(){
|
||||||
$this->registerClassLoader();
|
$this->registerClassLoader();
|
||||||
|
if(MainLogger::getLogger() === null){
|
||||||
|
$this->logger->registerStatic();
|
||||||
|
}
|
||||||
|
|
||||||
gc_enable();
|
gc_enable();
|
||||||
ini_set("memory_limit", '-1');
|
ini_set("memory_limit", '-1');
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ class MainLogger extends \AttachableThreadedLogger{
|
|||||||
if(static::$logger instanceof MainLogger){
|
if(static::$logger instanceof MainLogger){
|
||||||
throw new \RuntimeException("MainLogger has been already created");
|
throw new \RuntimeException("MainLogger has been already created");
|
||||||
}
|
}
|
||||||
static::$logger = $this;
|
|
||||||
touch($logFile);
|
touch($logFile);
|
||||||
$this->logFile = $logFile;
|
$this->logFile = $logFile;
|
||||||
$this->logDebug = (bool) $logDebug;
|
$this->logDebug = (bool) $logDebug;
|
||||||
@ -55,12 +54,24 @@ class MainLogger extends \AttachableThreadedLogger{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return MainLogger
|
* @return MainLogger|null
|
||||||
*/
|
*/
|
||||||
public static function getLogger(){
|
public static function getLogger(){
|
||||||
return static::$logger;
|
return static::$logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assigns the MainLogger instance to the {@link MainLogger#logger} static property. 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(){
|
||||||
|
if(static::$logger instanceof MainLogger){
|
||||||
|
throw new \RuntimeException("MainLogger has been already registered");
|
||||||
|
}
|
||||||
|
static::$logger = $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function emergency($message){
|
public function emergency($message){
|
||||||
$this->send($message, \LogLevel::EMERGENCY, "EMERGENCY", TextFormat::RED);
|
$this->send($message, \LogLevel::EMERGENCY, "EMERGENCY", TextFormat::RED);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user