Logging¶
Class Description¶
-
class
log.loggersetup.ColoredFormatter(fmt: str='', use_color: bool=True)¶ Formatter instances are used to convert a LogRecord to text with color highlighting.
-
format(record) → object¶ Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
:param record :return: object
-
-
class
log.loggersetup.LoggerSetup¶ LoggerSetup class to log messages in a log file and on the console and SyslogHandler of the system
USE: import logging from log.loggersetup import LoggerSetup
LoggerSetup.setup()
logging.info(‘INFO-MSG’) logging.debug(‘DEBUG-MSG’) logging.warning(‘WARNING-MSG’) logging.error(‘ERROR-MSG’) logging.critical(‘CRITICAL-MSG’)
message with log level deep: logging.info(“%sInfo deep 2”, LoggerSetup.get_log_deep(2))
logging.Level order: 0 < 10 < 20 < 30 < 40 < 50 NOTSET < DEBUG < INFO < WARNING < ERROR < CRITICAL
LoggerSetup.close()
-
static
add_handler(stream_path: str='') → bool¶ Add new console output to logger handlers.
:param stream_path Path of the stream :return: ‘True’ if handler is successfully added
-
static
create_file_handler(log_file_path: str='') → logging.Handler¶ Create a FileHandler.
Parameters: log_file_path – Path from the file Returns: FileHandler
-
static
create_stream_handler(stream_path: str='') → logging.Handler¶ Create a StreamHandler.
Parameters: stream_path – Path of the stream Returns: StreamHandler
-
static
create_syslog_handler() → logging.Handler¶ Create a SyslogHandler.
Returns: SyslogHandler
-
static
get_log_deep(deep: int=0, deep_char: <built-in function chr>='\t') → str¶ Return an string with tabulators. Count of tabulators are depend on log_level. log_level = 0 returns empty string.
Parameters: - deep – deep of the level mode
- deep_char – the character to show the deep
Returns: String with tabulators
-
static
is_setup_loaded() → bool¶ Check if the logger has run the setup routine.
Returns: ‘True’ if logger is loaded
-
static
register_multiprocess_handlers(logger: <module 'logging' from '/usr/lib/python3.4/logging/__init__.py'>=None)¶ Wraps the handlers in the given Logger with an MultiProcessingHandler.
Parameters: logger – whose handlers to wrap. By default, the root logger.
-
static
setup(log_level: int=10, log_file_path: str='logger.log', log_format: str='', max_log_deep: int=5, log_filter: logging.Filter=None)¶ Create and initialize a new logging.Logger and create a new file and stream handler with the params.
Parameters: - log_level – Logging level
- log_file_path – Path for the log file
- log_format – Formatter for the output
- max_log_deep – Define the max level, how deep goes a detail of a log
- log_filter – filter for filter the log output
-
static
shutdown()¶ Close open streams and handlers.
-
static
un_register_multiprocess_handlers(logger: <module 'logging' from '/usr/lib/python3.4/logging/__init__.py'>=None)¶ Un register the multiprocess handler.
Parameters: logger – logging.logger
-
static