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.
- The log config is defined by the following files.
First the default configuration is loaded (“pypeec/data/logger.ini”).
The logger configuration file is written as a Python ConfigParser INI file.
Afterward, a custom file can be loaded with an environment variable (“PYTHONLOGGER”).
Warning
This logging module is based on the Python logging module.
The philosophy of this logging module is slightly different.
Be careful if you are mixing both modules.
- class pypeec.log.BlockIndent(logger=None, name=None, level='INFO')
- Class for timing a block of code.
Uses enter and exit magic methods.
Display the name of the block.
Indent the results inside the block.
- Parameters:
logger (logger) – Logger object instance.
name (string) – Name of the code block.
level (string) – Logging level to be used.
- class pypeec.log.BlockTimer(logger=None, name=None, level='INFO')
- Class for timing a block of code.
Uses enter and exit magic methods.
Display the name of the block.
Display timing information.
Indent the results inside the block.
- Parameters:
logger (logger) – Logger object instance.
name (string) – Name of the code block.
level (string) – Logging level to be used.
- pypeec.log.log_exception(logger=None, ex=None, 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_timestamp()
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.reset_global()
- Reset the global variables.
timestamp (for the elapsed time)
indentation level (for log messages)
- 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, tag=None)
Get a logger with a specified name. If the logger does not exist, the logger is created. If the logger does exist, the logger is returned.
- Parameters:
name (string) – Name of the logger to be returned.
tag (string) – Non-unique tag assigned to the logger.
- Returns:
logger – Logger object instance.
- Return type:
logger