topology.logging

Logging module for the Topology Modular Framework.

Classes

class topology.logging.BaseLogger(nameparts, propagate=False, level=0, log_dir=None, *args, **kwargs)

Base class for Topology logger classes.

Parameters:
  • nameparts (OrderedDict) – Namespaced name of the logger.
  • propagate (bool) – Propagate messages to the root logger.
  • level (int) – Logging level as in Python’s logging framework. .. autodata:: topology.logging.LEVELS
  • log_dir (str) – Directory to store the logging file (if any, see subclasses).

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:
  • propagate (bool) – True if message propagation to the root logger is enabled.
  • level (int) – Current logging level for this logger.
  • log_dir – Current logging directory for this logger.

Inheritance

Inheritance diagram of BaseLogger

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 the log_dir with the .log extension.

Parameters:file_formatter (str) – Format to use in the PexpectFileHandler, defaulting to logging.BASIC_FORMAT.

Inheritance

Inheritance diagram of FileLogger

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 the write() and flush() 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 to utf-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 the decode method of a bytes object expects in its error keyword argument. Defaults to ignore.

Inheritance

Inheritance diagram of PexpectLogger

class topology.logging.PexpectLoggerRead(*args, **kwargs)

Inheritance

Inheritance diagram of PexpectLoggerRead

class topology.logging.PexpectLoggerSend(*args, **kwargs)

Inheritance

Inheritance diagram of PexpectLoggerSend

class topology.logging.ConnectionLogger(*args, **kwargs)

Logger for shell connections.

Purpose: to log every send_command and get_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

Inheritance diagram of ConnectionLogger

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:

  1. core
  2. library
  3. platform
  4. user
  5. node
  6. shell
  7. connection
  8. pexpect
  9. service
  10. step

Read-only properties:

Variables:categories – A list of available logging categories.

Read-write properties:

Variables:
  • logging_directory (str) – Framework wide logging directory. Any change on this setting will be notified to all loggers.
  • logging_context (str) – Current framework wide logging context.

Inheritance

Inheritance diagram of LoggingManager

get_logger(name, category='core', *args, **kwargs)

Get a logger tailored for the given category.

Parameters:
  • name (OrderedDict or str) – Full namespaced name or simple name.
  • category (str) – Category of the logger.
Returns:

A new logger instance of the given category.

Return type:

BaseLogger

set_category_level(category, level)

Set the logging level property to all logger in the given category.

Parameters:
  • category (str) – Name of the category.
  • level (int) – Value to set the level property.
set_category_propagate(category, propagate)

Set the propagate property to all logger in the given category.

Parameters:
  • category (str) – Name of the category.
  • propagate (bool) – Value of set the propagate property.

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:
  • name (OrderedDict or str) – Full namespaced name or simple name.
  • category (str) – Category of the logger.
Returns:

A new logger instance of the given category.

Return type:

BaseLogger

<bound method LoggingManager.get_logger of <topology.logging.LoggingManager object at 0x7fd8ca298470>>