-
Notifications
You must be signed in to change notification settings - Fork 61
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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
networkop
approved these changes
Mar 4, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great.
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.
Todo: Create handler for
|
- 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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goals:
Based on logging library
Workflow:
MODULE_LOGGER = logging.getLogger('arista.cvp.cv_facts')
Options & configuration:
var:
ANSIBLE_CVP_LOG_LEVEL
/tmp/arista.cvp.debug.log
and can beoverride with an env var:
ANSIBLE_CVP_LOG_FILE
Log output examples: