Conversation
631f874 to
c99c5ab
Compare
There was a problem hiding this comment.
Pull Request Overview
This pull request (SCANPY-135) introduces additional logging throughout the codebase to improve traceability of operations and errors. The key changes include:
- Adding logging statements in critical functions across the application, including engine provisioning, configuration loading, API operations, and CLI startup.
- Updating unit tests to verify the newly added log messages using mocks.
- Adjusting import statements to support the new logging integrations.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_pyproject_toml.py | Added patching of app_logging.get_logger to verify proper warning logging for malformed TOML. |
| tests/unit/test_configuration_loader.py | Updated import to include MagicMock alongside patch for enhanced test assertions. |
| tests/test_environment_variables.py | Patched the logger and updated test for invalid JSON logging, ensuring JSONDecodeError handling. |
| src/pysonar_scanner/scannerengine.py | Inserted logging messages to trace the engine download and command execution steps. |
| src/pysonar_scanner/configuration/pyproject_toml.py | Modified the exception handling to log errors during TOML parsing with detailed exception info. |
| src/pysonar_scanner/configuration/environment_variables.py | Enhanced JSONDecodeError handling by logging a warning with exception details. |
| src/pysonar_scanner/configuration/configuration_loader.py | Added an info log to indicate when the configuration properties are being loaded from sources. |
| src/pysonar_scanner/configuration/cli.py | Introduced logging imports to support logging in command line configuration handling. |
| src/pysonar_scanner/app_logging.py | Created a get_logger() helper function for a consistent logging interface across modules. |
| src/pysonar_scanner/api.py | Logged the download action for the analysis engine, aiding in tracking API interactions. |
| src/pysonar_scanner/main.py | Added multiple log statements to track application startup, configuration updates, and version checking. |
Seppli11
left a comment
There was a problem hiding this comment.
Thanks for adding log statements. I think this will really help us in the long run.
Personally though, I feel like we need to log very little additional information when --verbose isn't enabled. Therefore, IMHO, most info messages in this PR should be debug messages.
On the other hand, I think we log not enough when verbose is enabled - especially dynamic properties, like where has this file been loaded from.
Sorry about the vague ticket. I should have been more precise.
| logging.getLogger().setLevel(logging.DEBUG if verbose else logging.INFO) | ||
|
|
||
|
|
||
| def get_logger() -> logging.Logger: |
There was a problem hiding this comment.
I'm not sure I understand why the indirection. Why not just use logging.info, logging.debug, ...
There was a problem hiding this comment.
It was in the case we wanted to have a more refined logger like a named one or different loggers depending of the context. I removed it for now as we want something simple.
|
|
||
| def check_version(api): | ||
| def check_version(api: SonarQubeApi): | ||
| app_logging.get_logger().info("Checking SonarQube version...") |
There was a problem hiding this comment.
Not sure if this needs to be logged
| app_logging.get_logger().info("Analysis will be run on SonarQube Cloud") | ||
| return | ||
| version = api.get_analysis_version() | ||
| app_logging.get_logger().info("Analysis will be run on SonarQube version %s", version) |
There was a problem hiding this comment.
I feel it would be more useful to print the url, instead of these two logging statements
|
|
||
|
|
||
| def create_scanner_engine(api, cache_manager, config): | ||
| app_logging.get_logger().info("Creating the scanner engine...") |
There was a problem hiding this comment.
| app_logging.get_logger().info("Creating the scanner engine...") |
| Alternative, if the file IO fails, an IOError or OSError can be raised. | ||
| """ | ||
|
|
||
| app_logging.get_logger().info("Download the analysis engine...") |
There was a problem hiding this comment.
I think this logging statement should be part of the ScannerEngineProvisioner.provision method and probably should be debug level
There was a problem hiding this comment.
I removed it
| engine_info = self.api.get_analysis_engine() | ||
| cache_file = self.cache.get_file(engine_info.filename, engine_info.sha256) | ||
| if not cache_file.is_valid(): | ||
| app_logging.get_logger().info("Cached analysis engine is not valid.") |
There was a problem hiding this comment.
| app_logging.get_logger().info("Cached analysis engine is not valid.") | |
| app_logging.get_logger().debug("No valid cached analysis engine jar was found") |
| except Exception: | ||
| # If there's any error parsing the TOML file, return empty TomlProperties | ||
| # SCANPY-135: We should log the pyproject.toml parsing error | ||
| except Exception as e: |
There was a problem hiding this comment.
It would be nice to also have a debug log statement from where we loaded pyproject.toml and one if we didn't find a pyproject.toml file.
e.g.
logging.debug(f"pyproject.toml loaded from \"{filepath}\"")and
logging.debug(f"No pyproject.toml at \"{filepath}\"")There was a problem hiding this comment.
Same applies for the sonar_project_properties module. (e.g. have an debug message which file has been loaded and when nothing has been found)
| "The JSON in SONAR_SCANNER_JSON_PARAMS environment variable is invalid. The other environment variables will still be loaded.", | ||
| e, | ||
| ) | ||
|
|
There was a problem hiding this comment.
I could see it making sense having a debug statement which prints which environment variable have been loaded.
| logging.debug("Loaded environment properties: " + ", ".join(f"key=value" for key,value in properties.items())) |
| api = build_api(config) | ||
| check_version(api) | ||
| update_config_with_api_urls(config, api.base_urls) | ||
| app_logging.get_logger().debug(f"Configuration after update from API URL: {config}") |
There was a problem hiding this comment.
| app_logging.get_logger().debug(f"Configuration after update from API URL: {config}") | |
| app_logging.get_logger().debug(f"Final loaded configuration: {config}") |
| app_logging.get_logger().info("Starting Pysonar, the Sonar scanner CLI for Python") | ||
| config = ConfigurationLoader.load() | ||
| set_logging_options(config) | ||
| app_logging.get_logger().debug(f"Loaded configuration: {config}") |
There was a problem hiding this comment.
| app_logging.get_logger().debug(f"Loaded configuration: {config}") |
e19deee to
d489c5b
Compare
d489c5b to
e026662
Compare
|




No description provided.