-
Notifications
You must be signed in to change notification settings - Fork 1
Dse/log standardization prod 14939 #411
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
base: main
Are you sure you want to change the base?
Conversation
Removed duplicate code. Configure the location of logs with an option instead of environment variable
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.
Pull Request Overview
This pull request focuses on standardizing logging across the Babylon codebase to improve consistency and maintainability. The changes include migrating from hard-coded logger names to module-based naming, removing redundant log prefixes, and enhancing the logging infrastructure.
Key Changes:
- Standardized logger initialization from
getLogger("Babylon")togetLogger(__name__)across all modules for better log traceability - Removed redundant prefixes (
[api],[powerbi],[babylon]) from log messages since the logger name now includes module information - Refactored logging setup in main.py with dedicated file handlers for standard logs and errors, plus a new
--log-pathCLI option
Reviewed Changes
Copilot reviewed 93 out of 93 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| Babylon/main.py | Introduced setup_logging() function with file handlers and new --log-path option; removed test mode parameter |
| Babylon/utils/response.py | Changed logger name to __name__ and added info logging for YAML file dumps |
| Babylon/test/api/datasets/test_datasets_service.py | Updated test expectations to match API response format changes (list instead of dict) and added workspace-id parameter |
| Babylon/commands/macro/*.py | Standardized logger initialization and removed log prefixes from messages |
| Babylon/commands/api/**/*.py | Standardized logger names, removed JSON dumps from logs, removed redundant prefixes, and corrected spelling errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from Babylon.commands.api.solutions.services.solutions_security_svc import SolutionSecurityService | ||
|
|
||
| logger = getLogger("Babylon") | ||
| logger = getLogger("__name__") |
Copilot
AI
Nov 14, 2025
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 logger is incorrectly initialized with "__name__" as a string literal instead of the __name__ variable. This will result in all log messages from this module showing "name" instead of the actual module name.
Change to: logger = getLogger(__name__)
| default_security = response.json() | ||
| logger.info(json.dumps(default_security, indent=2)) | ||
| logger.info(f"[api] default RBAC access successfully setted with role {[role]}") | ||
| logger.info(f"default RBAC access successfully setted with role {[role]}") |
Copilot
AI
Nov 14, 2025
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 word "setted" should be corrected to "set" (proper past participle of "set").
| from Babylon.commands.api.solutions.services.solutions_security_svc import SolutionSecurityService | ||
|
|
||
| logger = getLogger("Babylon") | ||
| logger = getLogger("__name__") |
Copilot
AI
Nov 14, 2025
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 logger is incorrectly initialized with "__name__" as a string literal instead of the __name__ variable. This will result in all log messages from this module showing "name" instead of the actual module name.
Change to: logger = getLogger(__name__)
| return CommandResponse.fail() | ||
| run_templates = response.json() | ||
| logger.info(json.dumps(run_templates, indent=2)) | ||
| logger.info(f"Retrieving all runtemplates in the solution {[service_state['api']['solution_id']]}") |
Copilot
AI
Nov 14, 2025
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 log message is placed after the API call returns successfully, which changes the logging behavior. The message says "Retrieving" (present tense) but appears after retrieval is complete. Consider either:
- Moving this line before line 39 (before the API call) to maintain the original intent, or
- Changing the message to past tense: "Retrieved all runtemplates from solution..."
| env.store_state_in_cloud(state) | ||
| logger.info(json.dumps(organizations, indent=2)) | ||
| ids = [o["id"] for o in organizations] | ||
| logger.info(f"Retrieved {ids} organizations details") |
Copilot
AI
Nov 14, 2025
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 log message format is incorrect. The f-string is trying to insert a list of IDs directly before the word "organizations", resulting in output like "Retrieved ['id1', 'id2'] organizations details".
Consider changing to: logger.info(f"Retrieved {len(ids)} organizations details: {ids}")
| logger.info(f"Retrieved {ids} organizations details") | |
| logger.info(f"Retrieved {len(ids)} organizations details: {ids}") |
| from Babylon.commands.api.solutions.services.solutions_security_svc import SolutionSecurityService | ||
|
|
||
| logger = getLogger("Babylon") | ||
| logger = getLogger("__name__") |
Copilot
AI
Nov 14, 2025
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 logger is incorrectly initialized with "__name__" as a string literal instead of the __name__ variable. This will result in all log messages from this module showing "name" instead of the actual module name.
Change to: logger = getLogger(__name__)
| from Babylon.commands.api.solutions.services.solutions_security_svc import SolutionSecurityService | ||
|
|
||
| logger = getLogger("Babylon") | ||
| logger = getLogger("__name__") |
Copilot
AI
Nov 14, 2025
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 logger is incorrectly initialized with "__name__" as a string literal instead of the __name__ variable. This will result in all log messages from this module showing "name" instead of the actual module name.
Change to: logger = getLogger(__name__)
| from Babylon.commands.api.solutions.services.solutions_security_svc import SolutionSecurityService | ||
|
|
||
| logger = getLogger("Babylon") | ||
| logger = getLogger("__name__") |
Copilot
AI
Nov 14, 2025
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 logger is incorrectly initialized with "__name__" as a string literal instead of the __name__ variable. This will result in all log messages from this module showing "name" instead of the actual module name.
Change to: logger = getLogger(__name__)
| if len(datasets) and filter: | ||
| datasets = jmespath.search(filter, datasets) | ||
| logger.info(json.dumps(datasets, indent=2)) | ||
| logger.info(f"Retrieved {[d.get('id') for d in datasets]} datastes") |
Copilot
AI
Nov 14, 2025
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.
Typo in log message: "datastes" should be "datasets".
| logger.info(f"Retrieved {[d.get('id') for d in datasets]} datastes") | |
| logger.info(f"Retrieved {[d.get('id') for d in datasets]} datasets") |
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.
Pull Request Overview
Copilot reviewed 94 out of 94 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| log_file_handler.setLevel(logging.INFO) | ||
| error_file_handler = logging.FileHandler(log_path / "babylon.error") | ||
| error_file_handler.setLevel(logging.WARNING) | ||
| logging.basicConfig(format="%(asctime)s:%(levelname)s:%(name)s:%(message)s", |
Copilot
AI
Nov 14, 2025
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.
Inconsistent logging format: The format string uses %(name)s to include the logger name, but line 19 changes the root logger from getLogger("Babylon") to getLogger() (root logger). This means all loggers will now use their module names (e.g., "Babylon.commands.api.workspaces.create") which could make the log format string %(name)s produce very long entries. Consider adjusting the format to truncate or use a shorter format for the name.
|
|
||
|
|
||
| def setup_logging(log_path: pathlibPath = pathlibPath.cwd()) -> None: | ||
| import click # noqa F401 |
Copilot
AI
Nov 14, 2025
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.
Unused import: import click # noqa F401 is imported but not used in this function. The import appears to be only for the tracebacks_suppress parameter, but it's already imported at the top level of the module.
| print(response.text) | ||
| return CommandResponse.success(response.text) |
Copilot
AI
Nov 14, 2025
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.
Changed return type from JSON to text: The function now returns response.text instead of response.json(). This changes the API behavior - callers expecting JSON data will now receive a string. This also adds a print() statement that outputs directly to stdout, which may not be desired in all contexts (e.g., when output is redirected or when running in non-interactive mode).
7c62e9e to
205d019
Compare
No description provided.