dautil.log_api

Logging utilities.

class dautil.log_api.Printer(modules=None, name=None, nelems=-1)

Utility class for pretty printing.

Variables:nelems – Max number of elements in a list to print.
compress_mid(alist, replace='...')

Takes the head, mid and the tail of a list and discards the rest. For example

>>> from dautil import log_api
>>> p = log_api.Printer(nelems=3)
>>> p.compress_mid(list(range(5)))
[0, '...', 2, '...', 4]
Parameters:
  • alist – A list.
  • replace – A string used to replace discarded elements.
Returns:

The list with discarded values replaced.

print(*args, **kwargs)

Pretty prints a message.

class dautil.log_api.VersionsLogFileHandler(fName)

A specialized file handler for the logging of software versions.

dautil.log_api.conf_logger(name)

Creates a logger using a configuration file provided by the user in the current working directory. If a configuration file is not found, dautil uses basic configuration.

Parameters:name – The name of the logger.
Returns:The configured logger.
dautil.log_api.env_logger()

Creates a configurable logger. The environment variable DAUTIL_LOGGER controls whether the logger is enabled. If the value of the variable is *, then all loggers will be enabled, otherwise the calling function name is matched against DAUTIL_LOGGER. Enabling/disabling the logger may be influenced by an underlying framework.

Returns:A configurable logger.
dautil.log_api.get_logger(name)

Creates a logger using an internal configuration file.

Parameters:name – The name of the logger.
Returns:The configured logger.
dautil.log_api.log(modules, name)

Logs the versions of imported modules in a best effort fashion. Some common modules are excluded.

Parameters:
  • modules – A list of modules as available in sys.modules.
  • name – The name of the logger.
Returns:

A dictionary with modules as keys and versions as values.

dautil.log_api.shorten(module_name)

Helper function which shortens a module name using the first occurrence of a dot. For example pandas.io.wb is shortened to pandas.

Parameters:module_name – The name of the module.
Returns:The shortened name.
>>> from dautil import log_api
>>> log_api.shorten('pandas.io.wb')
'pandas'

Previous topic

dautil.db

Next topic

dautil.nb

This Page