Parcourir la source

Pure Logging improvements

master
Dirk Alders il y a 3 ans
Parent
révision
a8aa15974b
1 fichiers modifiés avec 10 ajouts et 10 suppressions
  1. 10
    10
      __init__.py

+ 10
- 10
__init__.py Voir le fichier

@@ -291,6 +291,9 @@ class pure_json_protocol(object):
291 291
         self.__sid_name_dict__ = {}
292 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 297
         self.__status_name_dict = {}
295 298
         self.add_status(STATUS_OKAY, 'okay')
296 299
         self.add_status(STATUS_BUFFERING_UNHANDLED_REQUEST, 'no callback for service, data buffered')
@@ -300,9 +303,6 @@ class pure_json_protocol(object):
300 303
         self.add_status(STATUS_CHECKSUM_ERROR, 'checksum error')
301 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 306
         self.__clean_receive_buffer__()
307 307
 
308 308
         self.add_service(SID_AUTH_REQUEST, SID_AUTH_RESPONSE, 'authentification request', 'authentification response')
@@ -334,7 +334,7 @@ class pure_json_protocol(object):
334 334
         self.__comm_inst__.register_callback(self.__data_available_callback__)
335 335
         self.__comm_inst__.register_connect_callback(self.__connection_established__)
336 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 339
     def __analyse_frame__(self, frame):
340 340
         if sys.version_info >= (3, 0):
@@ -491,7 +491,7 @@ class pure_json_protocol(object):
491 491
                     try:
492 492
                         status, data = callback(msg, *args, **kwargs)
493 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 495
                         status = STATUS_CALLBACK_ERROR
496 496
                         data = None
497 497
             else:
@@ -505,7 +505,7 @@ class pure_json_protocol(object):
505 505
                     try:
506 506
                         callback(msg, *args, **kwargs)
507 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 509
                 return  # No response needed
510 510
         self.send(self.__sid_response_dict__[msg.get_service_id()], msg.get_data_id(), data, status=status)
511 511
 
@@ -568,7 +568,7 @@ class pure_json_protocol(object):
568 568
         if service_id not in self.__auth_whitelist__:
569 569
             self.__auth_whitelist__[service_id] = []
570 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 573
     def add_service(self, req_sid, resp_sid, req_name=None, resp_name=None):
574 574
         """
@@ -580,10 +580,10 @@ class pure_json_protocol(object):
580 580
         :type resp_sid: int
581 581
         """
582 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 584
             raise RequestSidExistsError("Request for this Service is already registered")
585 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 587
             raise ResponseSidExistsError("Response for this Service is already registered")
588 588
         else:
589 589
             self.__sid_response_dict__[req_sid] = resp_sid
@@ -591,7 +591,7 @@ class pure_json_protocol(object):
591 591
                 self.__sid_name_dict__[req_sid] = req_name
592 592
             if resp_name is not None:
593 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 596
     def add_status(self, status, name):
597 597
         """

Chargement…
Annuler
Enregistrer