Skip to content

Conversation

OutisLi
Copy link

@OutisLi OutisLi commented Aug 30, 2025

the cp2kdata python package will pollution the logging information:
ec3b1f08d6eef965b1b4ea8fd028ab80

This pull corrects the root logging info, and change the style of root logging to separate from sub logging.

Summary by CodeRabbit

  • Refactor
    • Standardized logging so the application consistently emits INFO-level messages.
    • Adopted a unified log format: “[timestamp] logger - LEVEL : message” for clearer, timestamped diagnostics.
    • Existing log handlers are respected and updated; default logging is initialized only when no handlers exist.
    • No changes to runtime behavior or public interfaces.

Copy link

coderabbitai bot commented Aug 30, 2025

📝 Walkthrough

Walkthrough

main() now configures the root logger explicitly: sets level INFO, creates a custom formatter "%(asctime)s %(name)s - %(levelname)-5s : %(message)s", updates existing handlers’ formatter and level if present, or calls basicConfig with the same settings. No other behavior changed.

Changes

Cohort / File(s) Summary of Changes
Logging initialization
dpgen2/entrypoint/main.py
Replace simple logging.basicConfig(level=logging.INFO) with explicit root-logger configuration: set level to INFO; create formatter %(asctime)s %(name)s - %(levelname)-5s : %(message)s; if root logger has handlers, update each handler's formatter and level; otherwise call logging.basicConfig with the same level and formatter.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7a8d36b and 7b83fae.

📒 Files selected for processing (1)
  • dpgen2/entrypoint/main.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • dpgen2/entrypoint/main.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build (3.9)
  • GitHub Check: build (3.10)
  • GitHub Check: build (3.8)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
dpgen2/entrypoint/main.py (2)

327-344: Don’t override existing logging configs; set levels only when you own the handlers.

Unconditionally setting the root logger level and all handler levels to INFO can silently change user/dflow configurations. Limit mutations to StreamHandlers and only when no handlers exist; also allow env override for log level.

@@
-    root_logger = logging.getLogger()
-    root_logger.setLevel(logging.INFO)
+    root_logger = logging.getLogger()
     formatter = logging.Formatter(
         "[%(asctime)s] %(name)s - %(levelname)-5s : %(message)s"
     )
 
-    if root_logger.hasHandlers():
-        # If handlers already exist (e.g., created by other modules), update their formatter and level
-        for handler in root_logger.handlers:
-            handler.setFormatter(formatter)
-            handler.setLevel(logging.INFO)
+    if root_logger.handlers:
+        # Respect previously configured handlers; only touch StreamHandlers and avoid changing explicit levels
+        for handler in list(root_logger.handlers):
+            if isinstance(handler, logging.StreamHandler):
+                handler.setFormatter(formatter)
+                if handler.level == logging.NOTSET:
+                    handler.setLevel(logging.INFO)
     else:
-        # If no handlers exist, initialize logging with the desired format and level
-        logging.basicConfig(
-            level=logging.INFO,
-            format="[%(asctime)s] %(name)s - %(levelname)-5s : %(message)s",
-        )
+        # If no handlers exist, we own logging config
+        level_name = os.getenv("DPGEN2_LOGLEVEL", "INFO").upper()
+        level = getattr(logging, level_name, logging.INFO)
+        root_logger.setLevel(level)
+        stream = logging.StreamHandler()
+        stream.setLevel(level)
+        stream.setFormatter(formatter)
+        root_logger.addHandler(stream)

334-344: If the goal is distinct styles for DPGEN2 vs third-party (e.g., cp2kdata), split handlers with filters.

Updating one root handler’s formatter doesn’t actually separate styles. Optionally add two StreamHandlers: one for dpgen2 (INFO, detailed format) and one for others (WARNING, simpler format). This also curbs cp2kdata noise by default.

@@
-    else:
-        # If no handlers exist, initialize logging with the desired format and level
-        logging.basicConfig(
-            level=logging.INFO,
-            format="[%(asctime)s] %(name)s - %(levelname)-5s : %(message)s",
-        )
+    else:
+        level_name = os.getenv("DPGEN2_LOGLEVEL", "INFO").upper()
+        level = getattr(logging, level_name, logging.INFO)
+        root_logger.setLevel(level)
+
+        # DPGEN2 handler (detailed)
+        dp_handler = logging.StreamHandler()
+        dp_handler.addFilter(logging.Filter("dpgen2"))  # passes names starting with "dpgen2"
+        dp_handler.setLevel(level)
+        dp_handler.setFormatter(formatter)
+        root_logger.addHandler(dp_handler)
+
+        # Third-party handler (quieter, simpler)
+        class _ExcludeDPGEN2(logging.Filter):
+            def filter(self, record):
+                return not record.name.startswith("dpgen2")
+        ext_handler = logging.StreamHandler()
+        ext_handler.addFilter(_ExcludeDPGEN2())
+        ext_level_name = os.getenv("DPGEN2_3P_LOGLEVEL", "WARNING").upper()
+        ext_level = getattr(logging, ext_level_name, logging.WARNING)
+        ext_handler.setLevel(ext_level)
+        ext_handler.setFormatter(logging.Formatter("%(levelname)s: %(name)s: %(message)s"))
+        root_logger.addHandler(ext_handler)

Minimal alternative: explicitly quiet cp2kdata without split handlers:

  • logging.getLogger("cp2kdata").setLevel(getattr(logging, os.getenv("DPGEN2_CP2KDATA_LOGLEVEL", "WARNING").upper(), logging.WARNING))
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between eb779cb and 7a8d36b.

📒 Files selected for processing (1)
  • dpgen2/entrypoint/main.py (1 hunks)

Copy link

codecov bot commented Aug 30, 2025

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.14%. Comparing base (eb779cb) to head (7b83fae).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
dpgen2/entrypoint/main.py 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #313      +/-   ##
==========================================
- Coverage   84.23%   84.14%   -0.10%     
==========================================
  Files         104      104              
  Lines        6129     6136       +7     
==========================================
  Hits         5163     5163              
- Misses        966      973       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wanghan-iapcm wanghan-iapcm requested a review from zjgemi September 1, 2025 00:33
@zjgemi
Copy link
Collaborator

zjgemi commented Sep 1, 2025

The cp2kdata module modifies the format of the global logger, which is an improper practice. DPGEN2 directly uses this global logger, and repeatedly modifying its format is not advisable. Besides, modifying the logging format in the main() function in the entrypoint only affects logs in the debug mode and does not influence logs in workflow nodes. If modifying the logging format is necessary, it would be better to create a dedicated logger for DPGEN2, and update all logging implementations to use this specific logger. Otherwise, efforts should be made to advocate for cp2kdata to adjust its behavior regarding logger format modifications.

@OutisLi
Copy link
Author

OutisLi commented Sep 2, 2025

The cp2kdata module modifies the format of the global logger, which is an improper practice. DPGEN2 directly uses this global logger, and repeatedly modifying its format is not advisable. Besides, modifying the logging format in the main() function in the entrypoint only affects logs in the debug mode and does not influence logs in workflow nodes. If modifying the logging format is necessary, it would be better to create a dedicated logger for DPGEN2, and update all logging implementations to use this specific logger. Otherwise, efforts should be made to advocate for cp2kdata to adjust its behavior regarding logger format modifications.

Thanks, in that case, I'll take this pr for my personal usage.

@OutisLi OutisLi closed this Sep 2, 2025
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.

2 participants