Log wrong flush order
actorius opened this issue · comments
Vitaliy D commented
Monolog version 2
Have 2 channels for writing same file, make info and debug records but flushed wrong sequence.
What i'm doing wrong?
Should be:
Child.DEBUG: START UPDATE PROCESS [] []
Primary.DEBUG: Call Action method. []
Child.INFO: END PROCESS [] []
Writed to file:
Primary.DEBUG: Call Action method. []
Child.DEBUG: START UPDATE PROCESS [] []
Child.INFO: END PROCESS [] []
Base class
abstract class Primary
{
protected $baseLogger;
function __construct()
{
$this->InitLog();
}
function InitLog() {
$stream = new StreamHandler($_SERVER["DOCUMENT_ROOT"] . "/logs/app.log", Logger::DEBUG);
$firephp = new FirePHPHandler();
$this->baseLogger = new Logger('BaseChannel');
$this->baseLogger->pushHandler($stream);
$this->baseLogger->pushHandler($firephp);
}
protected function doAction()
{
$this->baseLogger->debug("Call Action method.");
}
}
Extended class
class Child extends Primary
{
var $logger;
public function __construct()
{
parent::__construct();
$channelName = (new \ReflectionClass($this))->getShortName();
$this->logger = $this->baseLogger->withName($channelName);
}
public function Process()
{
$this->logger->info("START UPDATE PROCESS");
...
$this->doAction();
...
$this->logger->info("END UPDATE PROCESS");
}
}
Call:
$c = new Child();
$c->Process();