From 8cfe7d926914c5ee8c3a26e8416fdb0256d1a336 Mon Sep 17 00:00:00 2001 From: Thomas Grimonet Date: Sat, 7 Mar 2020 09:11:08 +0100 Subject: [PATCH] Implement logging handler for cv_client / cv_api #124 Configure a dedicated logging.handler to log cv_client and cv_api fucntions: ``` arista.cvp.cv_client: DEBUG - func: get_inventory (L:105) - get_inventory: called arista.cvp.cv_client: DEBUG - func: get_inventory (L:106) - 2019 Inventory API Call ``` --- .../arista/cvp/plugins/module_utils/cv_api2019.py | 2 +- .../arista/cvp/plugins/module_utils/cv_client.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ansible_collections/arista/cvp/plugins/module_utils/cv_api2019.py b/ansible_collections/arista/cvp/plugins/module_utils/cv_api2019.py index e5d9a3997..4047a25ce 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/cv_api2019.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/cv_api2019.py @@ -895,7 +895,7 @@ def get_container_by_name(self, name): container (dict): Container info in dictionary format or None ''' self.log.debug('Get info for container %s' % name) - logging.debug( + self.log.debug( '* cv_api2019 - get_container_by_name - container name is: %s', str(name)) containers = self.clnt.get('/provisioning/searchTopology.do?queryParam=%s' '&startIndex=0&endIndex=0' % qplus(name)) diff --git a/ansible_collections/arista/cvp/plugins/module_utils/cv_client.py b/ansible_collections/arista/cvp/plugins/module_utils/cv_client.py index 69e928d4b..889e34e72 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/cv_client.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/cv_client.py @@ -89,6 +89,7 @@ import inspect import traceback from logging.handlers import SysLogHandler +import ansible_collections.arista.cvp.plugins.module_utils.logger from itertools import cycle from ansible_collections.arista.cvp.plugins.module_utils.cv_client_errors import CvpApiError, CvpLoginError, CvpRequestError, CvpSessionLogOutError REQUESTS_IMP_ERR = None @@ -144,8 +145,8 @@ def __init__(self, logger='cv_apiClient', syslog=False, filename=None, self.headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} - self.log = logging.getLogger(logger) - self.set_log_level(log_level) + self.log = logging.getLogger('arista.cvp.cv_client') + self.log.info('Start cv_client API execution') if syslog: # Enables sending logging messages to the local syslog server. self.log.addHandler(SysLogHandler()) @@ -278,6 +279,7 @@ def connect(self, nodes, username, password, connect_timeout=10, self._create_session(all_nodes=True) # Verify that we can connect to at least one node if not self.session: + self.log.error(' error connecting cvp: %s', str(self.error_msg)) raise CvpLoginError(self.error_msg) else: # Instantiate the CvpApi class