logger
Core logging module for pyRevit.
Attributes
LOG_REC_FORMAT = '%(levelname)s [%(name)s] %(message)s'
module-attribute
LOG_REC_FORMAT_HEADER = coreutils.prepare_html_str('<strong>%(levelname)s</strong> [%(name)s] %(message)s')
module-attribute
LOG_REC_FORMAT_HEADER_NO_NAME = coreutils.prepare_html_str('<strong>%(levelname)s</strong>\n%(message)s')
module-attribute
LOG_REC_FORMAT_EMOJI = '{emoji} %(levelname)s [%(name)s] %(message)s'
module-attribute
LOG_REC_FORMAT_FILE = '%(asctime)s %(levelname)s [%(name)s] %(message)s'
module-attribute
LOG_REC_FORMAT_FILE_C = '%(asctime)s %(levelname)s [<{}> %(name)s] %(message)s'
module-attribute
LOG_REC_FORMAT_HTML = coreutils.prepare_html_str('<div class="logdefault {style}">{message}</div>')
module-attribute
LOG_REC_CLASS_ERROR = 'logerror'
module-attribute
LOG_REC_FORMAT_ERROR = LOG_REC_FORMAT_HTML.format(style=LOG_REC_CLASS_ERROR, message=LOG_REC_FORMAT_HEADER)
module-attribute
LOG_REC_CLASS_WARNING = 'logwarning'
module-attribute
LOG_REC_FORMAT_WARNING = LOG_REC_FORMAT_HTML.format(style=LOG_REC_CLASS_WARNING, message=LOG_REC_FORMAT_HEADER)
module-attribute
LOG_REC_CLASS_CRITICAL = 'logcritical'
module-attribute
LOG_REC_FORMAT_CRITICAL = LOG_REC_FORMAT_HTML.format(style=LOG_REC_CLASS_CRITICAL, message=LOG_REC_FORMAT_HEADER)
module-attribute
LOG_REC_CLASS_SUCCESS = 'logsuccess'
module-attribute
LOG_REC_FORMAT_SUCCESS = LOG_REC_FORMAT_HTML.format(style=LOG_REC_CLASS_SUCCESS, message=LOG_REC_FORMAT_HEADER_NO_NAME)
module-attribute
LOG_REC_CLASS_DEPRECATE = 'logdeprecate'
module-attribute
LOG_REC_FORMAT_DEPRECATE = LOG_REC_FORMAT_HTML.format(style=LOG_REC_CLASS_DEPRECATE, message=LOG_REC_FORMAT_HEADER_NO_NAME)
module-attribute
DEFAULT_LOGGING_LEVEL = logging.WARNING
module-attribute
DEPRECATE_LOG_LEVEL = 25
module-attribute
SUCCESS_LOG_LEVEL = 80
module-attribute
FILE_LOG_FILENAME = '{}runtime.log'.format(PYREVIT_FILE_PREFIX_STAMPED)
module-attribute
FILE_LOG_FILEPATH = op.join(PYREVIT_VERSION_APP_DIR, FILE_LOG_FILENAME)
module-attribute
FILE_LOGGING_DEFAULT_STATE = False
module-attribute
stdout_hndlr = logging.StreamHandler(sys.stdout)
module-attribute
default_formatter = logging.Formatter(LOG_REC_FORMAT)
module-attribute
formatters = {SUCCESS_LOG_LEVEL: logging.Formatter(LOG_REC_FORMAT_SUCCESS), logging.ERROR: logging.Formatter(LOG_REC_FORMAT_ERROR), logging.WARNING: logging.Formatter(LOG_REC_FORMAT_WARNING), logging.CRITICAL: logging.Formatter(LOG_REC_FORMAT_CRITICAL), DEPRECATE_LOG_LEVEL: logging.Formatter(LOG_REC_FORMAT_DEPRECATE)}
module-attribute
file_hndlr = logging.FileHandler(FILE_LOG_FILEPATH, mode='a', delay=True)
module-attribute
file_formatter = logging.Formatter(LOG_REC_FORMAT_FILE)
module-attribute
loggers = {}
module-attribute
Classes
DispatchingFormatter(log_formatters, log_default_formatter)
Bases: object
Dispatching formatter to format by log level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log_formatters |
dict[int
|
logging.Formatter]): dict of level:formatter key pairs |
required |
log_default_formatter |
Formatter
|
default formatter |
required |
Source code in pyrevitlib/pyrevit/coreutils/logger.py
Functions
LoggerWrapper(*args)
Bases: Logger
Custom logging object.
Source code in pyrevitlib/pyrevit/coreutils/logger.py
Functions
callHandlers(record)
Override logging.Logger.callHandlers.
Source code in pyrevitlib/pyrevit/coreutils/logger.py
isEnabledFor(level)
Override logging.Logger.isEnabledFor.
Source code in pyrevitlib/pyrevit/coreutils/logger.py
is_enabled_for(level)
Check if logger is enabled for level in pyRevit environment.
Source code in pyrevitlib/pyrevit/coreutils/logger.py
has_errors()
set_level(level)
set_quiet_mode()
set_verbose_mode()
set_debug_mode()
reset_level()
get_level()
log_parse_except(parsed_file, parse_ex)
Logs a file parsing exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parsed_file |
str
|
File path that failed the parsing |
required |
parse_ex |
Exception
|
Parsing exception |
required |
Source code in pyrevitlib/pyrevit/coreutils/logger.py
success(message, *args, **kws)
Log a success message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
success message |
required |
*args |
Any
|
extra agruments passed to the log function |
()
|
**kws |
Any
|
extra agruments passed to the log function |
{}
|
Source code in pyrevitlib/pyrevit/coreutils/logger.py
deprecate(message, *args, **kws)
Log a deprecation message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
deprecation message |
required |
*args |
Any
|
extra agruments passed to the log function |
()
|
**kws |
Any
|
extra agruments passed to the log function |
{}
|
Source code in pyrevitlib/pyrevit/coreutils/logger.py
dev_log(source, message='')
Appends a message to a log file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
str
|
source of the message |
required |
message |
str
|
message to log |
''
|
Source code in pyrevitlib/pyrevit/coreutils/logger.py
Functions
get_stdout_hndlr()
Return stdout logging handler object.
Returns:
Type | Description |
---|---|
StreamHandler
|
configured instance of python's native stream handler |
Source code in pyrevitlib/pyrevit/coreutils/logger.py
get_file_hndlr()
Return file logging handler object.
Returns:
Type | Description |
---|---|
FileHandler
|
configured instance of python's native stream handler |
Source code in pyrevitlib/pyrevit/coreutils/logger.py
get_logger(logger_name)
Register and return a logger with given name.
Caches all registered loggers and returns the same logger object on second call with the same logger name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger_name |
str
|
logger name |
required |
Returns:
Type | Description |
---|---|
LoggerWrapper
|
logger object wrapper python's native logger |
Examples:
Source code in pyrevitlib/pyrevit/coreutils/logger.py
set_file_logging(status)
Set file logging status (enable/disable).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status |
bool
|
True to enable, False to disable |
required |
loggers_have_errors()
Check if any errors have been reported by any of registered loggers.