forThisObject=$forThisObject; //parent::__construct(); } ///* public function __destruct() { //$this->log->trace( "." ); foreach( $this as $key => $toDestruct ) if ( isset( $this->$key ) ) unset( $this->$key ); //parent::__destruct(); } //*/ public function trace($message, $throwable = null) { $this->log('TRACE', $message, $throwable); } public function debug($message, $throwable = null) { $this->log('DEBUG', $message, $throwable); } public function info($message, $throwable = null) { $this->log('INFO', $message, $throwable); } public function warn($message, $throwable = null) { $this->log('WARN', $message, $throwable); } public function error($message, $throwable = null) { $this->log('ERROR', $message, $throwable); } public function fatal($message, $throwable = null) { $this->log('FATAL', $message, $throwable); } public function throwable( $exception ) : void { $this->log('THROW', \darkphp\error\DwException::exceptionToString($exception) ); } /** * Log a message using the provided logging level. * * @param log4php\DwLoggerLevel $level The logging level. * @param mixed $message Message to log. * @param Exception $throwable Optional throwable information to include * in the logging event. */ public function log(string $level, $message, $throwable = null) { $time=\microtime(true); if ( \is_object ( $this->forThisObject ) ) if ( method_exists( $this->forThisObject ,'toString' ) ) $loggerFqcn = $this->forThisObject->toString(); elseif ( method_exists( $this->forThisObject ,'__toString' ) ) $loggerFqcn = $this->forThisObject; elseif ( method_exists( $this->forThisObject ,'getClassName' ) ) $loggerFqcn = $this->forThisObject->getClassName(); else $loggerFqcn = \get_class( $this->forThisObject ); else $loggerFqcn = $this->forThisObject; // nothing append in null logger self::$buf[]="[ $loggerFqcn ] '$level': $message".( \is_null( $throwable ) ? "" : "/ ".$throwable ).\PHP_EOL; } // \darkphp\logger\DwBuffLogger::getAndCleanBuf(); public static function getAndCleanBuf() : array { $buffer = self::$buf; self::$buf = array(); return $buffer; } public function getClassName( bool $fqcn=null ) : string { return self::getStaticClassName( $fqcn ); } public static function getStaticClassName( bool $fqcn=null ) : string { return __CLASS__; } } ?>