Skip to content

Commit

Permalink
Implement logging handler for cv_client / cv_api #124
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
titom73 committed Mar 7, 2020
1 parent 02a0a23 commit 8cfe7d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8cfe7d9

Please sign in to comment.