Logging System¶
The module extended the builtin logging
module and provides
a coloured version of Logger
to better demonstrate
the logging information of darc
.
- class darc.logging.ColorFormatter(fmt=None, datefmt=None, style='%', validate=True)[source]¶
Bases:
logging.Formatter
Color formatter based on record levels.
- class darc.logging.DarcLogger(name, level=0)[source]¶
Bases:
logging.Logger
The tailored logger for
darc
module.- pexc(level=40, message=None, category=None, line=None, **kwargs)[source]¶
Log
msg % args
with severitylevel
.- Parameters
- Keyword Arguments
**kwargs – Arbitrary keyword arguments for log information.
- Return type
To pass exception information, use the keyword argument
exc_info
with a true value, e.g.logger.pexc("Houston, we have a thorny problem", type, exc_info=1)
See also
The method mocks the output of
warnings.warn()
for the log message.
- pline(level, msg, *args, **kwargs)[source]¶
Log
msg % args
with severitylevel
.- Parameters
- Keyword Arguments
**kwargs – Arbitrary keyword arguments for log information.
- Return type
To pass exception information, use the keyword argument
exc_info
with a true value, e.g.logger.pline(level, "Houston, we have a %s", "thorny problem", exc_info=1)
Note
The method replaces
formatter
withline_formatter
, which has not prefixing contents in the log line.
- plog(level, msg, *args, object, pprint=None, **kwargs)[source]¶
Log
msg % args
into a pretty-printed representation with severitylevel
.- Parameters
- Keyword Arguments
object – Object to be pretty printed.
pprint – Arbitrary arguments for
pprint.pformat()
.**kwargs – Arbitrary keyword arguments for log information.
- Return type
To pass exception information, use the keyword argument
exc_info
with a true value, e.g.logger.plog(level, "Houston, we have a %s", "thorny problem", object=object, exc_info=1)
See also
The method uses
pprint.pformat()
to format the targetobject
withpprint
arguments.
- ptb(msg, *args, level=50, **kwargs)[source]¶
Log
msg % args
with severitylevel
.- Parameters
- Keyword Arguments
level – Log severity level.
**kwargs – Arbitrary keyword arguments for log information.
- Return type
To pass exception information, use the keyword argument
exc_info
with a true value, e.g.logger.ptb(level, "Houston, we have a %s", "thorny problem", exc_info=1)
Note
The method logs the full traceback stack from
traceback.format_exc()
.
- verbose(msg, *args, **kwargs)[source]¶
Log
msg % args
with severityVERBOSE
.- Parameters
msg (
Any
) – Message to be logged.*args – Arbitrary positional arguments for interploration.
**kwargs – Arbitrary keyword arguments for log information.
args (Any) –
kwargs (Any) –
- Return type
To pass exception information, use the keyword argument
exc_info
with a true value, e.g.logger.verbose("Houston, we have a %s", "thorny problem", exc_info=1)
- Return type
- Parameters
msg (Any) –
args (Any) –
kwargs (Any) –
- property horizon: str¶
Horizon line.
See also
The property uses
shutil.get_terminal_size()
to calculate the desired length of the-
horizon line.- Return type
- darc.logging.render_message(message, *attr)[source]¶
Render message.
The function wraps the
stem.util.term.format()
function to provide multi-line formatting support.- Parameters
message (
AnyStr
) – Multi-line message to be rendered withcolour
.*attr – Formatting attributes of text, c.f.
stem.util.term
.attr (str) –
- Return type
- Returns
The rendered message.
See also
The message formatting is done by
stem.util.term.format()
with its various predefined formatting attributes.
- darc.logging.CRITICAL = 50¶
CRITICAL
logging level, c.f.,logging.CRITICAL
.
- darc.logging.DEBUG = 10¶
DEBUG
logging level, c.f.,logging.DEBUG
.
- darc.logging.ERROR = 40¶
ERROR
logging level, c.f.,logging.ERROR
.
- darc.logging.INFO = 20¶
INFO
logging level, c.f.,logging.INFO
.
- darc.logging.VERBOSE = 5¶
VERBOSE
logging level.
- darc.logging.WARNING = 30¶
WARNING
logging level, c.f.,logging.WARNING
.
- darc.logging._LOG_ATTR = {5: ('Blue',), 10: ('Cyan',), 20: ('Green',), 30: ('Yellow',), 40: ('Red',), 50: ('Bg Red', 'Highlight')}¶
Mapping of logging levels with corresponding color format.
- darc.logging.formatter = <darc.logging.ColorFormatter object>¶
Generic log formatter instance for
handler
.
- darc.logging.line_formatter = <darc.logging.ColorFormatter object>¶
Line-only log formmater instance for
pline()
.