Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement consistent logging in all modules #146

Merged
merged 15 commits into from
Mar 7, 2020

Conversation

titom73
Copy link
Contributor

@titom73 titom73 commented Mar 4, 2020

Goals:

  • Centralize file destination for both modules & module_utils
  • Common and easy mechanism to log in modules: no if constraint to make it easy to read.

Based on logging library

Workflow:

  • Create a new module_utils.logger file to configure logger
  • Get a logger in modules with MODULE_LOGGER = logging.getLogger('arista.cvp.cv_facts')
  • use MODULE_LOGER. to log in file

Options & configuration:

  • Log Facility is set to info by default and can be override with an env
    var: ANSIBLE_CVP_LOG_LEVEL
  • Log destination is a file set to /tmp/arista.cvp.debug.log and can be
    override with an env var: ANSIBLE_CVP_LOG_FILE
  • Use logrotation to reduce file disk usage.
$ export ANSIBLE_CVP_LOG_FILE=arista.cvp.debug.log
$ export ANSIBLE_CVP_LOG_LEVEL=debug
$ export ANSIBLE_CVP_LOG_APICALL=warning

Log output examples:

03-04 11:35 arista.cvp.cv_facts INFO     Start cv_facts module execution
03-04 11:35 arista.cvp.cv_facts INFO     Connecting to CVP
03-04 11:35 urllib3.connectionpool DEBUG    Starting new HTTPS connection (1): 10.83.28.164:443

titom73 added 3 commits March 4, 2020 11:36
First test to build logging across all modules.

Goal:
-----
- centralize file destination for both modules & module_utils *
- common and easy mechanism to log in modules: no if constraint to make
it easy to read.

Based on logging library

Workflow:
---------
- Create a new module_utils.logger file to configure logger
- Get a logger in modules with MODULE_LOGGER = logging.getLogger('arista.cvp.cv_facts')
- use MODULE_LOGER.<level> to log in file

Options & configuration:
------------------------
- Log Facility is set to info by default and can be override with an env
var: ANSIBLE_CVP_LOG_LEVEL
- Log destination is a file set to /temp/arista.cvp.debug.log and can be
override with an env var: ANSIBLE_CVP_LOG_FILE

Log output examples:
--------------------
```
03-04 11:35 arista.cvp.cv_facts INFO     Start cv_facts module execution
03-04 11:35 arista.cvp.cv_facts INFO     Connecting to CVP
03-04 11:35 urllib3.connectionpool DEBUG    Starting new HTTPS connection (1): 10.83.28.164:443
```
Configure default handler to run log rotation by default to avoid to
saturate disk storage.
Even if no logging is active in modules, default configuration has been
set:

```
import ansible_collections.arista.cvp.plugins.module_utils.logger

MODULE_LOGGER = logging.getLogger('arista.cvp.cv_facts')
MODULE_LOGGER.info('Start cv_facts module execution')

[...]

MODULE_LOGGER.debug('*** Connected to CVP')
```
@titom73 titom73 added type: enhancement New feature or request status: in-progress Currently under investigation or implementation status: cherry_pick Issue / PR shall be cherry pick labels Mar 4, 2020
@titom73 titom73 self-assigned this Mar 4, 2020
@titom73 titom73 requested review from networkop and Hugh-Adams March 4, 2020 15:17
@titom73 titom73 marked this pull request as ready for review March 4, 2020 15:17
Copy link
Contributor

@networkop networkop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great.

@titom73 titom73 added the state: accepted Issue is part of the development roadmap label Mar 5, 2020
titom73 added 2 commits March 5, 2020 21:59
Because URLLIB3 is logging a lot, being able to specificy urllib3
specifically is implemented:

- Log facilyt is set to WARNING by default for urllib3 handler
- User can get other verbosity with env variable: `export ANSIBLE_CVP_LOG_APICALL=debug`

Output is part of collection log file.
@titom73
Copy link
Contributor Author

titom73 commented Mar 5, 2020

Todo: Create handler for module_utils/cv_api* files.

arista.cvp.cv_container: DEBUG - func: is_container_empty (L:550) - get_devices_in_container Undefined
root        : DEBUG - func: get_devices_in_container (L:929) - * cv_api2019 - container name is: Undefined

titom73 added 8 commits March 7, 2020 09:14
- Linting: All branches except master and tag
- Ansible-test: Pull request with base releases/*
- Rebase: rebase pr when user comment with /rebase
- Stale: When issue/PR have not label state:accepted and inactive for 30
days. Closed after 5 days after stale
Even if no logging is active in modules, default configuration has been
set:

```
import ansible_collections.arista.cvp.plugins.module_utils.logger

MODULE_LOGGER = logging.getLogger('arista.cvp.cv_facts')
MODULE_LOGGER.info('Start cv_facts module execution')

[...]

MODULE_LOGGER.debug('*** Connected to CVP')
```
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
```
@titom73 titom73 added status: testing PR under testing and removed status: cherry_pick Issue / PR shall be cherry pick status: in-progress Currently under investigation or implementation labels Mar 7, 2020
@titom73 titom73 merged commit c1a7710 into releases/v1.0.x Mar 7, 2020
@titom73 titom73 deleted the features/logging branch March 7, 2020 12:29
@titom73 titom73 mentioned this pull request Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: accepted Issue is part of the development roadmap status: testing PR under testing type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants