<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _errmsg(self, error: "Err", tb: bool=False, i: int=None, msgformat: str="terminal") -> str: """ Get the error message """

        if msgformat == "terminal":
            msg = self._headline(error, i)
            if error.ex is not None:
                msg += "\n" + "line " + colors.bold(str(error.line))
                msg += ": " + colors.yellow(error.code)
                msg += "\n" + str(error.file)
                if self.errs_traceback is True or tb is True:
                    if error.tb is not None:
                        msg += "\n" + error.tb
        elif msgformat == "csv":
            sep = ","
            msg = error.msg + sep
            msg += str(error.line) + sep + error.code + sep
            msg += str(error.file)
        elif msgformat == "text":
            sep = ","
            msg = error.msg
            if error.ex is not None:
                msg += sep + str(error.line) + sep + error.code + sep
                msg += str(error.file) + sep         
                if self.errs_traceback is True or tb is True:
                    if error.tb is not None:
                        msg += sep + error.tb
        elif msgformat == "dict":
            msg = {"date": datetime.now()}
            if error.ex is not None:
                msg["msg"] = error.msg
                msg["line"] = error.line
                msg["code"] = error.code
                msg["file"] = error.file         
                if self.errs_traceback is True or tb is True:
                    if error.tb is not None:
                        msg["traceback"] = error.tb
        return msg