Label of the logger * =========================================================*/ private function __construct($label){ /* (1) Set logfile and label */ $this->label = $label; $this->file = __BUILD__."/log/log/$label.log"; /* (2) Create file if doesn't exist already */ if( !is_file($this->file) ) FileDriver::create($this->file); } /* [3] Writes a new log to the file * * @content Content to log * @tag [OPT] Tag of the log (category) * * @return outputname outputdesc * =========================================================*/ public function log($content="...", $tag="default"){ /* (1) Get time data */ $timestamp = time(); $date = date('Y-m-s H:i:s', $timestamp); /* (2) Create beginning string */ $body = "$timestamp | $date | [$tag] "; $headerl = strlen($body); /* (3) Split content by length */ $body .= substr($content, 0, self::$maxlen); for( $i = self::$maxlen, $l = strlen($content) ; $i < $l ; $i += self::$maxlen ) $body .= "\n".str_repeat(" ", $headerl).substr($content, $i, self::$maxlen); /* (4) Append to log file */ FileDriver::append($this->file, $body); } /* [4] Multiton attributes =========================================================*/ private static $instance = []; // instances /* [5] Multiton Manager * * @label Label of the logger you want * * @return instance instance of the wanted logger * =========================================================*/ public static function get($label="default"){ /* (1) Create if doesn't exist */ if( !isset(self::$instance[$label]) ) self::$instance[$label] = new Log($label); /* (2) Return instance for all cases */ return self::$instance[$label]; } }