conductor.lib.loggeria module

class conductor.lib.loggeria.MPFileHandler(filename, when='h', interval=1, backupCount=0, encoding=None, delay=0, utc=0)

Bases: logging.Handler

Multiprocess-safe Rotating File Handler

Copied from: http://stackoverflow.com/questions/641420/how-should-i-log-while-using-multiprocessing-in-python

close()

Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

emit(record)

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

receive()
send(s)
setFormatter(fmt)

Set the formatter for this handler.

class conductor.lib.loggeria.TableStr(data, column_names, title='', footer='', upper_headers=True)

Bases: object

A class to help log/print tables of data:

############## DOWNLOAD HISTORY #################
COMPLETED AT         DOWNLOAD ID       JOB    TASK       SIZE  ACTION  DURATION  THREAD     FILEPATH
2016-01-16 01:12:46  5228833175240704  00208  010    137.51MB  DL      0:00:57   Thread-12  /tmp/conductor_daemon_dl/04/cental/cental.010.exr
2016-01-16 01:12:42  6032237141164032  00208  004    145.48MB  DL      0:02:24   Thread-2   /tmp/conductor_daemon_dl/04/cental/cental.004.exr
2016-01-16 01:12:40  5273802288136192  00208  012    140.86MB  DL      0:02:02   Thread-16  /tmp/conductor_daemon_dl/04/cental/cental.012.exr
cell_modifiers = {}
column_spacer = ' '
get_title()
header_modifiers = {}
make_column_strs(column_name, data)

Return a two dimensional list (list of lists), where the inner lists represent a column of data.

make_table_str()

Create and return a final table string that is suitable to print/log.

This is achieved by creating a list of items for each column in the table. Once all column lists have been created, they are then joined via a constant column space character(s) - self.column_spacer. The rows that are created from the columns are then prefixed with given title (self.title) and suffixed with the given footer (self.footer)

modify_cell(column_name, cell_data)

Modify and return the given cell data of the given column name.

This provides an opportunity to adjust what the header should consist.

modify_header(column_name)

Modify and return the given column name.

This provides an opportunity to adjust what the header should consist.

row_spacer = '\n'
conductor.lib.loggeria.create_file_handler(filepath, level=None, formatter=None, multiproc=False)

Create a file handler object for the given filepath. This is a ROTATING file handler, which rotates every day (24 hours) and stores up to 7 days of logs at a time (equaling up to as many as 7 log files at a given time.

conductor.lib.loggeria.get_conductor_logger()

Return the “conductor” package’s logger object

conductor.lib.loggeria.set_conductor_log_level(log_level)

Set the “conductor” package’s logger to the given log level

conductor.lib.loggeria.setup_conductor_logging(logger_level=20, console_level=None, console_formatter=<logging.Formatter object>, log_filepath=None, file_level=None, file_formatter=<logging.Formatter object>, multiproc=False)

The is convenience function to help set up logging.

THIS SHOULD ONLY BE CALLED ONCE within an execution environment.

This function does the following:

  1. Creates/retrieves the logger object for the “conductor” package

  2. Sets that logger’s log level to the given logger_level (optional)

  3. Creates a console handler and attaches it to the logger object.

    1. Optionally sets that console handler’s log level to the given console_level
    2. Optionally sets that console handler’s formatter to the the given console_formatter
  4. Optionally creates a file handler (if a log filepath is given)

    1. Optionally sets that file handler’s log level to the given file_level
    2. Optionally sets that file handler’s formatter to the the given file_formatter

Notes

console_formatter and file_formatter formatters are the logging.Formatter objects, not just a string such as “DEBUG”.

This is because you may need more than just a string to define a formatter object.

Parameters:multiproc (bool) – If True, a custom file handler will be used that handles multiprocess logging correctly. This file handler creates an additional Process.