log
log
¶
Module configures the logger to log messages. It has a logger object that sends messages to different logging handlers (file and stream), a few classes for formatters.
Constants:
LOGGER: logging.Logger The logger object for sending messages to logging handlers. VERBOSITY_MAP: dict A dictionary mapping the verbosity level to the corresponding logging level. LOG_ENCODING: str The encoding type of the log file.
Functions:
def configure_logger( *, verbosity: int, logger_name: str, use_rich: bool, log_dir: Path | None = None, auto_rollover_sec: int = 24 * 60 * 60, max_log_files: int = 10, ) -> None: Configures the logger and creates logging handlers for file and stream. It takes the following parameters: * verbosity (int): The verbosity level of the logging messages. Must be an integer from 0 to 3. Default is 0. * logger_name (str): The name of the logger. Default is an empty string. * use_rich (bool): A flag to indicate whether to use the rich library to create a colorful log. Default is False. * log_dir (Path | None): The path to the directory where log files will be created. Default is the current working directory. * auto_rollover_sec (int): The time interval in seconds before rolling over the log file. Default is 86400 seconds (24 hours). * max_log_files (int): The maximum number of log files to keep. Default is 10.
Classes:
MarkupStripFormatter(logging.Formatter) A class to remove all formatting from the logging messages and return the plain text.
Functions:
Name | Description |
---|---|
* format |
|
NoHighlightRichHandler |
A subclass of RichHandler to remove all rich formatting from the logging messages. |
MarkupStripFormatter
¶
Bases: Formatter
A logging formatter that strips rich
markup tags from log messages before they
are emitted.
Attributes:
Name | Type | Description |
---|---|---|
None |
|
Methods:
Name | Description |
---|---|
format |
Return a formatted and stripped version of the log message. |
Source code in cssfinder/log.py
format
¶
Return the formatted string of a log record after stripping all formatting tags.
extended_summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
LogRecord
|
The log record to be formatted. |
required |
Returns:
Type | Description |
---|---|
str
|
The formatted string with all formatting tags removed. |
Source code in cssfinder/log.py
NoHighlightRichHandler
¶
Bases: RichHandler
RichHandler subclass which permanently disables message highlighting (coloring of integers, strings, etc.).
Source code in cssfinder/log.py
configure_logger
¶
configure_logger(
*,
verbosity: int,
logger_name: str,
use_rich: bool,
log_dir: Path | None = None,
auto_rollover_sec: int = 24 * 60 * 60,
max_log_files: int = 10
) -> None
Configure a logger with a file handler and a console handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
verbosity |
int
|
The verbosity level for the console handler. The value should be between 0 and 3, with 0 being the least verbose and 3 being the most verbose. |
required |
logger_name |
str
|
The name of the logger. |
required |
use_rich |
bool
|
A flag indicating whether to use the rich console handler. If True, use the rich console handler; otherwise, use the standard console handler. |
required |
log_dir |
str or Path or None
|
The path to the directory where log files should be stored. If None, store the log files in the current working directory. The default is None. |
None
|
auto_rollover_sec |
int
|
The number of seconds after which to rollover the log file. The default is 24 * 60 * 60. |
24 * 60 * 60
|
max_log_files |
int
|
The maximum number of log files to keep. The default is 10. |
10
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in cssfinder/log.py
enable_performance_logging
¶
Enable run time measurement and logging for run_project() function.