Log handlers
File: base/log/log_handlers.py
This file implements two log handlers: - FileLogHandler: Writes log messages to a file. - ConsoleLogHandler: Writes log messages to the console with color formatting.
Classes:
-
ILogHandler
–Abstract base class for log handlers.
-
FileLogHandler
–Log handler that writes log messages to a file.
-
ConsoleLogHandler
–Log handler that writes log messages to the console.
ILogHandler
Bases: ABC
Abstract base class for log handlers.
Methods:
Source code in kern_comm_lib/base/log/log_handlers.py
handle
abstractmethod
Handles a log message.
Parameters:
-
severity
(LogSeverity
) –The severity level of the log message.
-
message
(str
) –The log message to be handled.
Returns:
-
Status
–A Status object indicating success or failure of the operation.
Source code in kern_comm_lib/base/log/log_handlers.py
close
Closes the log handler.
This method should be overridden by subclasses to implement any necessary cleanup operations when the handler is no longer needed.
FileLogHandler
Bases: ILogHandler
Log handler that writes log messages to a file.
Attributes:
-
file_path
(str
) –The path to the log file.
-
_mutex
(IMutex
) –A lock to ensure thread-safe file access.
-
file
–The file object for the log file.
Methods:
-
__init__
–Initializes a FileLogHandler instance.
-
handle
–Writes a log message to the file.
-
close
–Closes the log file.
Source code in kern_comm_lib/base/log/log_handlers.py
__init__
Initializes a FileLogHandler instance.
Parameters:
-
file_path
(str
) –The path to the log file.
Source code in kern_comm_lib/base/log/log_handlers.py
handle
Writes a log message to the file.
Parameters:
-
severity
(LogSeverity
) –The severity level of the log message.
-
message
(str
) –The log message to be written.
Returns:
-
Status
–A Status object indicating success or failure of the operation.
Source code in kern_comm_lib/base/log/log_handlers.py
close
Closes the log file.
Ensures that the file is properly closed, even if an exception occurs.
Source code in kern_comm_lib/base/log/log_handlers.py
ConsoleLogHandler
Bases: ILogHandler
Log handler that writes log messages to the console.
Attributes:
-
_mutex
(IMutex
) –A lock to ensure thread-safe console access.
Methods:
Source code in kern_comm_lib/base/log/log_handlers.py
__init__
Constructor.
Parameters:
-
format_pattern
(str | None
, default:None
) –Optional format string for log messages
Source code in kern_comm_lib/base/log/log_handlers.py
handle
Writes a log message to the console with color formatting.
Parameters:
-
severity
(LogSeverity
) –The severity level of the log message.
-
message
(str
) –The log message to be written.
Returns:
-
Status
–A Status object indicating success or failure of the operation.