YouTubeDownloader v1.1.2
YouTube content downloader
Loading...
Searching...
No Matches
Source.Util.colored_log Namespace Reference

Classes

class  ColorFormatter
 Logging formatter that colors logging messages depending on their level. More...
 

Functions

str get_format (bool line_no=False, bool threads=False)
 Get the configurable log format string.
 
None init_console_logging (int level, bool threads=False)
 Initializes logging for console output.
 

Variables

 log = logging.getLogger(__name__)
 
str S_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
 
str S_LOG_MSG_FORMAT_W_LINENO_W_THREADS = "%(asctime)s [%(name)s:%(lineno)d][%(threadName)s][%(levelname)s] %(message)s"
 
str S_LOG_MSG_FORMAT_W_LINENO_WO_THREADS = "%(asctime)s [%(name)s:%(lineno)d][%(levelname)s] %(message)s"
 
str S_LOG_MSG_FORMAT_WO_LINENO_W_THREADS = "%(asctime)s [%(name)s][%(threadName)s][%(levelname)s] %(message)s"
 
str S_LOG_MSG_FORMAT_WO_LINENO_WO_THREADS = "%(asctime)s [%(name)s][%(levelname)s] %(message)s"
 

Detailed Description


Function Documentation

◆ get_format()

str get_format ( bool line_no = False,
bool threads = False )

Get the configurable log format string.

Parameters
line_no: include line number in log string
threads: include thread name in log string
Returns
log format string

Definition at line 32 of file colored_log.py.

32def get_format(line_no: bool = False, threads: bool = False) -> str:
33 """!
34 @brief Get the configurable log format string
35 @param line_no : include line number in log string
36 @param threads : include thread name in log string
37 @return log format string
38 """
39 if not line_no and not threads:
40 msg_format = S_LOG_MSG_FORMAT_WO_LINENO_WO_THREADS
41 elif not line_no and threads:
42 msg_format = S_LOG_MSG_FORMAT_WO_LINENO_W_THREADS
43 elif line_no and not threads:
44 msg_format = S_LOG_MSG_FORMAT_W_LINENO_WO_THREADS
45 elif line_no and threads:
46 msg_format = S_LOG_MSG_FORMAT_W_LINENO_W_THREADS
47 else:
48 raise ValueError("No valid format found")
49 return msg_format
50
51

◆ init_console_logging()

None init_console_logging ( int level,
bool threads = False )

Initializes logging for console output.

Line numbers are active in DEBUG level or lower.

Parameters
level: root log level
threads: include thread names in log strings

Definition at line 52 of file colored_log.py.

52def init_console_logging(level: int, threads: bool = False) -> None:
53 """!
54 @brief Initializes logging for console output.
55 Line numbers are active in DEBUG level or lower.
56 @param level : root log level
57 @param threads : include thread names in log strings
58 """
59 root_logger = logging.getLogger()
60 root_logger.setLevel(level)
61 stream_handler = logging.StreamHandler()
62 line_no = bool(level == logging.DEBUG)
63 date_format = S_LOG_DATE_FORMAT if (level != logging.DEBUG) else None
64 stream_handler.setFormatter(ColorFormatter(line_no=line_no, threads=threads, data_format=date_format))
65 root_logger.handlers.clear()
66 root_logger.addHandler(stream_handler)
67
68

Variable Documentation

◆ log

log = logging.getLogger(__name__)

Definition at line 118 of file colored_log.py.

◆ S_LOG_DATE_FORMAT

str S_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"

Definition at line 29 of file colored_log.py.

◆ S_LOG_MSG_FORMAT_W_LINENO_W_THREADS

str S_LOG_MSG_FORMAT_W_LINENO_W_THREADS = "%(asctime)s [%(name)s:%(lineno)d][%(threadName)s][%(levelname)s] %(message)s"

Definition at line 28 of file colored_log.py.

◆ S_LOG_MSG_FORMAT_W_LINENO_WO_THREADS

str S_LOG_MSG_FORMAT_W_LINENO_WO_THREADS = "%(asctime)s [%(name)s:%(lineno)d][%(levelname)s] %(message)s"

Definition at line 27 of file colored_log.py.

◆ S_LOG_MSG_FORMAT_WO_LINENO_W_THREADS

str S_LOG_MSG_FORMAT_WO_LINENO_W_THREADS = "%(asctime)s [%(name)s][%(threadName)s][%(levelname)s] %(message)s"

Definition at line 26 of file colored_log.py.

◆ S_LOG_MSG_FORMAT_WO_LINENO_WO_THREADS

str S_LOG_MSG_FORMAT_WO_LINENO_WO_THREADS = "%(asctime)s [%(name)s][%(levelname)s] %(message)s"

Definition at line 25 of file colored_log.py.