QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
StateMachineLogger Class Reference

#include <StateMachineLogger.h>

+ Inheritance diagram for StateMachineLogger:
+ Collaboration diagram for StateMachineLogger:

Classes

struct  LogEntry
 Structured log entry. More...
 

Public Types

enum  LogLevel {
  Silent = 0 , Error = 1 , Normal = 2 , Verbose = 3 ,
  Trace = 4
}
 Log verbosity levels. More...
 
enum  LogEvent {
  EventNone = 0 , EventStateEntry = 1 << 0 , EventStateExit = 1 << 1 , EventTransition = 1 << 2 ,
  EventSignal = 1 << 3 , EventTimeout = 1 << 4 , EventError = 1 << 5 , EventMachineStart = 1 << 6 ,
  EventMachineStop = 1 << 7 , EventRetry = 1 << 8 , EventProgress = 1 << 9 , EventCustom = 1 << 10 ,
  EventAll = 0xFFFF , EventStateChanges = EventStateEntry | EventStateExit , EventMachineEvents = EventMachineStart | EventMachineStop , EventErrors = EventError | EventTimeout
}
 Types of log events. More...
 
using LogHandler = std::function< void(const LogEntry &)>
 

Public Member Functions

 StateMachineLogger (QGCStateMachine *machine, QObject *parent=nullptr)
 
 ~StateMachineLogger () override
 
void setEnabled (bool enabled)
 
bool isEnabled () const
 
void setLogLevel (LogLevel level)
 
LogLevel logLevel () const
 
void setStateLogLevel (const QString &stateName, LogLevel level)
 Set log level override for a specific state.
 
void clearStateLogLevel (const QString &stateName)
 
void setLogFilter (LogEvents events)
 Set which events to log (default: all)
 
LogEvents logFilter () const
 
void excludeState (const QString &stateName)
 Exclude specific states from logging.
 
void includeState (const QString &stateName)
 
void clearExclusions ()
 
void setColoredOutput (bool enabled)
 Enable colored console output.
 
bool coloredOutput () const
 
void setLogTimings (bool enabled)
 Enable timing annotations.
 
bool logTimings () const
 
void setLogIndent (bool enabled)
 Enable hierarchy indentation.
 
bool logIndent () const
 
void setLogTransitionReasons (bool enabled)
 Log transition reasons (signal name, timeout, etc.)
 
bool logTransitionReasons () const
 
bool setLogFile (const QString &filePath)
 Log to a file (in addition to console)
 
void closeLogFile ()
 
void setLogHandler (LogHandler handler)
 Set a custom log handler.
 
void enableCrashLog (int maxEntries)
 Enable crash log buffer (circular buffer for post-mortem analysis)
 
void disableCrashLog ()
 
QString dumpCrashLog () const
 
QList< LogEntrycrashLogEntries () const
 
void log (LogLevel level, const QString &message, const QJsonObject &context=QJsonObject())
 Log a custom message.
 
void logEvent (LogEvent event, const QString &message, const QJsonObject &context=QJsonObject())
 Log with specific event type.
 
QHash< LogEvent, int > eventCounts () const
 Get count of entries by event type.
 
void resetStats ()
 Reset statistics.
 

Detailed Description

Extended logging for state machines.

Provides configurable, structured logging with multiple output options.

Example usage:

QGCStateMachine machine("MyMachine", nullptr);
StateMachineLogger logger(&machine);
logger.setLogLevel(StateMachineLogger::Verbose);
logger.setColoredOutput(true);
logger.setLogTimings(true);
logger.setEnabled(true);
// Or log to file
logger.setLogFile("/tmp/machine.log");
QGroundControl specific state machine with enhanced error handling.
@ Verbose
Normal + signals/transitions.

Definition at line 37 of file StateMachineLogger.h.

Member Typedef Documentation

◆ LogHandler

using StateMachineLogger::LogHandler = std::function<void(const LogEntry&)>

Definition at line 93 of file StateMachineLogger.h.

Member Enumeration Documentation

◆ LogEvent

Types of log events.

Enumerator
EventNone 
EventStateEntry 
EventStateExit 
EventTransition 
EventSignal 
EventTimeout 
EventError 
EventMachineStart 
EventMachineStop 
EventRetry 
EventProgress 
EventCustom 
EventAll 
EventStateChanges 
EventMachineEvents 
EventErrors 

Definition at line 53 of file StateMachineLogger.h.

◆ LogLevel

Log verbosity levels.

Enumerator
Silent 

No logging.

Error 

Only errors.

Normal 

Errors + state changes.

Verbose 

Normal + signals/transitions.

Trace 

Everything including internal details.

Definition at line 43 of file StateMachineLogger.h.

Constructor & Destructor Documentation

◆ StateMachineLogger()

StateMachineLogger::StateMachineLogger ( QGCStateMachine machine,
QObject *  parent = nullptr 
)
explicit

Definition at line 167 of file StateMachineLogger.cc.

◆ ~StateMachineLogger()

StateMachineLogger::~StateMachineLogger ( )
override

Definition at line 173 of file StateMachineLogger.cc.

References closeLogFile().

Member Function Documentation

◆ clearExclusions()

void StateMachineLogger::clearExclusions ( )
inline

Definition at line 127 of file StateMachineLogger.h.

◆ clearStateLogLevel()

void StateMachineLogger::clearStateLogLevel ( const QString &  stateName)

Definition at line 224 of file StateMachineLogger.cc.

◆ closeLogFile()

void StateMachineLogger::closeLogFile ( )

Definition at line 254 of file StateMachineLogger.cc.

Referenced by setLogFile(), and ~StateMachineLogger().

◆ coloredOutput()

bool StateMachineLogger::coloredOutput ( ) const
inline

Definition at line 135 of file StateMachineLogger.h.

◆ crashLogEntries()

QList< LogEntry > StateMachineLogger::crashLogEntries ( ) const
inline

Definition at line 164 of file StateMachineLogger.h.

◆ disableCrashLog()

void StateMachineLogger::disableCrashLog ( )

Definition at line 273 of file StateMachineLogger.cc.

◆ dumpCrashLog()

QString StateMachineLogger::dumpCrashLog ( ) const

Definition at line 279 of file StateMachineLogger.cc.

◆ enableCrashLog()

void StateMachineLogger::enableCrashLog ( int  maxEntries)

Enable crash log buffer (circular buffer for post-mortem analysis)

Definition at line 267 of file StateMachineLogger.cc.

◆ eventCounts()

QHash< LogEvent, int > StateMachineLogger::eventCounts ( ) const
inline

Get count of entries by event type.

Definition at line 181 of file StateMachineLogger.h.

◆ excludeState()

void StateMachineLogger::excludeState ( const QString &  stateName)

Exclude specific states from logging.

Definition at line 229 of file StateMachineLogger.cc.

◆ includeState()

void StateMachineLogger::includeState ( const QString &  stateName)

Definition at line 234 of file StateMachineLogger.cc.

◆ isEnabled()

bool StateMachineLogger::isEnabled ( ) const
inline

Definition at line 103 of file StateMachineLogger.h.

◆ log()

◆ logEvent()

◆ logFilter()

LogEvents StateMachineLogger::logFilter ( ) const
inline

Definition at line 122 of file StateMachineLogger.h.

◆ logIndent()

bool StateMachineLogger::logIndent ( ) const
inline

Definition at line 143 of file StateMachineLogger.h.

◆ logLevel()

LogLevel StateMachineLogger::logLevel ( ) const
inline

Definition at line 110 of file StateMachineLogger.h.

◆ logTimings()

bool StateMachineLogger::logTimings ( ) const
inline

Definition at line 139 of file StateMachineLogger.h.

◆ logTransitionReasons()

bool StateMachineLogger::logTransitionReasons ( ) const
inline

Definition at line 147 of file StateMachineLogger.h.

◆ resetStats()

void StateMachineLogger::resetStats ( )
inline

Reset statistics.

Definition at line 184 of file StateMachineLogger.h.

◆ setColoredOutput()

void StateMachineLogger::setColoredOutput ( bool  enabled)
inline

Enable colored console output.

Definition at line 134 of file StateMachineLogger.h.

◆ setEnabled()

void StateMachineLogger::setEnabled ( bool  enabled)

Definition at line 178 of file StateMachineLogger.cc.

◆ setLogFile()

bool StateMachineLogger::setLogFile ( const QString &  filePath)

Log to a file (in addition to console)

Definition at line 239 of file StateMachineLogger.cc.

References closeLogFile().

◆ setLogFilter()

void StateMachineLogger::setLogFilter ( LogEvents  events)
inline

Set which events to log (default: all)

Definition at line 121 of file StateMachineLogger.h.

◆ setLogHandler()

void StateMachineLogger::setLogHandler ( LogHandler  handler)
inline

Set a custom log handler.

Definition at line 158 of file StateMachineLogger.h.

◆ setLogIndent()

void StateMachineLogger::setLogIndent ( bool  enabled)
inline

Enable hierarchy indentation.

Definition at line 142 of file StateMachineLogger.h.

◆ setLogLevel()

void StateMachineLogger::setLogLevel ( LogLevel  level)
inline

Definition at line 109 of file StateMachineLogger.h.

◆ setLogTimings()

void StateMachineLogger::setLogTimings ( bool  enabled)
inline

Enable timing annotations.

Definition at line 138 of file StateMachineLogger.h.

◆ setLogTransitionReasons()

void StateMachineLogger::setLogTransitionReasons ( bool  enabled)
inline

Log transition reasons (signal name, timeout, etc.)

Definition at line 146 of file StateMachineLogger.h.

◆ setStateLogLevel()

void StateMachineLogger::setStateLogLevel ( const QString &  stateName,
LogLevel  level 
)

Set log level override for a specific state.

Definition at line 219 of file StateMachineLogger.cc.


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