protected function send($message, $level, $prefix, $color)
{
$now = time();
$thread = \Thread::getCurrentThread();
if ($thread === null) {
$threadName = "Server thread";
} elseif ($thread instanceof Thread or $thread instanceof Worker) {
$threadName = $thread->getThreadName() . " thread";
} else {
$threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
}
if ($this->shouldRecordMsg) {
if (time() - $this->lastGet >= 10) {
$this->shouldRecordMsg = false;
} else {
if (strlen($this->shouldSendMsg) >= 10000) {
$this->shouldSendMsg = "";
}
$this->shouldSendMsg .= $color . "|" . $prefix . "|" . trim($message, "\r\n") . "\n";
}
}
$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s", $now) . "] " . TextFormat::RESET . $color . "[" . $threadName . "/" . $prefix . "]:" . " " . $message . TextFormat::RESET);
//$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s") . "] ". TextFormat::RESET . $color ."<".$prefix . ">" . " " . $message . TextFormat::RESET);
$cleanMessage = TextFormat::clean($message);
if (!Terminal::hasFormattingCodes()) {
echo $cleanMessage . PHP_EOL;
} else {
echo $message . PHP_EOL;
}
if (isset($this->consoleCallback)) {
call_user_func($this->consoleCallback);
}
if ($this->attachment instanceof \ThreadedLoggerAttachment) {
$this->attachment->call($level, $message);
}
$this->logStream[] = date("Y-m-d", $now) . " " . $cleanMessage . "\n";
if ($this->logStream->count() === 1) {
$this->synchronized(function () {
$this->notify();
});
}
}