Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 23, 2025

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, and PythonSSAPropagationCallGraphBuilder
  • ML Utilities: Replaced debug output in TensorType and error logging in CloudFunction
  • Parser Components: Fixed debug statements in both jython and jython3 PythonParser classes
  • Loader Components: Updated logging in PytestLoader and Python2Loader
  • 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, and TestPythonMLCallGraphShape.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.java main method error handling and user messages
  • DiagnosticsFormatter.java print 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 Copilot AI changed the title [WIP] Using logging instead of print statements Replace System.out/err.println with logging in non-CLI analysis code Sep 23, 2025
@Copilot Copilot AI requested a review from khatchad September 23, 2025 20:11
Copilot finished work on behalf of khatchad September 23, 2025 20:11
@khatchad khatchad marked this pull request as ready for review September 23, 2025 20:12
@khatchad
Copy link
Collaborator

@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.

Copy link
Contributor Author

Copilot AI commented Sep 23, 2025

@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

@Copilot Copilot AI changed the title Replace System.out/err.println with logging in non-CLI analysis code Replace System.out/err.println with logging in analysis and test code Sep 23, 2025
Copilot finished work on behalf of khatchad September 23, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using logging instead of print statements
2 participants