Browse Source

Pure Logging improvements

master
Dirk Alders 3 years ago
parent
commit
a8aa15974b
1 changed files with 10 additions and 10 deletions
  1. 10
    10
      __init__.py

+ 10
- 10
__init__.py View File

291
         self.__sid_name_dict__ = {}
291
         self.__sid_name_dict__ = {}
292
         self.__did_name_dict__ = {}
292
         self.__did_name_dict__ = {}
293
         #
293
         #
294
+        self.__callbacks__ = _callback_storage(channel_name, self.__log_prefix__)
295
+        self.__init_channel_name__(channel_name)
296
+        #
294
         self.__status_name_dict = {}
297
         self.__status_name_dict = {}
295
         self.add_status(STATUS_OKAY, 'okay')
298
         self.add_status(STATUS_OKAY, 'okay')
296
         self.add_status(STATUS_BUFFERING_UNHANDLED_REQUEST, 'no callback for service, data buffered')
299
         self.add_status(STATUS_BUFFERING_UNHANDLED_REQUEST, 'no callback for service, data buffered')
300
         self.add_status(STATUS_CHECKSUM_ERROR, 'checksum error')
303
         self.add_status(STATUS_CHECKSUM_ERROR, 'checksum error')
301
         self.add_status(STATUS_OPERATION_NOT_PERMITTED, 'operation not permitted')
304
         self.add_status(STATUS_OPERATION_NOT_PERMITTED, 'operation not permitted')
302
         #
305
         #
303
-        self.__callbacks__ = _callback_storage(channel_name, self.__log_prefix__)
304
-        self.__init_channel_name__(channel_name)
305
-        #
306
         self.__clean_receive_buffer__()
306
         self.__clean_receive_buffer__()
307
 
307
 
308
         self.add_service(SID_AUTH_REQUEST, SID_AUTH_RESPONSE, 'authentification request', 'authentification response')
308
         self.add_service(SID_AUTH_REQUEST, SID_AUTH_RESPONSE, 'authentification request', 'authentification response')
334
         self.__comm_inst__.register_callback(self.__data_available_callback__)
334
         self.__comm_inst__.register_callback(self.__data_available_callback__)
335
         self.__comm_inst__.register_connect_callback(self.__connection_established__)
335
         self.__comm_inst__.register_connect_callback(self.__connection_established__)
336
         self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
336
         self.__comm_inst__.register_disconnect_callback(self.__authentification_state_reset__)
337
-        logger.info('%s Initialisation finished.', self.__log_prefix__())
337
+        self.logger.info('%s Initialisation finished.', self.__log_prefix__())
338
 
338
 
339
     def __analyse_frame__(self, frame):
339
     def __analyse_frame__(self, frame):
340
         if sys.version_info >= (3, 0):
340
         if sys.version_info >= (3, 0):
491
                     try:
491
                     try:
492
                         status, data = callback(msg, *args, **kwargs)
492
                         status, data = callback(msg, *args, **kwargs)
493
                     except Exception as e:
493
                     except Exception as e:
494
-                        logger.error('{lp} Exception raised. Check callback {callback_name}: "{message}" and it\'s return values for {msg_info}'.format(lp=self.__log_prefix__(), callback_name=callback.__name__, message=str(e), msg_info=self.__get_message_name__(msg.get_service_id(), msg.get_data_id())))
494
+                        self.logger.error('{lp} Exception raised. Check callback {callback_name}: "{message}" and it\'s return values for {msg_info}'.format(lp=self.__log_prefix__(), callback_name=callback.__name__, message=str(e), msg_info=self.__get_message_name__(msg.get_service_id(), msg.get_data_id())))
495
                         status = STATUS_CALLBACK_ERROR
495
                         status = STATUS_CALLBACK_ERROR
496
                         data = None
496
                         data = None
497
             else:
497
             else:
505
                     try:
505
                     try:
506
                         callback(msg, *args, **kwargs)
506
                         callback(msg, *args, **kwargs)
507
                     except Exception as e:
507
                     except Exception as e:
508
-                        logger.error('{lp} Exception raised. Check callback {callback_name}: "{message}" for {msg_info}'.format(lp=self.__log_prefix__(), callback_name=callback.__name__, message=str(e), msg_info=self.__get_message_name__(msg.get_service_id(), msg.get_data_id())))
508
+                        self.logger.error('{lp} Exception raised. Check callback {callback_name}: "{message}" for {msg_info}'.format(lp=self.__log_prefix__(), callback_name=callback.__name__, message=str(e), msg_info=self.__get_message_name__(msg.get_service_id(), msg.get_data_id())))
509
                 return  # No response needed
509
                 return  # No response needed
510
         self.send(self.__sid_response_dict__[msg.get_service_id()], msg.get_data_id(), data, status=status)
510
         self.send(self.__sid_response_dict__[msg.get_service_id()], msg.get_data_id(), data, status=status)
511
 
511
 
568
         if service_id not in self.__auth_whitelist__:
568
         if service_id not in self.__auth_whitelist__:
569
             self.__auth_whitelist__[service_id] = []
569
             self.__auth_whitelist__[service_id] = []
570
         self.__auth_whitelist__[service_id].append(data_id)
570
         self.__auth_whitelist__[service_id].append(data_id)
571
-        logger.debug('%s Adding Message (%s) to the authentification whitelist', self.__log_prefix__(), self.__get_message_name__(service_id, data_id))
571
+        self.logger.debug('%s Adding Message (%s) to the authentification whitelist', self.__log_prefix__(), self.__get_message_name__(service_id, data_id))
572
 
572
 
573
     def add_service(self, req_sid, resp_sid, req_name=None, resp_name=None):
573
     def add_service(self, req_sid, resp_sid, req_name=None, resp_name=None):
574
         """
574
         """
580
         :type resp_sid: int
580
         :type resp_sid: int
581
         """
581
         """
582
         if req_sid in self.__sid_response_dict__:
582
         if req_sid in self.__sid_response_dict__:
583
-            logger.error('%s Service with Request-SID=%d and Response-SID=%d not added, because request SID is already registered', self.__log_prefix__(), req_sid, resp_sid)
583
+            self.logger.error('%s Service with Request-SID=%d and Response-SID=%d not added, because request SID is already registered', self.__log_prefix__(), req_sid, resp_sid)
584
             raise RequestSidExistsError("Request for this Service is already registered")
584
             raise RequestSidExistsError("Request for this Service is already registered")
585
         elif resp_sid in self.__sid_response_dict__.values():
585
         elif resp_sid in self.__sid_response_dict__.values():
586
-            logger.error('%s Service with Request-SID=%d and Response-SID=%d not added, because response SID is already registered', self.__log_prefix__(), req_sid, resp_sid)
586
+            self.logger.error('%s Service with Request-SID=%d and Response-SID=%d not added, because response SID is already registered', self.__log_prefix__(), req_sid, resp_sid)
587
             raise ResponseSidExistsError("Response for this Service is already registered")
587
             raise ResponseSidExistsError("Response for this Service is already registered")
588
         else:
588
         else:
589
             self.__sid_response_dict__[req_sid] = resp_sid
589
             self.__sid_response_dict__[req_sid] = resp_sid
591
                 self.__sid_name_dict__[req_sid] = req_name
591
                 self.__sid_name_dict__[req_sid] = req_name
592
             if resp_name is not None:
592
             if resp_name is not None:
593
                 self.__sid_name_dict__[resp_sid] = resp_name
593
                 self.__sid_name_dict__[resp_sid] = resp_name
594
-            logger.debug('%s Adding Service with Request=%s and Response=%s', self.__log_prefix__(), req_name or repr(req_sid), resp_name or repr(resp_sid))
594
+            self.logger.debug('%s Adding Service with Request=%s and Response=%s', self.__log_prefix__(), req_name or repr(req_sid), resp_name or repr(resp_sid))
595
 
595
 
596
     def add_status(self, status, name):
596
     def add_status(self, status, name):
597
         """
597
         """

Loading…
Cancel
Save