{Core} Make CLI respect file logging configuration option: enable_log_file and AZURE_LOGGING_ENABLE_LOG_FILE env variable#12949
Merged
haroldrandom merged 3 commits intoAzure:devfrom Apr 10, 2020
Conversation
Collaborator
|
pytest |
| self._init_command_logfile_handlers(cmd_logger, args) # pylint: disable=protected-access | ||
| get_logger(__name__).debug("metadata file logging enabled - writing logs to '%s'.", self.command_log_dir) | ||
| # overwrite CLILogging._is_file_log_enabled() from knack | ||
| self.file_log_enabled = cli_ctx.config.getboolean('logging', 'enable_log_file', fallback=True) |
Member
There was a problem hiding this comment.
The default for logging is no in az configure.
Member
There was a problem hiding this comment.
However, changing it to no could be a breaking change since the bug made the actual default to be logging enabled.
Contributor
Author
There was a problem hiding this comment.
I overwrite the implementation from knack to enable logging by default like currenty CLI does, so it's transparency to user. Not a breaking it is.
fengzhou-msft
approved these changes
Apr 10, 2020
jiasli
approved these changes
Apr 10, 2020
Member
jiasli
left a comment
There was a problem hiding this comment.
FYI, Knack handles the logging correctly:
https://github.com/microsoft/knack/blob/master/knack/log.py#L129-L131
if self.file_log_enabled:
self._init_logfile_handlers(root_logger, cli_logger)
get_logger(__name__).debug("File logging enabled - writing logs to '%s'.", self.log_dir)
2 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of PR (Mandatory)
I am migrating test framwork from nose to pytest and found CLI would log every command's invocation output to a filep even though I configured in ~/.azure/config
And consequently, pytest wouldn't clear the AzCLI instance cleanly such that the test process would crash because of holding too many file descriptor (over the limit by OS):


So, here, I want to enable the ability to repect the logging configuratin even though I won't use it in CI. I will fire another PR to fix the bug that CLI holding too many opened files. (related issues: #12882, #10435)
Testing Guide
It affects two instance variables' assignment
command_logger_handlerandcommand_metadata_logger.In the places they are referenced, there is a fault protection, so, it won't be a problem if user disbale the output of a logger to a log file.
Verify by running command with prefix
AZURE_LOGGING_ENABLE_LOG_FILE=noor config in ~/.azure/config like above, then there should be no files under~/.azure/commands/. Otherwise, there should be a file under that folderHistory Notes:
(Fill in the following template if multiple notes are needed, otherwise PR title will be used for history note.)
[Component Name 1] (BREAKING CHANGE:) (az command:) make some customer-facing change.
[Component Name 2] (BREAKING CHANGE:) (az command:) make some customer-facing change.
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.