Ezpl¶
Main singleton class for logging management.
Overview¶
The Ezpl class is the main entry point for the ezpl logging framework. It implements the singleton pattern with thread-safe double-checked locking to ensure only one instance exists across the application.
Class Reference¶
Ezpl
¶
Main logging singleton for the Ezpl framework.
Ezpl provides a unified, thread-safe interface for console and file logging with advanced features including indentation management, pattern-based logging, and dynamic progress bars. It implements the Singleton pattern to ensure only one instance exists throughout the application lifecycle.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_instance |
The singleton instance of Ezpl
TYPE:
|
_lock |
Thread lock for synchronized access
TYPE:
|
_config_locked |
Whether configuration can be modified
TYPE:
|
_log_file |
Path to the log file
TYPE:
|
_printer |
Console output handler
TYPE:
|
_logger |
File logging handler
TYPE:
|
_config_manager |
Configuration manager instance
TYPE:
|
Note
Once initialized, Ezpl cannot be re-configured unless reset. Access it via the singleton pattern or module-level functions.
Example
log = Ezpl() log.printer.log("INFO", "Application started") log.logger.log("INFO", "Starting logging to file")
Attributes¶
Functions¶
is_initialized
classmethod
¶
Return True if the Ezpl singleton has already been created.
Useful for libraries that want to know whether they are the first to initialize Ezpl or if they should avoid re-configuring it.
Source code in src/ezpl/ezpl.py
get_printer
¶
get_printer() -> EzPrinter
Returns the EzPrinter instance.
Returns:
* EzPrinter: The console printer instance providing info(), debug(), success(), etc.
Implements PrinterProtocol for type safety.
Source code in src/ezpl/ezpl.py
get_logger
¶
get_logger() -> EzLogger
Returns the EzLogger instance.
Returns:
* EzLogger: The file logger instance for file logging.
Use logger.info(), logger.debug(), etc. directly.
For advanced loguru features, use logger.get_loguru()
Implements LoggerProtocol for type safety.
Source code in src/ezpl/ezpl.py
set_level
¶
set_level(level: str, *, force: bool = False, owner: str | None = None, token: str | None = None) -> None
Set the log level for both the printer and the logger simultaneously (compatibility method).
Args:
* `level` (str): The desired log level (e.g., "INFO", "WARNING").
* `force` (bool): If True, bypasses the configuration lock.
Returns:
* `None`.
Source code in src/ezpl/ezpl.py
set_printer_level
¶
set_printer_level(level: str, *, force: bool = False, owner: str | None = None, token: str | None = None) -> None
Set the log level for the printer only.
Args:
* `level` (str): The desired log level for the printer.
* `force` (bool): If True, bypasses the configuration lock.
Returns:
* `None`.
Source code in src/ezpl/ezpl.py
set_logger_level
¶
set_logger_level(level: str, *, force: bool = False, owner: str | None = None, token: str | None = None) -> None
Set the log level for the file logger only.
Args:
* `level` (str): The desired log level for the file logger.
* `force` (bool): If True, bypasses the configuration lock.
Returns:
* `None`.
Source code in src/ezpl/ezpl.py
add_separator
¶
manage_indent
¶
Context manager to manage indentation level.
Returns:
* `None`.
reset
classmethod
¶
Reset the singleton instance (useful for testing).
Warning: This will destroy the current instance and all its state.
Source code in src/ezpl/ezpl.py
lock_config
classmethod
¶
Lock Ezpl configuration so that future configure() calls are ignored unless explicitly forced.
Intended usage
- Root application configures Ezpl once
- Calls Ezpl.lock_config()
- Libraries calling configure() later will not override settings
Source code in src/ezpl/ezpl.py
unlock_config
classmethod
¶
Unlock Ezpl configuration.
Use with care: this allows configure() to change global logging configuration again.
Source code in src/ezpl/ezpl.py
config_lock_info
classmethod
¶
Return current configuration lock state for diagnostics.
Source code in src/ezpl/ezpl.py
set_log_file
¶
Change the log file (requires reinitialization of the logger).
| PARAMETER | DESCRIPTION |
|---|---|
log_file
|
New path to the log file
TYPE:
|
Note: This will reinitialize the file logger but keep the singleton instance.
Source code in src/ezpl/ezpl.py
get_log_file
¶
get_config
¶
get_config() -> ConfigurationManager
Get the current configuration manager.
| RETURNS | DESCRIPTION |
|---|---|
ConfigurationManager
|
ConfigurationManager instance for accessing and modifying configuration |
set_printer_class
¶
Replace the current printer with a custom printer class or instance.
Allows users to override the default printer with a custom class that inherits from EzPrinter. The method preserves current configuration values (level, indentation settings) unless explicitly overridden in init_kwargs.
| PARAMETER | DESCRIPTION |
|---|---|
printer_class
|
Custom printer class inheriting from EzPrinter, or an already instantiated EzPrinter instance |
**init_kwargs
|
Optional initialization parameters for the printer class. If not provided, current configuration values are used.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If printer_class is not a valid class or instance |
ValidationError
|
If initialization parameters are invalid |
Example
from ezpl import Ezpl, EzPrinter
class CustomPrinter(EzPrinter): ... def info(self, message): ... super().info(f"[CUSTOM] {message}")
ezpl = Ezpl() ezpl.set_printer_class(CustomPrinter, level="DEBUG") ezpl.get_printer().info("Test") [CUSTOM] Test
Source code in src/ezpl/ezpl.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | |
set_logger_class
¶
Replace the current logger with a custom logger class or instance.
Allows users to override the default logger with a custom class that inherits from EzLogger. The method preserves current configuration values (level, rotation, retention, compression) unless explicitly overridden in init_kwargs.
| PARAMETER | DESCRIPTION |
|---|---|
logger_class
|
Custom logger class inheriting from EzLogger, or an already instantiated EzLogger instance |
**init_kwargs
|
Optional initialization parameters for the logger class. If not provided, current configuration values are used.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If logger_class is not a valid class or instance |
ValidationError
|
If initialization parameters are invalid |
FileOperationError
|
If file operations fail during logger creation (may be raised by the logger class constructor) |
Example
from ezpl import Ezpl, EzLogger
class CustomLogger(EzLogger): ... def info(self, message): ... super().info(f"[CUSTOM LOG] {message}")
ezpl = Ezpl() ezpl.set_logger_class(CustomLogger, log_file="custom.log") ezpl.get_logger().info("Test")
Source code in src/ezpl/ezpl.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 | |
reload_config
¶
Reload configuration from file and environment variables.
This method reloads the configuration and reapplies it to handlers. Useful when environment variables or the config file have changed after the singleton was initialized.
Note: This will reinitialize handlers with the new configuration.
Source code in src/ezpl/ezpl.py
configure
¶
Configure Ezpl dynamically.
| PARAMETER | DESCRIPTION |
|---|---|
config_dict
|
Dictionary of configuration values to update
TYPE:
|
**kwargs
|
Configuration options (alternative to config_dict): - log_file or log-file: Path to log file - printer_level or printer-level: Printer log level - logger_level or file-logger-level: File logger level - level or log-level: Set both printer and logger level - log_rotation or log-rotation: Rotation setting (e.g., "10 MB", "1 day") - log_retention or log-retention: Retention period (e.g., "7 days") - log_compression or log-compression: Compression format (e.g., "zip", "gz") - indent_step or indent-step: Indentation step size - indent_symbol or indent-symbol: Symbol for indentation - base_indent_symbol or base-indent-symbol: Base indentation symbol
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if configuration was applied, False if it was blocked by lock. |
Note: Changes are persisted to the configuration file.
Source code in src/ezpl/ezpl.py
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 | |