SignalLogger
A library for signal logging.
signal_logger::SignalLoggerBase Class Referenceabstract

Class that severs as base class for all the loggers. More...

#include <SignalLoggerBase.hpp>

Inheritance diagram for signal_logger::SignalLoggerBase:
Inheritance graph

Classes

struct  maxScaledBufferSize
 Comparison operator, get element with largest scaled buffer size. More...
 

Public Member Functions

 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 Types

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

bool readDataCollectScript (const std::string &scriptName)
 
bool saveDataCollectScript (const std::string &scriptName)
 
virtual bool workerSaveData (const std::string &logFileName, const LogFileTypeSet &logfileTypes)=0
 
virtual void initTimeLogElement ()
 
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...
 

Protected Attributes

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...
 

Private Member Functions

bool workerSaveDataWrapper (const LogFileTypeSet &logfileTypes)
 
bool workerStartLogger (bool updateLogger=false)
 
template<typename PropertyType_ >
bool setElementProperty (const std::string &elementName, const PropertyType_ property, const std::string &propertyName, std::function< PropertyType_(const std::unique_ptr< LogElementInterface > &)> propertyGetter, std::function< void(const std::unique_ptr< LogElementInterface > &, const PropertyType_)> propertySetter)
 Set property of log element, if: More...
 
bool setElementPropertyForNamespace (const std::string &ns, std::function< bool(const std::string &)> setElementProperty)
 Set a property for a complete namespace. More...
 

Detailed Description

Class that severs as base class for all the loggers.

Member Typedef Documentation

using signal_logger::SignalLoggerBase::LogElementMap = std::unordered_map<std::string, std::unique_ptr<LogElementInterface>>
protected
using signal_logger::SignalLoggerBase::LogElementMapIterator = LogElementMap::iterator
protected
using signal_logger::SignalLoggerBase::LogPair = std::pair<std::string, std::unique_ptr<LogElementInterface>>
protected

Log element map types.

Constructor & Destructor Documentation

signal_logger::SignalLoggerBase::SignalLoggerBase ( )

Constructor

Parameters
loggerPrefixprefix to the logger variables
virtual signal_logger::SignalLoggerBase::~SignalLoggerBase ( )
virtualdefault

Destructor.

Member Function Documentation

virtual bool signal_logger::SignalLoggerBase::cleanup ( )
virtual

Cleanup logger.

Reimplemented in signal_logger_ros::SignalLoggerRos.

virtual bool signal_logger::SignalLoggerBase::collectLoggerData ( )
virtual

Collect log data, read data and push it into the buffer.

Reimplemented in signal_logger::SignalLoggerNone.

bool signal_logger::SignalLoggerBase::disableElement ( const std::string &  name)

Disables element if logger is not running.

Parameters
namename of the element
Returns
true, iff successful
bool signal_logger::SignalLoggerBase::disableNamespace ( const std::string &  ns)
bool signal_logger::SignalLoggerBase::enableElement ( const std::string &  name)

Enables the element if:

  • The logger is not running
  • Or, the logger is running, the element has looping buffer type and the time buffer is looping and large enough to provide timing info to the element
    Parameters
    namename of the element
    Returns
    true, iff successful
bool signal_logger::SignalLoggerBase::enableNamespace ( const std::string &  ns)

Property setting functions extended to namespace.

Parameters
nsnamespace to which changes are applied
Returns
true, iff successful
virtual signal_logger::TimestampPair signal_logger::SignalLoggerBase::getCurrentTime ( )
protectedvirtual

Returns the current time

Returns
current time

Reimplemented in signal_logger_ros::SignalLoggerRos.

const LogElementInterface& signal_logger::SignalLoggerBase::getElement ( const std::string &  name)

Gets a const reference to a log element.

Parameters
nameName of the log element to get
Exceptions
std::out_of_range()if no element with 'name' exists
Returns
const log element reference
bool signal_logger::SignalLoggerBase::hasElement ( const std::string &  name)

Checks if logger has a log element with name 'name'.

Parameters
nameName of the log element to check
Returns
true, iff element exists
virtual bool signal_logger::SignalLoggerBase::hasElementLockFree ( const std::string &  name)
protectedvirtual

Lock free version of has element.

virtual void signal_logger::SignalLoggerBase::initLogger ( const SignalLoggerOptions options)
virtual

Initializes the logger

Parameters
optionsSignal logger options

Reimplemented in signal_logger::SignalLoggerNone.

virtual void signal_logger::SignalLoggerBase::initTimeLogElement ( )
protectedvirtual

Initializes the pointer to the log element

Reimplemented in signal_logger_std::SignalLoggerStd.

bool signal_logger::SignalLoggerBase::isRunning ( ) const
inline

True if logger is running.

virtual bool signal_logger::SignalLoggerBase::publishData ( )
virtual

Publish a single data point of every element from the buffer.

Reimplemented in signal_logger::SignalLoggerNone.

bool signal_logger::SignalLoggerBase::readDataCollectScript ( const std::string &  scriptName)
protected

Reads collect script and enables all log data

Parameters
scriptNamefilename of the logging script
template<typename ValueType_ >
vector_type<ValueType_> signal_logger::SignalLoggerBase::readNewValues ( const std::string &  name)
inline

Get new values (since the last call to this function) as a vector (first entry is the oldest)

Template Parameters
ValueType_Valuetype of the log element to read values from
Parameters
nameName of the element to read values from
Exceptions
std::out_of_rangeif ValueType_ does not correspond stored type, or no element with name 'name' exists
Returns
vector of values since last call to this function (vector_type has a different allocator for Eigen types)
virtual bool signal_logger::SignalLoggerBase::restartLogger ( bool  updateLogger = false)
virtual

Stop and then restart the logger.

Reimplemented in signal_logger::SignalLoggerNone.

bool signal_logger::SignalLoggerBase::saveDataCollectScript ( const std::string &  scriptName)
protected

Save collect script

Parameters
scriptNamefilename of the logging script
virtual bool signal_logger::SignalLoggerBase::saveLoggerData ( const LogFileTypeSet logfileTypes)
virtual

Save all the buffered data into a log file

Parameters
logFileTypestypes of the log file

Reimplemented in signal_logger::SignalLoggerNone.

virtual bool signal_logger::SignalLoggerBase::saveLoggerScript ( const std::string &  scriptName = std::string(LOGGER_DEFAULT_SCRIPT_FILENAME))
virtual

Save logger script

Reimplemented in signal_logger::SignalLoggerNone.

bool signal_logger::SignalLoggerBase::setElementAction ( const std::string &  name,
const LogElementAction  action 
)

Sets action of element if logger is not running.

Parameters
namename of the element
actiondesired action
Returns
true, iff successful
bool signal_logger::SignalLoggerBase::setElementBufferSize ( const std::string &  name,
const std::size_t  size 
)

Sets buffer size of element if logger is not running.

Parameters
namename of the element
sizedesired buffer size
Returns
true, iff successful
bool signal_logger::SignalLoggerBase::setElementBufferType ( const std::string &  name,
const BufferType  type 
)

Sets buffer type of element if logger is not running.

Parameters
namename of the element
typedesired buffer type
Returns
true, iff successful
bool signal_logger::SignalLoggerBase::setElementDivider ( const std::string &  name,
const std::size_t  divider 
)

Sets divider of element if logger is not running.

Parameters
namename of the element
dividerdesired divider
Returns
true, iff successful
template<typename PropertyType_ >
bool signal_logger::SignalLoggerBase::setElementProperty ( const std::string &  elementName,
const PropertyType_  property,
const std::string &  propertyName,
std::function< PropertyType_(const std::unique_ptr< LogElementInterface > &)>  propertyGetter,
std::function< void(const std::unique_ptr< LogElementInterface > &, const PropertyType_)>  propertySetter 
)
inlineprivate

Set property of log element, if:

  • The logger is not running
  • Or the logger is running and the element is disabled
    Template Parameters
    PropertyType_Type of the property
    Parameters
    elementNameName of the element of which to change the property
    propertyDesired value of the property
    propertyNameDescriptive name of the property (used for warn outputs)
    propertyGetterLambda that gets the property from a log element interface ptr
    propertySetterLambda that sets the desired property to a log element interface ptr
    Returns
    true, iff successful
bool signal_logger::SignalLoggerBase::setElementPropertyForNamespace ( const std::string &  ns,
std::function< bool(const std::string &)>  setElementProperty 
)
inlineprivate

Set a property for a complete namespace.

Parameters
nsnamespace for which property shall be changed (remember log_element_name = (lognamespace + / + ns + / + name) )
setElementPropertyFunction setting the property of a single element
Returns
true, iff successful
void signal_logger::SignalLoggerBase::setMaxLoggingTime ( double  maxLoggingTime)

Set max logging time.

bool signal_logger::SignalLoggerBase::setNamespaceAction ( const std::string &  ns,
const LogElementAction  action 
)
bool signal_logger::SignalLoggerBase::setNamespaceBufferSize ( const std::string &  ns,
const std::size_t  size 
)
bool signal_logger::SignalLoggerBase::setNamespaceBufferType ( const std::string &  ns,
const BufferType  type 
)
bool signal_logger::SignalLoggerBase::setNamespaceDivider ( const std::string &  ns,
const std::size_t  divider 
)
virtual bool signal_logger::SignalLoggerBase::startLogger ( bool  updateLogger = false)
virtual

Starts the logger (enable collecting)

Reimplemented in signal_logger::SignalLoggerNone.

virtual bool signal_logger::SignalLoggerBase::stopAndSaveLoggerData ( const LogFileTypeSet logfileTypes)
virtual

Stop the logger and save all the buffered data into log files

Parameters
logFileTypestypes of the log file

Reimplemented in signal_logger::SignalLoggerNone.

virtual bool signal_logger::SignalLoggerBase::stopLogger ( )
virtual

Stop the logger (disable collecting)

Reimplemented in signal_logger::SignalLoggerNone.

virtual bool signal_logger::SignalLoggerBase::updateLogger ( const bool  readScript = true,
const std::string &  scriptname = "" 
)
virtual

Update the logger, variables added since the last call are added.

Update the logger (ded variables are added)

Parameters
readScriptDetermines whether the script is reloaded (sets the state as declared in the script)
scriptnameIf empty, the script defined in the options is loaded. Otherwise scriptname will be used.
Returns
true, iff logger was updated successfully

Reimplemented in signal_logger::SignalLoggerNone.

virtual bool signal_logger::SignalLoggerBase::updateLoggerLockFree ( const bool  readScript = true,
const std::string &  scriptname = "" 
)
protectedvirtual

Lock free version of updateLogger.

virtual bool signal_logger::SignalLoggerBase::workerSaveData ( const std::string &  logFileName,
const LogFileTypeSet logfileTypes 
)
protectedpure virtual

Saves the logger data in a file in a seperate thread

Parameters
logFileNamefilename of the log file
logfileTypestypes of the log files

Implemented in signal_logger_ros::SignalLoggerRos, signal_logger::SignalLoggerNone, and signal_logger_std::SignalLoggerStd.

bool signal_logger::SignalLoggerBase::workerSaveDataWrapper ( const LogFileTypeSet logfileTypes)
private

Wraps function workerSaveData to do common preparations and shutdown

Parameters
logFileTypsetypes of the log files
bool signal_logger::SignalLoggerBase::workerStartLogger ( bool  updateLogger = false)
private

Wait until logger can be started and start logger

Member Data Documentation

std::vector<LogElementMapIterator> signal_logger::SignalLoggerBase::enabledElements_
protected

Vector of iterators in logElements_ map.

std::atomic_bool signal_logger::SignalLoggerBase::isCollectingData_
protected

Flag to collect data.

std::atomic_bool signal_logger::SignalLoggerBase::isCopyingBuffer_
protected

Flag to save data.

std::atomic_bool signal_logger::SignalLoggerBase::isInitialized_
protected

Flag to check if logger is initialized.

std::atomic_bool signal_logger::SignalLoggerBase::isSavingData_
protected

Flag to save data.

std::atomic_bool signal_logger::SignalLoggerBase::isStarting_
protected

Flag is starting in different thread.

LogElementMap signal_logger::SignalLoggerBase::logElements_
protected

Map of log elements (excluding time, elements added after last updateLogger() call)

LogElementMap signal_logger::SignalLoggerBase::logElementsToAdd_
protected

Map of all log elements added since last call to updateLogger()

boost::shared_mutex signal_logger::SignalLoggerBase::loggerMutex_
protected

Init, add, update, start, stop and cleanup should be called in sequence.

TimestampPair signal_logger::SignalLoggerBase::logTime_
protected

Time variable.

std::atomic_uint signal_logger::SignalLoggerBase::noCollectDataCalls_
protected

Nr of calls to collect data.

std::atomic_uint signal_logger::SignalLoggerBase::noCollectDataCallsCopy_
protected

Copy of nr of calls to collect data for saving.

SignalLoggerOptions signal_logger::SignalLoggerBase::options_
protected

Logger Options.

std::mutex signal_logger::SignalLoggerBase::saveLoggerDataMutex_
protected

Allow call to save logger data only once.

std::atomic_bool signal_logger::SignalLoggerBase::shouldPublish_
protected

Flag if data should be published.

std::shared_ptr<LogElementBase<TimestampPair> > signal_logger::SignalLoggerBase::timeElement_
protected

Corresponding time log element.


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