Logging¶
Utilities for setting up and managing logging.
LoggingMixin ¶
Mixin that provides a cached logger instance based on the class name.
enable_stdout_logging ¶
enable_stdout_logging()
Enable stdout logging for this instance's logger.
Source code in src/aibs_informatics_core/utils/logging.py
187 188 189 | |
log_stacktrace ¶
log_stacktrace(message, error)
Log an error message and its stack trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message to log. |
required |
error
|
BaseException
|
The exception to log. |
required |
Source code in src/aibs_informatics_core/utils/logging.py
177 178 179 180 181 182 183 184 185 | |
check_formatter_equality ¶
check_formatter_equality(this, other)
Check if two formatters are equivalent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
this
|
Formatter | None
|
First formatter (or None). |
required |
other
|
Formatter | None
|
Second formatter (or None). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both formatters have the same format and datefmt. |
Source code in src/aibs_informatics_core/utils/logging.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
check_handler_equality ¶
check_handler_equality(this, other)
Check if two handlers are equivalent.
Compares type, level, name, and formatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
this
|
Handler
|
First handler. |
required |
other
|
Handler
|
Second handler. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both handlers are equivalent. |
Source code in src/aibs_informatics_core/utils/logging.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
enable_stdout_logging ¶
enable_stdout_logging(
logger, format=DEFAULT_LOGGING_FORMAT, level="INFO"
)
Enable stdout logging for a logger if not already configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
StrOrLogger
|
Logger instance or name. |
required |
format
|
StrOrFormatter
|
Format string or existing Formatter instance. |
DEFAULT_LOGGING_FORMAT
|
level
|
LogLevel
|
Logging level for the handler. |
'INFO'
|
Returns:
| Type | Description |
|---|---|
Logger
|
The configured |
Source code in src/aibs_informatics_core/utils/logging.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
get_all_handlers ¶
get_all_handlers(logger)
Collect all handlers from a logger and its parent chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
The logger to inspect. |
required |
Returns:
| Type | Description |
|---|---|
list[Handler]
|
A list of all handlers attached to the logger and its ancestors. |
Source code in src/aibs_informatics_core/utils/logging.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
get_formatter
cached
¶
get_formatter(format=DEFAULT_LOGGING_FORMAT)
Get or create a cached log formatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
StrOrFormatter
|
Format string or existing Formatter instance. |
DEFAULT_LOGGING_FORMAT
|
Returns:
| Type | Description |
|---|---|
Formatter
|
A |
Source code in src/aibs_informatics_core/utils/logging.py
40 41 42 43 44 45 46 47 48 49 50 51 | |
get_logger ¶
get_logger(name=None)
Get a logger by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Logger name. If None, returns the root logger. |
None
|
Returns:
| Type | Description |
|---|---|
|
A |
Source code in src/aibs_informatics_core/utils/logging.py
28 29 30 31 32 33 34 35 36 37 | |
get_stdout_handler
cached
¶
get_stdout_handler(
format=DEFAULT_LOGGING_FORMAT, level="INFO"
)
Get or create a cached stdout stream handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
StrOrFormatter
|
Format string or existing Formatter instance. |
DEFAULT_LOGGING_FORMAT
|
level
|
LogLevel
|
Logging level for the handler. |
'INFO'
|
Returns:
| Type | Description |
|---|---|
StreamHandler
|
A |
Source code in src/aibs_informatics_core/utils/logging.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |