Replace System.out/err.println with logging in analysis and test code
This PR refactors the codebase to replace System.out.println() and System.err.println() statements with proper logging in non-CLI analysis, processing, and test code, while preserving appropriate print statements in CLI-related functionality.
Changes Made
Refactored 37 instances across key analysis components and test files:
- Core Analysis Files: Fixed debug and status output in
PythonCAstToIRTranslator,PythonTurtleSKLearnClassifierAnalysis,PythonTurtlePandasMergeAnalysis, andPythonSSAPropagationCallGraphBuilder - ML Utilities: Replaced debug output in
TensorTypeand error logging inCloudFunction - Parser Components: Fixed debug statements in both jython and jython3
PythonParserclasses - Loader Components: Updated logging in
PytestLoaderandPython2Loader - Analysis Engines: Fixed debug output in
PytestAnalysisEngine - JEP Components: Fixed class hierarchy logging in
ParquetPythonReader - Test Files: Extended logging to test files including
TestClasses.java,TestCalls.java,TestSource.java, andTestPythonMLCallGraphShape.java
Established consistent logging patterns:
- Added proper logger initialization:
private static final Logger LOGGER = Logger.getLogger(ClassName.class.getName()); - Used appropriate log levels:
LOGGER.fine()for debug information,LOGGER.info()for status messages,LOGGER.severe()for errors - Integrated with existing logging infrastructure using
java.util.logging - Applied consistent patterns across both production analysis code and test code
Preserved CLI-appropriate usage:
Ariadne.javamain method error handling and user messagesDiagnosticsFormatter.javaprint methods for user-facing output- Parser main methods used as CLI utilities
- LSP
showMessage()methods for user communication
Example
Before:
public void someAnalysisMethod() {
// Debug information goes to stderr
System.err.println("Processing tensor: " + tensorInfo);
if (errorCondition) {
System.err.println("There was an error generating diagnostics");
}
}
After:
private static final Logger LOGGER = Logger.getLogger(ClassName.class.getName());
public void someAnalysisMethod() {
// Debug information uses appropriate logging level
LOGGER.fine("Processing tensor: " + tensorInfo);
if (errorCondition) {
LOGGER.severe("There was an error generating diagnostics");
}
}
The changes improve code maintainability by centralizing logging configuration and allowing proper log level control throughout both production and test code, while maintaining all existing CLI functionality for end users.
Fixes #331.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
@copilot Do we also use logging in test files? If so, then perhaps it is appropriate to also refactor print statements in test files to use logging.
@copilot Do we also use logging in test files? If so, then perhaps it is appropriate to also refactor print statements in test files to use logging.
Yes, the codebase already uses logging in test files. Analysis showed some test files like TestCalls.java already had proper logger setup, indicating an incomplete migration. I've refactored key test files to use consistent logging patterns, replacing ~4 instances across TestClasses.java, TestCalls.java, TestSource.java, and TestPythonMLCallGraphShape.java. The changes use LOGGER.info() for test results and LOGGER.fine() for detailed debug output, providing better control over test output through logging configuration. Commit: c3197c6