pypeec.log

Module for handling the logging.
  • Use a global timer to measure the elapsed time.

  • Provide a class for timing (and logging) code blocks.

  • Measure duration with local timers.

  • Log exceptions.

class pypeec.log.BlockTimer(logger, name, level='INFO')
Class for timing a block of code.
  • Uses enter and exit magic methods.

  • Display the results with a logger.

Parameters:
  • logger (logger) – Logger object instance.

  • name (string) – Name of the code block.

  • level (string) – Logging level to be used.

class pypeec.log.BlockIndent
Class for indenting a block of code.
  • Uses enter and exit magic methods.

  • Display the results with a logger.

pypeec.log.log_exception(logger, ex, level='ERROR')
Log an exception.
  • Log the exception type, message, and trace.

  • Remove the context from the exception before the logging.

Parameters:
  • logger (logger) – Logger object instance.

  • ex (exception) – Exception to be logged.

  • level (string) – Logging level to be used.

pypeec.log.get_timer()

Get a timestamp with the current time.

Returns:

timestamp – Timestamp with the current time.

Return type:

timestamp

pypeec.log.get_duration(timestamp)

Get the elapsed time with respect to a timestamp.

Parameters:

timestamp (timestamp) – Timestamp with the reference time.

Returns:

  • seconds (float) – Float with the elapsed time in seconds.

  • duration (string) – String with the formatted elapsed time.

  • date (string) – String with the formatted initial timestamp.

pypeec.log.set_global(timestamp, level)
Set the global variables.
  • timestamp (for the elapsed time)

  • indentation level (for log messages)

Parameters:
  • timestamp (timestamp) – Timestamp (for the elapsed time).

  • level (integer) – Indentation level for the log messages.

pypeec.log.get_global()
Get the global variables.
  • timestamp (for the elapsed time)

  • indentation level (for log messages)

Returns:

  • timestamp (timestamp) – Timestamp (for the elapsed time).

  • level (integer) – Indentation level for the log messages.

pypeec.log.get_logger(name)

Get a logger with a specified name.

Parameters:

name (string) – Name of the logger to be returned. If the logger does not exist, the logger is created. If the logger does exist, the logger is returned.

Returns:

logger – Logger object instance.

Return type:

logger