Logger
File: base/log/logger.py
This file implements the basic logger class that is used by the LOG functions.
Classes:
-
Logger
–A thread-safe logger class that manages log handlers and provides logging functionality.
Logger
A thread-safe logger class that manages log handlers and provides logging functionality.
Attributes:
-
_instance_mutex
–A mutex to ensure thread-safe access to the default logger instance.
-
_default_instance
(Optional[Logger]
) –The default logger instance, shared across threads.
-
_thread_local
–Thread-local storage for logger instances.
-
_handlers_registry
(dict[str, list[ILogHandler]]
) –A registry of handlers for each logger.
-
_registry_mutex
–A lock to ensure thread-safe access to the handler's registry.
Methods:
-
__init__
–Constructor.
-
add_handler
–Adds a log handler to the logger.
-
remove_handler
–Removes a log handler from the logger.
-
close_all_handlers
–Closes all log handlers.
-
log
–Logs a message with the specified severity level.
-
get_default
–Retrieves the default logger instance, creating it if necessary.
-
get_thread_logger
–Retrieves a thread-specific logger instance, creating it if necessary.
-
cleanup_thread_logger
–Cleans up the thread-local logger instance, removing it from the registry.
Source code in kern_comm_lib/base/log/logger.py
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
__init__
Constructor.
Parameters:
-
name
(default
, default:'default'
) –"default"): The name of the logger.
Source code in kern_comm_lib/base/log/logger.py
add_handler
Adds a log handler to the logger.
Parameters:
-
handler
(ILogHandler
) –The log handler to add.
Returns:
-
Status
–A Status object indicating success or failure.
Source code in kern_comm_lib/base/log/logger.py
remove_handler
Removes a log handler from the logger.
Parameters:
-
handler
(ILogHandler
) –The log handler to remove.
Returns:
-
Status
–A Status object indicating success or failure.
Source code in kern_comm_lib/base/log/logger.py
close_all_handlers
Closes all log handlers.
Returns:
-
Status
–A Status object indicating success or failure of the logging operation.
Source code in kern_comm_lib/base/log/logger.py
log
Logs a message with the specified severity level.
Parameters:
-
severity
(LogSeverity
) –The severity level of the log message.
-
message
(str
) –The log message to be recorded.
Returns:
-
Status
–A Status object indicating success or failure of the logging operation.
Source code in kern_comm_lib/base/log/logger.py
get_default
classmethod
Retrieves the default logger instance, creating it if necessary.
Returns:
-
Logger
–The default logger instance.
Source code in kern_comm_lib/base/log/logger.py
get_thread_logger
classmethod
Retrieves a thread-specific logger instance, creating it if necessary.
Parameters:
-
name
(default
, default:None
) –None): The name of the logger. If None, a name is generated based on the thread name.
Returns:
-
Logger
–The thread-specific logger instance.
Source code in kern_comm_lib/base/log/logger.py
cleanup_thread_logger
classmethod
Cleans up the thread-local logger instance, removing it from the registry.