<?php
 namespace Engine\Logger; class DirectPrintf extends GeneralAbstract { protected $handler; protected $loggedErrorTypes = []; public function __construct() { parent::__construct(); $this->handler = fopen('php://output', 'w'); } public function has($level) { return (bool)$this->loggedErrorTypes[$level]; } public function writeRawMessage($fields) { $this->loggedErrorTypes[$fields['level']]++; $t = $fields['addTime']; $micro = sprintf("%06d",($t - floor($t)) * 1000000); $d = new \DateTime( date('Y-m-d H:i:s.'.$micro, (int)$t) ); fwrite($this->handler, sprintf("\n<div class='type-%s' data-microtime='%s' data-memory='%s'><span class='time'>%s</span><span class='memory'>%.1fMb</span><span class='type'>%s</span><span class='msg'>%s</span></div>", $fields['level'], $fields['addTime'], $fields['memory'], $d->format("Y-m-d H:i:s.u"), $fields['memory']/(1024*1024), $fields['level'], $fields['message'])); return true; } public function idle($message, array $context = []) { return $this->log('idle', $message, $context); } public function success($message, array $context = []) { return $this->log('success', $message, $context); } public function waiting($message, array $context = []) { return $this->log('waiting', $message, $context); } public function log($level, $message, array $context = []) { if (!in_array($level, ['critical', 'error', 'warning', 'info', 'idle', 'waiting', 'success'])) { throw new \Exception("Invalid error level: {$level}"); } if ($context) { throw new \Exception("Context is not supported by this logging class"); } return $this->writeRawMessage([ 'level' => $level, 'message' => $message, 'addTime' => microtime(true), 'memory' => memory_get_usage(true), 'logSession' => $this->getLogSession(true), ]); } } 