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 common logging mechanism for all modules. #124

Closed
titom73 opened this issue Jan 28, 2020 · 1 comment
Closed

Implement common logging mechanism for all modules. #124

titom73 opened this issue Jan 28, 2020 · 1 comment
Assignees
Labels
state: accepted Issue is part of the development roadmap type: enhancement New feature or request
Milestone

Comments

@titom73
Copy link
Contributor

titom73 commented Jan 28, 2020

Implement a generic logging / debug support in all modules to make debug easier.

Some pointers provided by @networkop during previous review:

@titom73 titom73 added type: enhancement New feature or request state: accepted Issue is part of the development roadmap labels Jan 28, 2020
@titom73 titom73 added this to the v1.1 milestone Jan 28, 2020
titom73 added a commit that referenced this issue Mar 4, 2020
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
```
titom73 added a commit that referenced this issue Mar 4, 2020
Configure default handler to run log rotation by default to avoid to
saturate disk storage.
titom73 added a commit that referenced this issue Mar 4, 2020
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 status: in-progress Currently under investigation or implementation and removed state: accepted Issue is part of the development roadmap labels Mar 4, 2020
@titom73 titom73 self-assigned this Mar 4, 2020
@titom73 titom73 added the state: accepted Issue is part of the development roadmap label Mar 5, 2020
titom73 added a commit that referenced this issue Mar 5, 2020
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

Tracked in PR #146

@titom73 titom73 closed this as completed Mar 5, 2020
@titom73 titom73 removed the status: in-progress Currently under investigation or implementation label Mar 5, 2020
titom73 added a commit that referenced this issue Mar 7, 2020
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 added a commit that referenced this issue Mar 7, 2020
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
```
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 type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant