-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactor logging #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor logging #306
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the logging infrastructure by deprecating configure_logger() and introducing a more flexible logging setup API with setup() and setup_module() functions. The new API provides enhanced functionality including rich console formatting, per-submodule log levels, file handlers, and warning capture.
- Introduces
setup()function with comprehensive logging configuration options (console, color, file handlers, submodule levels, etc.) - Adds
setup_module()for basic logger configuration with dictConfig - Deprecates
configure_logger()(renamed tosetup_logging()) with migration path to new API - Updates all example files and CLI tools to use the new
setup_logging()function - Adds comprehensive test coverage for new logging functionality
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| agentlightning/logging.py | Core refactoring: adds setup() and setup_module() functions, deprecates old configure_logger() as setup_logging(), adds file handler support and helper utilities |
| agentlightning/init.py | Updates exports to expose new logging functions through module API |
| tests/test_logging.py | New comprehensive test suite covering all logging configuration scenarios including multiprocessing, file handlers, and rich formatting |
| tests/utils/test_server_launcher.py | Removes deprecated configure_logger() import and call |
| examples/*/*.py | Updates 13 example files to use setup_logging() instead of configure_logger() |
| agentlightning/cli/store.py | Updates CLI store command to use setup_logging() |
| agentlightning/verl/daemon.py | Updates VERL daemon to use setup_logging() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
agentlightning/logging.py
Outdated
| from typing import Any, Dict, Optional | ||
|
|
||
| __all__ = ["configure_logger"] | ||
| __all__ = ["setup_logging"] |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The __all__ list only exports setup_logging (the deprecated function), but not the new setup and setup_module functions. This means these new functions won't be included when using from agentlightning.logging import *. Consider adding "setup" and "setup_module" to the __all__ list.
| __all__ = ["setup_logging"] | |
| __all__ = ["setup_logging", "setup", "setup_module"] |
agentlightning/logging.py
Outdated
| >>> setup(extra_handlers=[fh]) | ||
| """ | ||
| # Ensure UTF-8 encoding on Windows consoles | ||
| # Note: This change does not fully represent support for execution under the windown system. |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "windown" should be "Windows".
| # Note: This change does not fully represent support for execution under the windown system. | |
| # Note: This change does not fully represent support for execution under the Windows system. |
agentlightning/logging.py
Outdated
| if color is not False: | ||
| fmt_name = "rich" | ||
| if isinstance(color, dict): | ||
| rich_handler_config = color | ||
| else: | ||
| rich_handler_config: Dict[str, Any] = { | ||
| "rich_tracebacks": True, | ||
| "markup": False, | ||
| "show_time": True, | ||
| "show_path": True, | ||
| } | ||
| root_cfg["handlers"]["console"] = { | ||
| "class": "rich.logging.RichHandler", | ||
| "level": level, | ||
| **rich_handler_config, | ||
| } | ||
| # RichHandler manages its own style; keep formatter None | ||
| else: | ||
| fmt_name = "plain" | ||
| root_cfg["formatters"][fmt_name] = { | ||
| "format": DEFAULT_FORMAT, | ||
| "datefmt": DATE_FORMAT, | ||
| } | ||
|
|
||
| if console: | ||
| root_cfg["handlers"]["console"] = { | ||
| "class": "logging.StreamHandler", | ||
| "level": level, | ||
| "formatter": fmt_name, | ||
| } |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent behavior: When color=True and console=False, a RichHandler is still created (lines 319-334), but when color=False and console=False, no handler is created at all (lines 336-348). This asymmetry means the console parameter is only respected when color=False. Consider checking the console parameter in the color is not False branch as well, or documenting this behavior clearly.
| logger.info("agent-lightning is ready!") | ||
| ``` | ||
| """ | ||
| warnings.warn("This function is deprecated in favor of `setup_logging`.", DeprecationWarning, stacklevel=2) |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecation warning message is incorrect. It states "This function is deprecated in favor of setup_logging" but the function itself is setup_logging. Based on the context, this should likely reference the new setup() function instead.
| warnings.warn("This function is deprecated in favor of `setup_logging`.", DeprecationWarning, stacklevel=2) | |
| warnings.warn("This function is deprecated in favor of `setup()`.", DeprecationWarning, stacklevel=2) |
agentlightning/logging.py
Outdated
| !!! danger | ||
|
|
||
| This function is deprecated in favor of `[agentlightning.setup_logging][agentlightning.setup_logging]`. |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring states this function is deprecated in favor of [agentlightning.setup_logging][agentlightning.setup_logging], but the function itself is named setup_logging. This creates a circular reference. Based on the refactoring, this should likely reference setup() instead.
| from .litagent import * | ||
| from .llm_proxy import * | ||
| from .logging import * | ||
| from .logging import setup as setup_logging # type: ignore |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 14 imports setup_logging with a comment indicating it's deprecated, but line 12 also exports __all__ = ["setup_logging"]. This is confusing because:
- Line 13 imports
setupand aliases it assetup_logging - Line 14 imports
setup_logging(marked as deprecated) - This creates a naming conflict where
setup_loggingrefers to both the newsetupfunction and the deprecatedsetup_loggingfunction
The second import on line 14 will overwrite the alias from line 13. This appears to be a bug in the export logic.
| from .logging import setup as setup_logging # type: ignore | |
| # from .logging import setup as setup_logging # type: ignore |
agentlightning/logging.py
Outdated
|
|
||
| # Choose formatter / handler definition | ||
| if color is not False: | ||
| fmt_name = "rich" |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable fmt_name is not used.
| fmt_name = "rich" |
| Runs in a separate process using spawn. It performs a specific logging | ||
| configuration scenario and returns a summary dict via the queue. | ||
| """ | ||
| import logging |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import of module logging is redundant, as it was previously imported on line 4.
| Runs in a separate spawned process and configures logging with a single | ||
| files=str path. Returns information about the attached FileHandler. | ||
| """ | ||
| import logging |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import of module logging is redundant, as it was previously imported on line 4.
| import logging |
| Runs in a separate spawned process and configures logging with a files=dict | ||
| mapping, then calls setup twice to verify idempotent FileHandler attachment. | ||
| """ | ||
| import logging |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import of module logging is redundant, as it was previously imported on line 4.
| import logging |
|
/ci |
|
🚀 CI Watcher for correlation id-3527573709-mhxej3ss triggered by comment 3527573709
✅ All runs completed. |
|
/ci |
|
🚀 CI Watcher for correlation id-3527885453-mhxhceoc triggered by comment 3527885453
✅ All runs completed. |
|
/ci |
|
🚀 CI Watcher for correlation id-3527997190-mhxi70jp triggered by comment 3527997190
✅ All runs completed. |
No description provided.