Personal utility library for Python projects.
uv add git+https://github.com/shimarch/pylibs.gitpip install git+https://github.com/shimarch/pylibs.gitGit dependencies are heavily cached by uv. Use the following commands to ensure you get the latest version:
uv cache clean
uv syncpip install --upgrade git+https://github.com/shimarch/pylibs.gitstructured_logger- Structured logging with emoji and context supportsecret_core- Secret management with pluggable storage backendsgoogle_chat_client- Google Chat API client for webhook-based messaginggoogle_sheet_client- Google Sheets API client
Global singleton context for managing the application logger.
Methods:
-
initialize(logger: StructuredLogger | None = None) -> StructuredLogger- Initialize the global logger
- Args:
logger: Optional logger instance. If None, creates a default logger.
- Returns: The initialized logger instance
-
get_logger() -> StructuredLogger- Get the logger instance
- Returns: The logger instance
- Raises:
RuntimeErrorif logger is not initialized
-
is_initialized() -> bool- Check if logger is initialized
- Returns: True if logger is initialized, False otherwise
-
reset() -> None- Reset the logger instance
- This clears the current logger instance, allowing it to be reinitialized
- Useful for testing or when you need to reconfigure the logger
Example:
from smrlib.structured_logger import LoggerContext
# Initialize logger
LoggerContext.initialize()
# Use logger in any module
class MyClass:
def __init__(self):
self.logger = LoggerContext.get_logger()
def do_something(self):
self.logger.info("Task started", {"id": 123})
self.logger.success("Task completed")
# Reset logger (e.g., for testing)
LoggerContext.reset()