Logging

poriscope.utils.LogDecorator.log(_func: F, *, logger: Logger) F
poriscope.utils.LogDecorator.log(_func: None = None, *, logger: Logger) Callable[[F], F]

@log(logger): A decorator that logs the entry and exit of a function. Exceptions raised by the decorated function are not caught or logged here; they propagate to the caller unchanged.

The decorator logs, and only when the decorated module’s logger is enabled for DEBUG: - Entry into the function, qualified by its class name, with the arguments it was called with. - The result it returned.

Nothing is logged at any other level. The check is logger.isEnabledFor, so a single module can be turned up to DEBUG on its own without raising the level of the whole application, and nothing is formatted until it passes.

Example usage:

At the level of the class definition, define a logger exactly as follows:

import logging
from poriscope.utils.LogDecotrator import log
class SomePlugin(MetaPlugin):
    logger = logging.getLogger(__name__)
    @log(logger=logger)
    def __init__(self):
        ...

Once this is done, you can decorate any member functions you want logged to the logfile like so:

@log(logger=logger)
def my_function(self, ...):
    pass

All member methods of plugins should be decorated with this logger. Calls to the logger inside functions proceed normally.

@log(logger=logger)
def my_function(self, ...):
    self.logger.info('This message is informational')
Parameters:
  • _func (Optional[F]) – The function to be decorated. If None, the decorator is returned.

  • logger (logging.Logger) – The logger instance used for logging.

Returns:

The decorated function or the decorator itself.

Return type:

Union[F, Callable[[F], F]]