basic_robotics.utilities.FaserLog module

Logging helpers for writing text and JSON logs to disk.

class basic_robotics.utilities.FaserLog.FaserLog(name='Misc', dir='Default')[source]

Bases: object

Write timestamped status and matrix data to a text log file using the logging module.

__init__(name='Misc', dir='Default')[source]

Create a new FaserLog and initialize its underlying log file.

The log file name is the given name suffixed with the current timestamp; if a directory is provided it is prepended to the file name.

Parameters:
  • name (str, optional) – Base name for the log. Defaults to “Misc”.

  • dir (str, optional) – Directory to place the log file in. If “Default”, the log file is created in the current directory. Defaults to “Default”.

writeToLog(status)[source]

Write a status message to the log file.

Parameters:

status – Message or object to write to the log.

writeMatrixToLog(matrix, title='MATRIX')[source]

Write a formatted matrix to the log file.

Parameters:
  • matrix – Matrix (or other object accepted by dispa) to log.

  • title (str, optional) – Caption to log alongside the matrix. Defaults to “MATRIX”.

class basic_robotics.utilities.FaserLog.JSONLog(logfname)[source]

Bases: object

Accumulate timestamped log entries in memory and persist them to a JSON file.

__init__(logfname)[source]

Create a new JSONLog.

Parameters:

logfname (str) – Path of the JSON file to read from and write to.

openLog()[source]

Load the log from its JSON file, creating a new (empty) log file if none exists.

saveLog()[source]

Save the current log entries, along with the total item count, to the JSON file.

writeToLog(item, openClose=False)[source]

Append a new timestamped entry to the log.

Parameters:
  • item – Data to store for this log entry.

  • openClose (bool, optional) – If True, load the log from disk before writing and save it back to disk afterward. Defaults to False.