General Overview of Logging

In general, there are three steps to configuring logging in ModelSpace regardless of the language. The three steps are:

  • Creation of the logger — right now that can be CsvLogger or Hdf5Logger

  • Addition of parameters — the same (as defined below) regardless of logger type

  • Passing the logger to the executive — the same regardless of logger type

Creation of the Logger

This example shows creating a logger as Csv in Python and Hdf5 in C++, but those can be easily reversed. Creation of the logger involves creating it as a child of the executive and providing a name, which will become the logged filename

C++

Hdf5Logger state(exc, "states.h5");

Python

state = CsvLogger(exc, "states.csv")

Adding Parameters to the Logger

Adding parameters to the logger should be done as defined below. Simple C++ and Python examples are provided here.

C++

state.addParameter(exc.time()->base_time, "time");                        // Add time as a logged by object with name time
state.addParameter(".exc.fs_model.outputs.vel_tgt_ref__ref", "sc_vel");   // Add veolocity by address with name sc_vel

Python

state.addParameter(exc.time().base_time, "time")                        # Add time as a logged by object with name time
state.addParameter(".exc.fs_model.outputs.vel_tgt_ref__ref", "sc_vel")  # Add veolocity by address with name sc_vel

Passing the Logger to the Executive

The final step in configuring logging is to pass the logger to the executive, which will automatically run it at a configured rate. Simple examples are provided below.

C++

exc.logManager()->addLog(state, 1); // Set our log to run at a rate of 1 Hz

Python

exc.logManager().addLog(state, 1)   # Set our log to run at a rate of 1 Hz

Adding Logging Parameters

The following functions to add logging parameters are the same regardless of which logger is applied.

Description C++ Example Python Example

Adding Parameter by Object - Adds a logging parameter by passing the object itself

logger.addParameter(object, "paramName");
logger.addParameter(object, "paramName")

Adding Parameter by Address String - Adds a logging parameter by passing an address string. This exists for almost all objects in the sim, and can be handy for accessing objects more easily.

logger.addParameter("paramAddress", "paramName");
logger.addParameter("paramAddress", "paramName")

Adding Parameter with recursive logging. This logs the parameter and all of its children — for example, passing a model to this would log all inputs and outputs to the model.

logger.addParameter(object, "paramName", true);
logger.addParameter(object, "paramName", true)