. */ include_once __DIR__ . '/../config/config.php'; class Logger { private static $instance = null; private $log_file; public function __construct() { if (!LOGS_ENABLED) { return; } if (USE_ONE_LOG_FILE) { $this->log_file = LOG_FILE; } else { if (!file_exists(LOG_DIR)) { mkdir(LOG_DIR, 0777, true); } $this->log_file = LOG_DIR . "/" . date('d-M-Y') . '.logs'; } } public static function getInstance() { if (!self::$instance) { self::$instance = new Logger(); } return self::$instance; } private function mylog($level, $message) { if (!LOGS_ENABLED) { return; } if (is_array($message)) { $message = implode(" ", $message); } $now = getdate(); $month = sprintf("%02d", $now["mon"]); $day = sprintf("%02d", $now["mday"]); $hours = sprintf("%02d", $now["hours"]); $minutes = sprintf("%02d", $now["minutes"]); $seconds = sprintf("%02d", $now["seconds"]); $log_msg = "[" . $day . "/" . $month . "/" . $now["year"] . " " . $hours . ":" . $minutes . ":" . $seconds . "] [" . $level . "] " . $message . "\r\n"; file_put_contents($this->log_file, $log_msg, FILE_APPEND); } public function error($message) { $this->mylog("Error", $message); } public function warning($message) { $this->mylog("Warning", $message); } public function message($message) { $this->mylog("Message", $message); } public function debug($message) { $this->mylog("Debug", $message); } }