def _log_message(self, message_type: str, message: str):
     from sims4communitylib.utils.common_date_utils import CommonRealDateUtils
     from pprint import pformat
     from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
     current_date_time = CommonRealDateUtils.get_current_date_string()
     new_message = '{} [{}] {}: [{}]: {}\n'.format(current_date_time, self._mod_name, str(message_type), self.name, message)
     try:
         from sims4communitylib.utils.common_io_utils import CommonIOUtils
         file_path = CommonLogUtils.get_message_file_path(self._mod_name)
         CommonIOUtils.write_to_file(file_path, new_message, ignore_errors=True)
     except Exception as ex:
         CommonExceptionHandler.log_exception(self._mod_name, 'Error occurred while attempting to log message: {}'.format(pformat(message)), exception=ex)
 def _log_error(self, message: str, exception: Exception = None):
     from sims4communitylib.utils.common_date_utils import CommonRealDateUtils
     from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
     try:
         exceptions = CommonStacktraceUtil.get_full_stack_trace()
         if exception is not None:
             stack_trace = '{}{} -> {}: {}\n'.format(
                 ''.join(exceptions), message,
                 type(exception).__name__, exception)
         else:
             stack_trace = 'No stack trace provided.'
         file_path = self.exceptions_file_path
         os.makedirs(os.path.dirname(file_path), exist_ok=True)
         exception_traceback_text = '[{}] {} {}\n'.format(
             self.mod_name, CommonRealDateUtils.get_current_date_string(),
             stack_trace)
         result = CommonIOUtils.write_to_file(file_path,
                                              exception_traceback_text,
                                              ignore_errors=True)
         if result:
             CommonExceptionHandler._notify_exception_occurred(
                 file_path, mod_identifier=self.mod_name)
     except Exception as ex:
         CommonExceptionHandler.log_exception(
             self.mod_name,
             'Error occurred while attempting to log message: {}'.format(
                 pformat(message)),
             exception=ex,
             custom_file_path=self._custom_file_path)
 def _log_stacktrace(mod_name: str, _traceback, file_path: str) -> bool:
     exception_traceback_text = '[{}] {} {}\n'.format(
         mod_name, CommonRealDateUtils.get_current_date_string(),
         _traceback)
     return CommonIOUtils.write_to_file(file_path,
                                        exception_traceback_text,
                                        ignore_errors=True)
Пример #4
0
 def _log_stacktrace(mod_identifier: Union[str, CommonModIdentity],
                     _traceback: str, file_path: str) -> bool:
     mod_identifier = CommonModIdentity._get_mod_name(mod_identifier)
     exception_traceback_text = '[{}] {} {}\n'.format(
         mod_identifier, CommonRealDateUtils.get_current_date_string(),
         _traceback)
     return CommonIOUtils.write_to_file(file_path,
                                        exception_traceback_text,
                                        ignore_errors=True)
 def _log_message(self, message_type: CommonMessageType, message: str):
     from sims4communitylib.utils.common_date_utils import CommonRealDateUtils
     from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
     current_date_time = CommonRealDateUtils.get_current_date_string()
     new_message = '{} {}: [{}]: {}\n'.format(current_date_time,
                                              message_type.name, self.name,
                                              message)
     try:
         from sims4communitylib.utils.common_io_utils import CommonIOUtils
         file_path = self.messages_file_path
         os.makedirs(os.path.dirname(file_path), exist_ok=True)
         CommonIOUtils.write_to_file(file_path,
                                     new_message,
                                     ignore_errors=True)
     except Exception as ex:
         CommonExceptionHandler.log_exception(
             self.mod_name,
             'Error occurred while attempting to log message: {}'.format(
                 pformat(message)),
             exception=ex,
             custom_file_path=self._custom_file_path)