-
Notifications
You must be signed in to change notification settings - Fork 56
Support log configuration in the .env file #230
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f424399
Outline of changes
rodrigobr-msft c44287a
Adding logging configuration handling when loading configuration
rodrigobr-msft 7712b93
name to level mapping fix for Python 3.10
rodrigobr-msft 44c0731
Code feedback changes
rodrigobr-msft 44386b4
Merge branch 'main' into users/robrandao/logging-with-config
rodrigobr-msft dccf8ae
Update libraries/microsoft-agents-activity/microsoft_agents/activity/…
rodrigobr-msft 6a4ac08
Small changes
rodrigobr-msft ca011cf
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft 8bb10c5
Update libraries/microsoft-agents-activity/microsoft_agents/activity/…
rodrigobr-msft 9a322bc
Merge branch 'main' into users/robrandao/logging-with-config
rodrigobr-msft 9b810ac
Merge branch 'main' into users/robrandao/logging-with-config
rodrigobr-msft 0f860d8
Creating ConfigurationErrorResources for microsoft-agents-activity
rodrigobr-msft 0d26e9c
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft f35009f
Pulling from remote
rodrigobr-msft b78948f
Merge branch 'users/robrandao/logging-with-config' of https://github.…
rodrigobr-msft 50eca2a
Merge branch 'main' into users/robrandao/logging-with-config
rodrigobr-msft c1b5224
Merge branch 'main' into users/robrandao/logging-with-config
rodrigobr-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
libraries/microsoft-agents-activity/microsoft_agents/activity/config/__init__.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from ._load_configuration import load_configuration_from_env | ||
|
|
||
| __all__ = [ | ||
| "load_configuration_from_env", | ||
| ] |
55 changes: 55 additions & 0 deletions
55
libraries/microsoft-agents-activity/microsoft_agents/activity/config/_configure_logging.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| import logging | ||
|
|
||
| from ..errors import configuration_errors | ||
|
|
||
| # in Python 3.11, we can move to using | ||
| # logging.getLevelNamesMapping() | ||
| _NAME_TO_LEVEL = { | ||
| "CRITICAL": logging.CRITICAL, | ||
| "FATAL": logging.FATAL, | ||
| "ERROR": logging.ERROR, | ||
| "WARN": logging.WARNING, | ||
| "WARNING": logging.WARNING, | ||
| "INFO": logging.INFO, | ||
| "INFORMATION": logging.INFO, # .NET parity | ||
| "DEBUG": logging.DEBUG, | ||
| "NOTSET": logging.NOTSET, | ||
| } | ||
|
|
||
|
|
||
| def _configure_logging(logging_config: dict): | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Configures logging based on the provided logging configuration dictionary. | ||
|
|
||
| :param logging_config: A dictionary containing logging configuration. | ||
| :raises ValueError: If an invalid log level is provided in the configuration. | ||
| """ | ||
|
|
||
| log_levels = logging_config.get("LOGLEVEL", {}) | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| console_handler = logging.StreamHandler() | ||
| console_handler.setFormatter( | ||
| logging.Formatter( | ||
| "%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)" | ||
| ) | ||
| ) | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| for key in log_levels: | ||
| level_name = log_levels[key].upper() | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| level = _NAME_TO_LEVEL.get(level_name) | ||
| if level is None: | ||
| raise ValueError( | ||
| configuration_errors.InvalidLoggingConfiguration.format(key, level_name) | ||
| ) | ||
|
|
||
| namespace = key.lower() | ||
| if namespace == "default": | ||
| logger = logging.getLogger() | ||
| else: | ||
| logger = logging.getLogger(namespace) | ||
|
|
||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger.handlers.clear() # Remove existing handlers to prevent duplicates | ||
| logger.addHandler(console_handler) | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger.setLevel(level) | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.