rsudp.__init__ (initialization functions)

These are the initialization functions in rsudp. The useful things here are likely printM, printW and printE which interface with the logging utility to print messages, warnings, and errors in color and save them to the logs.

class rsudp.__init__.LevelFormatter(fmt=None, datefmt=None, level_fmts={})

A class that formats messages differently depending on their level. Adapted from this stackoverflow answer.

Parameters
  • fmt (str or None) – Format of message strings (see logging; example: '%(asctime)-15s %(msg)s')

  • datefmt (str or None) – Date strings in strftime format (see logging example: '%Y-%m-%d %H:%M:%S')

  • level_fmts (dict) – Dictionary of log levels and associated formats {logging.INFO: 'infoformat', logging.WARNING: 'warnformat', logging.ERROR: 'errformat'}

format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

rsudp.__init__.add_debug_handler(testing=False)

Creates an additional handler for logging info and warnings to the command line.

Parameters

testing (bool) – whether or not testing is active (adds a “TESTING” label to messages)

Returns

True

Return type

bool

rsudp.__init__.init_dirs(odir)

Initialize the write directories if they do not already exist.

Parameters

odir (str) – output directory

Returns

True

Return type

bool

rsudp.__init__.printE(msg, sender='', announce=True, spaces=False)

Prints errors with datetime stamp and sends their output to the logging handlers.

Parameters
  • msg (str) – message to log

  • sender (str) – the name of the class or function sending the message

  • announce (bool) – whether or not to display “WARNING” before the message

  • spaces (bool) – whether or not to display formatting spaces before the message

rsudp.__init__.printM(msg, sender='', announce=False)

Prints messages with datetime stamp and sends their output to the logging handlers.

Parameters
  • msg (str) – message to log

  • sender (str) – the name of the class or function sending the message

rsudp.__init__.printW(msg, sender='', announce=True, spaces=False)

Prints warnings with datetime stamp and sends their output to the logging handlers.

Parameters
  • msg (str) – message to log

  • sender (str) – the name of the class or function sending the message

  • announce (bool) – whether or not to display “WARNING” before the message

  • spaces (bool) – whether or not to display formatting spaces before the message

rsudp.__init__.start_logging(testing=False)

Creates a handler for logging info and warnings to file.

Parameters

testing (bool) – whether or not testing is active (adds a “TESTING” label to messages)

Returns

True

Return type

bool

Back to top ↑