-
Notifications
You must be signed in to change notification settings - Fork 18
Closed
Description
Hello,
I see you use microtime() to get unique ids for loggers... this is not sufficient on recent machines anymore, as many PHP commands may be executed at the same microsecond...
(on constructors: $this->_id = md5(microtime()); )
I wondered why my composite logger only logged on my last child... after digging a little, I saw that each child was stored in an array with its id for key... which is the same for 2 loggers created at the same time:
// This only log on last added child:
$logger = Log::singleton('composite');
$logConsole = Log::factory('console', '', 'TEST');
$logFile = Log::factory('file', '/tmp/log', 'TEST');
$logger->addChild($logConsole);
$logger->addChild($logFile);
$logger->info('log me');
// This log on all children
$logger = Log::singleton('composite');
$logConsole = Log::factory('console', '', 'TEST');
sleep(1); // Wait!
$logFile = Log::factory('file', '/tmp/log', 'TEST');
$logger->addChild($logConsole);
$logger->addChild($logFile);
$logger->info('log me');A quick fix should be to add a random number after the microseconds on _id declaration, for example like this:
$this->_id = md5(microtime().rand());Best regards,
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels