SignalLogger
A library for signal logging.
signal_logger_std::SignalLoggerStd Class Reference

#include <SignalLoggerStd.hpp>

Inheritance diagram for signal_logger_std::SignalLoggerStd:
Inheritance graph

Public Member Functions

 SignalLoggerStd ()
 
virtual ~SignalLoggerStd ()
 
template<typename ValueType_ >
void add (const ValueType_ *const var, const std::string &name, const std::string &group=signal_logger::LOG_ELEMENT_DEFAULT_GROUP_NAME, const std::string &unit=signal_logger::LOG_ELEMENT_DEFAULT_UNIT, const std::size_t divider=signal_logger::LOG_ELEMENT_DEFAULT_DIVIDER, const signal_logger::LogElementAction action=signal_logger::LOG_ELEMENT_DEFAULT_ACTION, const std::size_t bufferSize=signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_SIZE, const signal_logger::BufferType bufferType=signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_TYPE)
 
virtual bool workerSaveData (const std::string &logFileName, const signal_logger::LogFileTypeSet &logfileTypes) override
 Save all the buffered data into a log file. More...
 
virtual void initTimeLogElement () override
 
- Public Member Functions inherited from signal_logger::SignalLoggerBase
 SignalLoggerBase ()
 
virtual ~SignalLoggerBase ()=default
 Destructor. More...
 
virtual void initLogger (const SignalLoggerOptions &options)
 
bool isRunning () const
 True if logger is running. More...
 
virtual bool startLogger (bool updateLogger=false)
 Starts the logger (enable collecting) More...
 
virtual bool stopLogger ()
 Stop the logger (disable collecting) More...
 
virtual bool restartLogger (bool updateLogger=false)
 Stop and then restart the logger. More...
 
virtual bool updateLogger (const bool readScript=true, const std::string &scriptname="")
 Update the logger, variables added since the last call are added. More...
 
virtual bool saveLoggerScript (const std::string &scriptName=std::string(LOGGER_DEFAULT_SCRIPT_FILENAME))
 
virtual bool collectLoggerData ()
 Collect log data, read data and push it into the buffer. More...
 
virtual bool publishData ()
 Publish a single data point of every element from the buffer. More...
 
virtual bool saveLoggerData (const LogFileTypeSet &logfileTypes)
 
virtual bool stopAndSaveLoggerData (const LogFileTypeSet &logfileTypes)
 
virtual bool cleanup ()
 Cleanup logger. More...
 
void setMaxLoggingTime (double maxLoggingTime)
 Set max logging time. More...
 
bool hasElement (const std::string &name)
 Checks if logger has a log element with name 'name'. More...
 
const LogElementInterfacegetElement (const std::string &name)
 Gets a const reference to a log element. More...
 
bool enableElement (const std::string &name)
 Enables the element if: More...
 
bool disableElement (const std::string &name)
 Disables element if logger is not running. More...
 
bool setElementBufferSize (const std::string &name, const std::size_t size)
 Sets buffer size of element if logger is not running. More...
 
bool setElementBufferType (const std::string &name, const BufferType type)
 Sets buffer type of element if logger is not running. More...
 
bool setElementDivider (const std::string &name, const std::size_t divider)
 Sets divider of element if logger is not running. More...
 
bool setElementAction (const std::string &name, const LogElementAction action)
 Sets action of element if logger is not running. More...
 
template<typename ValueType_ >
vector_type< ValueType_ > readNewValues (const std::string &name)
 Get new values (since the last call to this function) as a vector (first entry is the oldest) More...
 
bool enableNamespace (const std::string &ns)
 Property setting functions extended to namespace. More...
 
bool disableNamespace (const std::string &ns)
 
bool setNamespaceBufferSize (const std::string &ns, const std::size_t size)
 
bool setNamespaceBufferType (const std::string &ns, const BufferType type)
 
bool setNamespaceDivider (const std::string &ns, const std::size_t divider)
 
bool setNamespaceAction (const std::string &ns, const LogElementAction action)
 

Protected Attributes

std::ofstream file_
 Log file. More...
 
std::stringstream textStream_
 Text stream. More...
 
std::stringstream binaryStream_
 Binary stream. More...
 
- Protected Attributes inherited from signal_logger::SignalLoggerBase
SignalLoggerOptions options_
 Logger Options. More...
 
std::atomic_uint noCollectDataCalls_
 Nr of calls to collect data. More...
 
std::atomic_uint noCollectDataCallsCopy_
 Copy of nr of calls to collect data for saving. More...
 
LogElementMap logElements_
 Map of log elements (excluding time, elements added after last updateLogger() call) More...
 
std::vector< LogElementMapIteratorenabledElements_
 Vector of iterators in logElements_ map. More...
 
LogElementMap logElementsToAdd_
 Map of all log elements added since last call to updateLogger() More...
 
TimestampPair logTime_
 Time variable. More...
 
std::shared_ptr< LogElementBase< TimestampPair > > timeElement_
 Corresponding time log element. More...
 
std::atomic_bool isInitialized_
 Flag to check if logger is initialized. More...
 
std::atomic_bool isCollectingData_
 Flag to collect data. More...
 
std::atomic_bool isSavingData_
 Flag to save data. More...
 
std::atomic_bool isCopyingBuffer_
 Flag to save data. More...
 
std::atomic_bool isStarting_
 Flag is starting in different thread. More...
 
std::atomic_bool shouldPublish_
 Flag if data should be published. More...
 
boost::shared_mutex loggerMutex_
 Init, add, update, start, stop and cleanup should be called in sequence. More...
 
std::mutex saveLoggerDataMutex_
 Allow call to save logger data only once. More...
 

Additional Inherited Members

- Protected Types inherited from signal_logger::SignalLoggerBase
using LogPair = std::pair< std::string, std::unique_ptr< LogElementInterface > >
 Log element map types. More...
 
using LogElementMap = std::unordered_map< std::string, std::unique_ptr< LogElementInterface > >
 
using LogElementMapIterator = LogElementMap::iterator
 
- Protected Member Functions inherited from signal_logger::SignalLoggerBase
bool readDataCollectScript (const std::string &scriptName)
 
bool saveDataCollectScript (const std::string &scriptName)
 
virtual signal_logger::TimestampPair getCurrentTime ()
 
virtual bool hasElementLockFree (const std::string &name)
 Lock free version of has element. More...
 
virtual bool updateLoggerLockFree (const bool readScript=true, const std::string &scriptname="")
 Lock free version of updateLogger. More...
 

Constructor & Destructor Documentation

◆ SignalLoggerStd()

signal_logger_std::SignalLoggerStd::SignalLoggerStd ( )

◆ ~SignalLoggerStd()

virtual signal_logger_std::SignalLoggerStd::~SignalLoggerStd ( )
virtual

Member Function Documentation

◆ add()

template<typename ValueType_ >
void signal_logger_std::SignalLoggerStd::add ( const ValueType_ *const  var,
const std::string &  name,
const std::string &  group = signal_logger::LOG_ELEMENT_DEFAULT_GROUP_NAME,
const std::string &  unit = signal_logger::LOG_ELEMENT_DEFAULT_UNIT,
const std::size_t  divider = signal_logger::LOG_ELEMENT_DEFAULT_DIVIDER,
const signal_logger::LogElementAction  action = signal_logger::LOG_ELEMENT_DEFAULT_ACTION,
const std::size_t  bufferSize = signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_SIZE,
const signal_logger::BufferType  bufferType = signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_TYPE 
)
inline

Add variable to logger. This is a default implementation if no specialization is provided an error is posted.

Template Parameters
ValueType_Data type of the logger element
Parameters
varPointer to log variable
namename of the log variable
grouplogger group the variable belongs to
unitunit of the log variable
dividerdivider is defining the update frequency of the logger element (ctrl_freq/divider)
actionlog action of the log variable
bufferSizesize of the buffer storing log elements
bufferTypedetermines the buffer type

◆ initTimeLogElement()

virtual void signal_logger_std::SignalLoggerStd::initTimeLogElement ( )
overridevirtual

Initializes the pointer to the logelement

Reimplemented from signal_logger::SignalLoggerBase.

◆ workerSaveData()

virtual bool signal_logger_std::SignalLoggerStd::workerSaveData ( const std::string &  logFileName,
const signal_logger::LogFileTypeSet logfileTypes 
)
overridevirtual

Save all the buffered data into a log file.

Implements signal_logger::SignalLoggerBase.

Reimplemented in signal_logger_ros::SignalLoggerRos.

Member Data Documentation

◆ binaryStream_

std::stringstream signal_logger_std::SignalLoggerStd::binaryStream_
protected

Binary stream.

◆ file_

std::ofstream signal_logger_std::SignalLoggerStd::file_
protected

Log file.

◆ textStream_

std::stringstream signal_logger_std::SignalLoggerStd::textStream_
protected

Text stream.


The documentation for this class was generated from the following file: