loggers¶
Logging functionality
There are two types of loggers: a standard logging.Logger
-based logging system for debugging and recording system events,
and a tables
- based DataLogger
class to store continuously measured sensor values.
Classes
|
Class for logging numerical respiration data and control settings. |
Data
list of strings, which loggers have been created already. |
Functions
|
Initialize a logger for logging events. |
|
# TODO: Stub exception logger. Prints exception type & traceback |
Adjust each logger’s |
-
pvp.common.loggers.
_LOGGERS
= ['pvp.common.prefs', 'pvp.alarm.alarm_manager']¶ list of strings, which loggers have been created already.
-
pvp.common.loggers.
init_logger
(module_name: str, log_level: int = None, file_handler: bool = True) → logging.Logger[source]¶ Initialize a logger for logging events.
If a logger has already been initialized, return that.
- Parameters
module_name (str) – module name used to generate filename and name logger
log_level (int) – one of :var:`logging.DEBUG`, :var:`logging.INFO`, :var:`logging.WARNING`, or :var:`logging.ERROR`
file_handler (bool, str) – if
True
, (default), log in<logdir>/module_name.log
. ifFalse
, don’t log to disk.
- Returns
Logger 4 u 2 use
- Return type
-
pvp.common.loggers.
update_logger_sizes
()[source]¶ Adjust each logger’s
maxBytes
attribute so that the total across all loggers isprefs.LOGGING_MAX_BYTES
-
pvp.common.loggers.
log_exception
(e, tb)[source]¶ # TODO: Stub exception logger. Prints exception type & traceback
- Parameters
e – Exception to log
tb – TraceBack associated with Exception e
-
class
pvp.common.loggers.
DataLogger
(compression_level: int = 9)[source]¶ Bases:
object
Class for logging numerical respiration data and control settings. Creates a hdf5 file with this general structure:
Methods
__init__
(compression_level)Initialized the coontinuous numerical logger class.
Opens the hdf5 file and generates the file structure.
make sure that the file’s are not getting too large.
Flushes & closes the open hdf file.
This flushes the datapoints to the file.
load_file
([filename])This loads a hdf5 file, and returns data to the user as a dictionary with two keys: waveform_data and control_data
log2csv
([filename])Translates the compressed hdf5 into three csv files containing:
log2mat
([filename])Translates the compressed hdf5 into a matlab file containing a matlab struct.
This rotates through filenames, similar to a ringbuffer, to make sure that the program does not run of of space/
store_control_command
(control_setting)Appends a datapoint to the event-table, derived from ControlSettings
store_derived_data
(derived_values)Appends a datapoint to the event-table, derived the continuous data (PIP, PEEP etc.)
store_waveform_data
(sensor_values, …)Appends a datapoint to the file for continuous logging of streaming data.
/ root |— waveforms (group) | |— time | pressure_data | flow_out | control_signal_in | control_signal_out | FiO2 | Cycle No. | |— controls (group) | |— (time, controllsignal) | |— derived_quantities (group) | |— (time, Cycle No, I_PHASE_DURATION, PIP_TIME, PEEP_time, PIP, PIP_PLATEAU, PEEP, VTE ) | |
- Public Methods:
close_logfile(): Flushes, and closes the logfile. store_waveform_data(SensorValues): Takes data from SensorValues, but DOES NOT FLUSH store_controls(): Store controls in the same file? TODO: Discuss flush_logfile(): Flush the data into the file
Initialized the coontinuous numerical logger class.
- Parameters
compression_level (int, optional) – Compression level of the hdf5 file. Defaults to 9.
-
__init__
(compression_level: int = 9)[source]¶ Initialized the coontinuous numerical logger class.
- Parameters
compression_level (int, optional) – Compression level of the hdf5 file. Defaults to 9.
-
store_waveform_data
(sensor_values: SensorValues, control_values: ControlValues)[source]¶ Appends a datapoint to the file for continuous logging of streaming data. NOTE: Not flushed yet.
- Parameters
sensor_values (SensorValues) – SensorValues to be stored in the file.
control_values (ControlValues) – ControlValues to be stored in the file
-
store_control_command
(control_setting: ControlSetting)[source]¶ Appends a datapoint to the event-table, derived from ControlSettings
- Parameters
control_setting (ControlSetting) – ControlSettings object, the content of which should be stored
-
store_derived_data
(derived_values: DerivedValues)[source]¶ Appends a datapoint to the event-table, derived the continuous data (PIP, PEEP etc.)
- Parameters
derived_values (DerivedValues) – DerivedValues object, the content of which should be stored
-
flush_logfile
()[source]¶ This flushes the datapoints to the file. To be executed every other second, e.g. at the end of breath cycle.
-
rotation_newfile
()[source]¶ This rotates through filenames, similar to a ringbuffer, to make sure that the program does not run of of space/
-
load_file
(filename=None)[source]¶ This loads a hdf5 file, and returns data to the user as a dictionary with two keys: waveform_data and control_data
- Parameters
filename (str, optional) – Path to a hdf5-file. If none is given, uses currently open file. Defaults to None.
- Returns
Containing the data arranged as ` {“waveform_data”: waveform_data, “control_data”: control_data, “derived_data”: derived_data}`
- Return type
dictionary
-
log2mat
(filename=None)[source]¶ Translates the compressed hdf5 into a matlab file containing a matlab struct. This struct has the same structure as the hdf5 file, but is not compressed. Use for any file:
dl = DataLogger() dl.log2mat(filename)
The file is saved at the same path as .mat file, where the content is represented as matlab-structs.
- Parameters
filename (str, optional) – Path to a hdf5-file. If none is given, uses currently open file. Defaults to None.
-
log2csv
(filename=None)[source]¶ - Translates the compressed hdf5 into three csv files containing:
waveform_data (measurement once per cycle)
derived_quantities (PEEP, PIP etc.)
control_commands (control commands sent to the controller)
This approximates the structure contained in the hdf5 file. Use for any file:
dl = DataLogger() dl.log2csv(filename)
- Parameters
filename (str, optional) – Path to a hdf5-file. If none is given, uses currently open file. Defaults to None.