public static function writeLog ($filename, $string)
    {
        $logs_path = defined('PATH_LOGS')
            ? PATH_LOGS
            : getcwd();

        $logs_path_real = realpath($logs_path);

        if(!$logs_path_real || !is_writable($logs_path_real)) {
            throw new \Exception("Log path is not accessible or writable");
        }

        $file_name = $logs_path_real . DIRECTORY_SEPARATOR . strtolower(trim($filename));

        $file_folder = dirname($file_name);

        if (!is_dir($file_folder)) {
            if (!mkdir($file_folder, 0766, true)) {
                throw new \Exception("Couldn't create logs subfolder");
            }
        }

        if (!is_file($file_name)) {
            if (@touch($file_name)) {
                @chmod($file_name, 0777);
            }
        }

        return file_put_contents($file_name, $string . PHP_EOL, FILE_APPEND | LOCK_EX);
    }