JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
BufferLogger Class Reference

Detailed Description

Definition at line 59 of file FGLog.cpp.

+ Inheritance diagram for BufferLogger:
+ Collaboration diagram for BufferLogger:

Public Member Functions

const char * c_str (void) const noexcept
 
void FileLocation (const std::string &filename, int line) override
 Optionally provides source filename and line for contextual diagnostics.
 
void Format (LogFormat format) override
 Applies a formatting hint to subsequent output.
 
void Message (const std::string &message) override
 Appends message text. May be called multiple times per log record.
 
- Public Member Functions inherited from FGLogger
virtual ~FGLogger ()
 Virtual destructor for polymorphic use.
 
virtual void Flush (void)
 Ends the current log record and commits any buffered output.
 
virtual void SetLevel (LogLevel level)
 Starts a new log record and provides its severity level.
 

Additional Inherited Members

- Protected Attributes inherited from FGLogger
LogLevel log_level = LogLevel::BULK
 

Constructor & Destructor Documentation

◆ BufferLogger()

BufferLogger ( )
inline

Definition at line 62 of file FGLog.cpp.

62{ logMessageBuffer[0] = '\0'; }

◆ ~BufferLogger()

~BufferLogger ( )
override

Definition at line 116 of file FGLog.cpp.

117{
118 if (tokens.empty()) return;
119
120 GlobalLogger->SetLevel(log_level);
121
122 if (line > 0) GlobalLogger->FileLocation(filename, line);
123
124 for (const auto& token : tokens) {
125 if (token.messageItem.empty()) {
126 GlobalLogger->Format(token.format);
127 continue;
128 }
129 GlobalLogger->Message(std::string(token.messageItem));
130 }
131 GlobalLogger->Flush();
132}

Member Function Documentation

◆ c_str()

const char * c_str ( void  ) const
inlinenoexcept

Definition at line 69 of file FGLog.cpp.

69{ return logMessageBuffer; }

◆ FileLocation()

void FileLocation ( const std::string &  filename,
int  line 
)
inlineoverridevirtual

Optionally provides source filename and line for contextual diagnostics.

Reimplemented from FGLogger.

Definition at line 63 of file FGLog.cpp.

63 {
64 this->filename = filename;
65 this->line = line;
66 }

◆ Format()

void Format ( LogFormat  format)
overridevirtual

Applies a formatting hint to subsequent output.

Reimplemented from FGLogger.

Definition at line 108 of file FGLog.cpp.

109{
110 auto& new_token = tokens.emplace_back();
111 new_token.format = format;
112}

◆ Message()

void Message ( const std::string &  message)
overridevirtual

Appends message text. May be called multiple times per log record.

Implements FGLogger.

Definition at line 88 of file FGLog.cpp.

88 {
89 if (message.empty()) return;
90
91 size_t available = sizeof(logMessageBuffer) - bufferUsed - 1; // -1 for null terminator
92 size_t toCopy = std::min(message.size(), available); // Prevent buffer overflow
93
94 if (toCopy > 0) {
95 // Copy the message to the buffer
96 char* currentPos = logMessageBuffer + bufferUsed;
97 memcpy(currentPos, message.c_str(), toCopy);
98 bufferUsed += toCopy;
99 logMessageBuffer[bufferUsed] = '\0';
100 // Store the message in the tokens vector
101 auto& new_token = tokens.emplace_back();
102 new_token.messageItem = std::string_view(currentPos, toCopy);
103 }
104}

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