diff --git a/examples/base.py b/examples/base.py index dc6b8c4..fd403ae 100644 --- a/examples/base.py +++ b/examples/base.py @@ -3,8 +3,6 @@ from logurich import global_context_configure, init_logger, logger -logger.info("This is a basic log message") - def create_rich_table(): table = Table(title="Sample Table") @@ -17,6 +15,8 @@ def create_rich_table(): if __name__ == "__main__": + init_logger("INFO") + logger.info("This is a basic log message") logger.info("Example message") logger.rich("INFO", "OK") logger.rich("INFO", {"fake": "test"}) diff --git a/src/logurich/__init__.py b/src/logurich/__init__.py index 6bc5afe..e198be5 100644 --- a/src/logurich/__init__.py +++ b/src/logurich/__init__.py @@ -20,8 +20,6 @@ propagate_loguru_to_std_logger, ) -init_logger("INFO") - __all__ = [ "init_logger", "logger", diff --git a/src/logurich/core.py b/src/logurich/core.py index 357221e..8226c5f 100644 --- a/src/logurich/core.py +++ b/src/logurich/core.py @@ -496,13 +496,16 @@ def init_logger( diagnose: bool = False, enqueue: bool = True, highlight: bool = False, + enable_all: bool = True, rotation: Optional[Union[str, int]] = "12:00", retention: Optional[Union[str, int]] = "10 days", ) -> Optional[str]: """Initialize and configure the logger with rich formatting and customized handlers. This function sets up a logging system using Loguru with optional Rich integration. - It configures console output and optionally file-based logging with rotation. + It configures console output and optionally file-based logging with rotation. Call + it early in your application's startup before any logging, since LoguRich does not + auto-initialize handlers. Args: log_level: The minimum logging level to display (e.g. "DEBUG", "INFO", "WARNING"). @@ -525,6 +528,8 @@ def init_logger( enqueue (bool, optional): Whether to use a queue for thread-safe logging. Defaults to True. highlight (bool, optional): Whether to highlight log messages. Defaults to False. + enable_all (bool, optional): Whether to enable logging for all modules. + Defaults to True. rotation (str or int or None, optional): When to rotate log files. Can be a time string (e.g. "12:00", "1 week"), size (e.g. "500 MB"), or None to disable rotation. Defaults to "12:00". @@ -540,6 +545,8 @@ def init_logger( >>> logger.info("Application started") >>> logger.debug("Debug information") # Won't be displayed with INFO level """ + if enable_all: + logger.enable("") if rich_handler is False: env_rich_handler = parse_bool_env("LOGURU_RICH") if env_rich_handler is not None: