Skip to content

🧹 [code health improvement] Use logging instead of print in converter.py and fetcher.py#3

Open
frostmute wants to merge 1 commit intomainfrom
code-health-logging-improvement-13484029814748313138
Open

🧹 [code health improvement] Use logging instead of print in converter.py and fetcher.py#3
frostmute wants to merge 1 commit intomainfrom
code-health-logging-improvement-13484029814748313138

Conversation

@frostmute
Copy link
Copy Markdown
Owner

This PR replaces print statements in the claw2manus library with the standard logging module. This improvement enhances maintainability and allows consumers of the library to control log output.

🎯 What:

  • Added package-level logging configuration in claw2manus/__init__.py.
  • Replaced all print calls in claw2manus/converter.py and claw2manus/fetcher.py with appropriate logging calls.
  • Configured logging.basicConfig in claw2manus/cli.py to preserve console output.
  • Removed dead code (commented-out prints) in claw2manus/validators.py.

💡 Why:

  • Library code should avoid using print as it pollutes stdout/stderr of the calling application. Using logging is the standard practice for Python libraries.

✅ Verification:

  • Verified code changes via read_file and grep.
  • Ran a verification script (verify_logging.py) with mocked dependencies (since yaml, requests, etc. were missing in the environment) to confirm loggers are correctly initialized and functional.
  • Received a #Correct# rating from code review.

✨ Result:

  • Improved library maintainability and compliance with Python development best practices.

PR created automatically by Jules for task 13484029814748313138 started by @frostmute

Transitioned the library code from using `print` statements to using the Python `logging` module. This allows applications using the library to better control and capture output.

Changes:
- Initialized logging with a `NullHandler` in `claw2manus/__init__.py`.
- Replaced `print` with `logger.error` and `logger.info` in `converter.py` and `fetcher.py`.
- Configured logging in `cli.py` to maintain existing CLI output behavior.
- Cleaned up commented-out debug prints in `validators.py`.
- Verified changes using a custom script with mocked dependencies due to environment constraints.

Co-authored-by: frostmute <989225+frostmute@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces standard print statements with a structured logging system across the claw2manus package, including the addition of a NullHandler in the package root and basic configuration in the CLI. The review feedback recommends further improvements to the logging implementation, specifically using logger.exception() within except blocks to capture full stack traces and adopting lazy string formatting instead of f-strings to avoid unnecessary interpolation.

Comment thread claw2manus/converter.py
return config if config else default_config
except Exception as e:
print(f"Error loading config from {config_path}: {e}")
logger.error(f"Error loading config from {config_path}: {e}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Within an except block, it is recommended to use logger.exception() instead of logger.error(). This ensures the full stack trace is captured, which is crucial for troubleshooting. Additionally, using lazy formatting (passing arguments to the logger) is preferred over f-strings in logging to avoid unnecessary string interpolation when the log level is disabled.

Suggested change
logger.error(f"Error loading config from {config_path}: {e}")
logger.exception("Error loading config from %s", config_path)

Comment thread claw2manus/fetcher.py
return response.text
except requests.exceptions.RequestException as e:
print(f"Error fetching from GitHub: {e}")
logger.error(f"Error fetching from GitHub: {e}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In an except block, use logger.exception() to automatically include the stack trace in the log output. This is significantly more helpful for debugging than just logging the string representation of the exception. Also, prefer lazy formatting (passing arguments to the logger) over f-strings to avoid unnecessary string interpolation.

Suggested change
logger.error(f"Error fetching from GitHub: {e}")
logger.exception("Error fetching from GitHub")

Comment thread claw2manus/fetcher.py
return None
except requests.exceptions.RequestException as e:
print(f"Error scraping from clawhub.ai: {e}")
logger.error(f"Error scraping from clawhub.ai: {e}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In an except block, use logger.exception() to automatically include the stack trace in the log output. This is significantly more helpful for debugging than just logging the string representation of the exception. Also, prefer lazy formatting (passing arguments to the logger) over f-strings to avoid unnecessary string interpolation.

Suggested change
logger.error(f"Error scraping from clawhub.ai: {e}")
logger.exception("Error scraping from clawhub.ai")

Comment thread claw2manus/fetcher.py
return match.group("author")
except Exception as e:
print(f"Error discovering author via GitHub: {e}")
logger.error(f"Error discovering author via GitHub: {e}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In an except block, use logger.exception() to automatically include the stack trace in the log output. This is significantly more helpful for debugging than just logging the string representation of the exception. Also, prefer lazy formatting (passing arguments to the logger) over f-strings to avoid unnecessary string interpolation.

Suggested change
logger.error(f"Error discovering author via GitHub: {e}")
logger.exception("Error discovering author via GitHub")

Comment thread claw2manus/fetcher.py

# Try to discover author via GitHub Search API
print(f"Author not specified for '{skill_identifier}'. Attempting to discover via GitHub API...")
logger.info(f"Author not specified for '{skill_identifier}'. Attempting to discover via GitHub API...")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Prefer lazy formatting (e.g., logger.info('message %s', arg)) over f-strings for logging. This avoids the overhead of string interpolation if the current log level is higher than INFO, which is a best practice for Python libraries.

Suggested change
logger.info(f"Author not specified for '{skill_identifier}'. Attempting to discover via GitHub API...")
logger.info("Author not specified for '%s'. Attempting to discover via GitHub API...", skill_identifier)

Comment thread claw2manus/fetcher.py
discovered_author = self.discover_author_via_github(skill_identifier)
if discovered_author:
print(f"Discovered author: {discovered_author}")
logger.info(f"Discovered author: {discovered_author}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Prefer lazy formatting (e.g., logger.info('message %s', arg)) over f-strings for logging. This avoids the overhead of string interpolation if the current log level is higher than INFO, which is a best practice for Python libraries.

Suggested change
logger.info(f"Discovered author: {discovered_author}")
logger.info("Discovered author: %s", discovered_author)

Comment thread claw2manus/fetcher.py

# Fallback to scraping if GitHub fails and no author was specified
print(f"Falling back to scraping from {self.CLAW_HUB_WEBSITE_URL.format(name=skill_identifier)}...")
logger.info(f"Falling back to scraping from {self.CLAW_HUB_WEBSITE_URL.format(name=skill_identifier)}...")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Prefer lazy formatting (e.g., logger.info('message %s', arg)) over f-strings for logging. This avoids the overhead of string interpolation if the current log level is higher than INFO, which is a best practice for Python libraries.

Suggested change
logger.info(f"Falling back to scraping from {self.CLAW_HUB_WEBSITE_URL.format(name=skill_identifier)}...")
logger.info("Falling back to scraping from %s...", self.CLAW_HUB_WEBSITE_URL.format(name=skill_identifier))

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.

1 participant