topology.logging
¶
Logging module for the Topology Modular Framework.
Classes¶
BaseLogger
: Base class for Topology logger classes.FileLogger
: Subclass of BaseLogger that adds a PexpectFileHandler.PexpectLogger
: Special subclass that implements a logger to be used with PexpectPexpectLoggerRead
: Undocumented.PexpectLoggerSend
: Undocumented.ConnectionLogger
: Logger for shell connections.LoggingManager
: Defines an object that manage and create loggers for Topology components.
-
class
topology.logging.
BaseLogger
(nameparts, propagate=False, level=0, log_dir=None, *args, **kwargs)¶ Base class for Topology logger classes.
Parameters: Object read-only properties:
Variables: - nameparts (OrderedDict) –
Namespaced name of the logger. For example:
OrderedDict([ 'context': 'test_bar', 'category': 'core', 'name': 'mylogger' ])
- name (str) –
Name of this logger as concatenated nameparts. For example:
test_bar.core.mylogger
Object read-write properties:
Variables: Inheritance
- nameparts (OrderedDict) –
-
class
topology.logging.
FileLogger
(*args, **kwargs)¶ Subclass of BaseLogger that adds a PexpectFileHandler.
This class implements additional logic for when the
log_dir
path is changed. It will create a file with the name of the logger under thelog_dir
with the.log
extension.Parameters: file_formatter (str) – Format to use in the PexpectFileHandler, defaulting to logging.BASIC_FORMAT
.Inheritance
-
class
topology.logging.
PexpectLogger
(*args, **kwargs)¶ Special subclass that implements a logger to be used with Pexpect
logfile
keyword argument.Purpose: to log every character in the pexpect session.
Pexpect
logfile
is expected to be an open file-like object, so this class implements thewrite()
andflush()
operations for effective duck-typing.To implement one logging per
flush()
this class implements a local buffer.Pexpect loggers can be located with the name:
<context>.pexpect.<node_identifier>.<shell_name>.<connection>
Where
<context>
is optional if running interactively or if the context in the LoggerManager has not been set.Parameters: - encoding (str) – Encoding to log into. The
write()
interface expect bytes, so in order to log in plain text it is required to perform a decoding. Defaults toutf-8
. - errors (str) – Handling of decoding errors. The
write()
interface may find undecodeable characters when decoding with the selected encoding, so the handling of errors needs to be defined. The values available are the same ones that thedecode
method of a bytes object expects in itserror
keyword argument. Defaults toignore
.
Inheritance
- encoding (str) – Encoding to log into. The
-
class
topology.logging.
PexpectLoggerRead
(*args, **kwargs)¶ Inheritance
-
class
topology.logging.
PexpectLoggerSend
(*args, **kwargs)¶ Inheritance
-
class
topology.logging.
ConnectionLogger
(*args, **kwargs)¶ Logger for shell connections.
Purpose: to log every
send_command
andget_response
in a low-level connection.Connection loggers can be located with the name:
<context>.pexpect.<node_identifier>.<shell_name>.<connection>
Where
<context>
is optional if running interactively or if the context in the LoggerManager has not been set.Inheritance
-
class
topology.logging.
LoggingManager
(default_level=20, default_propagate=False)¶ Defines an object that manage and create loggers for Topology components.
Only an instance of this class is to be created, this instance exists in this module and is to be used by other components by importing its
get_logger
method straigth from this module.This method will return a logger tailored for each of these categories, if those loggers are implemented:
- core
- library
- platform
- user
- node
- shell
- connection
- pexpect
- service
- step
Read-only properties:
Variables: categories – A list of available logging categories. Read-write properties:
Variables: Inheritance
-
get_logger
(name, category='core', *args, **kwargs)¶ Get a logger tailored for the given category.
Parameters: Returns: A new logger instance of the given category.
Return type:
-
set_category_level
(category, level)¶ Set the logging level property to all logger in the given category.
Parameters:
Variables¶
-
topology.logging.
LEVELS
¶ Simple map with the default logging levels.
OrderedDict([('NOTSET', 0), ('DEBUG', 10), ('INFO', 20), ('WARNING', 30), ('ERROR', 40), ('CRITICAL', 50)])
-
topology.logging.
manager
¶ Main framework wide instance of :class:LoggingManager.
<topology.logging.LoggingManager object at 0x7fd8ca298470>
-
topology.logging.
get_logger
¶ Get a logger tailored for the given category.
Parameters: Returns: A new logger instance of the given category.
Return type: <bound method LoggingManager.get_logger of <topology.logging.LoggingManager object at 0x7fd8ca298470>>