feat(logging): Implement centralized logging with loguru#81
feat(logging): Implement centralized logging with loguru#81briansumma wants to merge 1 commit intoNorthShoreAutomation:mainfrom
Conversation
Add centralized logger configuration in _logger.py that: - Configures loguru as the logging system for the entire codebase - Removes default handlers and configures a stderr handler - Respects LOGURU_LEVEL environment variable with default level "INFO" - Standardizes logging across modules Replace print statements with structured logging in the Spec class: - Log request URLs at debug level with proper formatting - Log response data at debug level for successful requests - Update imports in affected modules to use the central logger Tests: - Added test_logger.py to verify core logger configuration - Added test_base_spec_logging.py to test logging in Spec base class - Added test_imports.py to verify correct logger imports - Added test_logger_integration.py for end-to-end tests This change improves debugging capabilities and provides a consistent approach to logging throughout the codebase.
| # try to populate the model | ||
| if response.ok: | ||
| print(response.text) | ||
| logger.debug(response.text) |
There was a problem hiding this comment.
thanks for doing this, we need to get rid of the noise in pythonik...
| @@ -0,0 +1,18 @@ | |||
| import sys | |||
There was a problem hiding this comment.
Thanks for taking a swing at this, id prefer though if we followed loguru's suggested way of doing things here:
https://github.com/Delgan/loguru?tab=readme-ov-file#suitable-for-scripts-and-libraries
If i understand that doc, we'd disable our library logs by default and allow the user to opt in to enabling it
|
The logger from pythonik._logger should match the same behavior as the logger from loguru but instead of the default level being DEBUG, it is INFO. You can still change the log level in the environment like you do the default logger, e.g., I think the only change would be to import the logger from pythonik/_logger.py instead of directly from loguru, i.e., from pythonik._logger import logger
config = {
"handlers": [
{"sink": sys.stdout, "format": "{time} - {message}"},
{"sink": "file.log", "serialize": True},
],
"extra": {"user": "someone"}
}
logger.configure(**config)
... |
Centralized Logging Implementation
This PR introduces a centralized logging system for the Pythonik SDK using the loguru library.
Changes
New Module:
_logger.pyLOGURU_LEVELenvironment variable with "INFO" as defaultUpdates to Base Classes
Spec.parse_responseandSpec.send_requestImport Standardization
Comprehensive Test Suite
Benefits
Testing
All tests pass as shown in the attached pytest logs. The implementation has been thoroughly tested for both functionality and edge cases.
Usage Examples
Configure log level via environment variable:
Default level is INFO, which keeps output clean while still showing important information.
Notes for Reviewers