This guide shows you how to set up centralized simulation reporting with CSimReports, log messages of different severities, and read the report buffer back.
1. Understand CSimReports
The CSimReports class provides a centralized system for collecting, storing, and reporting simulation messages, warnings, errors, and informational logs. It supports both persistent in-memory storage and dynamic reporting with optional formatting.
- Report Types: supports multiple categories via
EReportType:eError,eWarning,eInfo,eTest,eStates,eFatalError. - Persistent Storage: uses a shared memory object (
shoom::Shm) to store all report data for retrieval or external inspection. - Error Tracking: maintains an internal list of unique errors with counts and positions in the report text.
- Flexible Reporting: provides multiple
ReportMsgoverloads and a printf-styleReportmethod for formatted messages. - Access Reports:
GetReportPtrprovides raw access to the report data and size.
2. Know the Internal Structure
| Member | Description |
|---|---|
| simEngReports | Unique pointer to shared memory for storing all report messages. |
| text | Raw character buffer containing report text. |
| reportsSize | Current size of the report buffer. |
| errorList | Map of unique errors to CError structures that store position, length, and occurrence count. |
CSimReports::CError represents an individual tracked error or warning:
- spos: position of the message in the report text.
- length: length of the error message.
- counter: number of times this error has occurred.
3. Set Up Reporting
- Call
CSimReports::SetupReports()once to initialize the reporting system. - Log messages as your simulation runs (see next section for the available methods).
- Read back the report buffer whenever you need to inspect it.
4. Log Messages
Use the appropriate call for the kind of message you need to record:
// Setup the reporting system
CSimReports::SetupReports();
// Simple informational message
CSimReports::ReportMsg(CSimReports::eInfo, "Simulation started");
// Message with additional details
CSimReports::ReportMsg(CSimReports::eWarning, "Potential issue detected", "Extra info", 5);
// Formatted report
CSimReports::Report(CSimReports::eError, "Error code %d at frame %d", errorCode, frameNum);
5. Read the Report Buffer
// Access raw report data
size_t size;
uint8_t* reportData = CSimReports::GetReportPtr(size);
if(reportData) {
// process report buffer
}
6. Keep These Notes in Mind
- All reporting methods are static — no instance creation is needed.
- Error messages are deduplicated and counted using
errorList. - Shared memory allows external inspection of the simulation report buffer.