-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Make CLI respect file logging configuration option: enable_log_file and AZURE_LOGGING_ENABLE_LOG_FILE env variable #12949
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
Conversation
|
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) |
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.
The default for logging is no in az configure.
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.
However, changing it to no could be a breaking change since the bug made the actual default to be logging enabled.
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.
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.
jiasli
left a comment
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.
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)
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.