Logging

Logging module holds utilities that help with logging and analyzing the creative system’s behavior.

class creamas.logging.ObjectLogger(obj, folder, add_name=False, init=True, log_level=10)[source]

Base logger for Creamas objects. Not a subclass of logging.Logger.

Generates one file for each attribute to be logged.

Create new logger instance for obj in folder. If add_name is True, creates subfolder carrying obj.name to folder. If init is true, sets logger’s level to log_level and adds basic StreamHandler to the logger.

add_handler(handler)[source]

Add handler to the logger.

get_file(attr_name)[source]

Return absolute path to logging file for obj’s attribute.

log_attr(level, attr_name)[source]

Log attribute to file and pass the message to underlying logger.

Parameters
  • level (int) – logging level

  • attr_name (str) – attribute’s name to be logged

write(attr_name, prefix=None)[source]

Write attribute’s value to a file.

Parameters
  • attr_name (str) – Attribute’s name to be logged

  • prefix (str) – Optional. Attribute’s name that is prefixed to logging message, defaults to None.

Returns

message written to file

Return type

str

property folder

Root logging folder for this logger.

property obj

Object this logger belongs to. Object has to have name attribute.

creamas.logging.log_before(attr, level=10)[source]

Decorator to log attribute’s value(s) before function call.

Implementation allows usage only for methods belonging to class. The class instance needs to have a logger that is derived from ObjectLogger.

Parameters
  • level (int) – logging level

  • attr (str) – name of the class instance’s parameter to be logged

creamas.logging.log_after(attr, level=10)[source]

Decorator to log attribute’s value(s) after function call.

Implementation allows usage only for methods belonging to class. The class instance needs to have a logger that is derived from ObjectLogger.

Parameters
  • level (int) – logging level

  • attr (str) – name of the class instance’s parameter to be logged