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:
Dylan K. Taylor
2017-07-04 15:47:05 +01:00
parent 97f6a32557
commit 9c9095060f
4 changed files with 21 additions and 3 deletions

View File

@ -46,7 +46,6 @@ class MainLogger extends \AttachableThreadedLogger{
if(static::$logger instanceof MainLogger){
throw new \RuntimeException("MainLogger has been already created");
}
static::$logger = $this;
touch($logFile);
$this->logFile = $logFile;
$this->logDebug = (bool) $logDebug;
@ -55,12 +54,24 @@ class MainLogger extends \AttachableThreadedLogger{
}
/**
* @return MainLogger
* @return MainLogger|null
*/
public static function getLogger(){
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){
$this->send($message, \LogLevel::EMERGENCY, "EMERGENCY", TextFormat::RED);
}