get_rich_logger
Package for creating a rich logger.
get_rich_logger(level='NOTSET', name=None, log_format='%(message)s', traceback_show_locals=False, traceback_hide_dunder_sunder_locals=True, traceback_extra_lines=10, traceback_suppressed_modules=(), **logging_basic_config_extra_kwargs)
¶
Substitute for logging.getLogger(), but pre-configured as rich logger with rich traceback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level |
Literal['NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | Literal[0, 10, 20, 30, 40, 50]
|
The logging level to use. |
'NOTSET'
|
name |
str
|
The name of the logger. Recommended to use |
None
|
log_format |
str
|
The format string to use for the rich logger. |
'%(message)s'
|
traceback_show_locals |
bool
|
Whether to show local variables in tracebacks. |
False
|
traceback_hide_dunder_sunder_locals |
bool
|
Whether to hide dunder and sunder variables in tracebacks. Only applicable to unhandled errors. |
True
|
traceback_extra_lines |
int
|
The number of extra lines to show in tracebacks. |
10
|
traceback_suppressed_modules |
Iterable[ModuleType]
|
The modules to suppress in tracebacks (e.g., pandas). |
()
|
logging_basic_config_extra_kwargs |
Unpack[LoggingBasicConfigExtraKwargs]
|
Extra keyword arguments to pass to logging.basicConfig(). |
{}
|
Returns:
| Type | Description |
|---|---|
Logger
|
The configured rich logger. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If additional_handlers is not a logging.Handler, Iterable[logging.Handler], or None. |
Examples:
- Logs will be colored and formatted with rich.
- Unhandled errors will have rich traceback.
Source code in src\get_rich_logger\_logger.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |