FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

appendFormat() method from fcf::NTest::Logger class

void appendFormat(const fcf::NTest::Logger::Format& a_format)

Class: fcf::NTest::Logger

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Adds a new formatting configuration to the logger.

The appendFormat method allows you to add a new fcf::NTest::Logger::Format to the logger's current collection of formats.

If a format with the same name already exists in the logger, the existing configuration will be updated with the new settings. If no format with the matching name is found, a new format entry is created and added to the list.

Arguments

const fcf::NTest::Logger::Format& a_format
- The format configuration to be added or updated in the logger.

Example: Adding and Updating a Format

Demonstrating how to add a new format and then update its configuration using the same name.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DECLARE("FormatDemo", "Logger", "AppendFormatTest") { FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { fcf::NTest::Logger& logger = fcf::NTest::logger(); // 1. Create a new format fcf::NTest::Logger::Format customFormat; customFormat.name = "my-custom-format"; customFormat.handler = []( fcf::NTest::Logger&, fcf::NTest::Logger::MessageContext& a_context) { a_context.message = "[message: " + (std::stringstream() << std::hex << a_context.category).str() + "]\n"; }; // 2. Add the format to the logger logger.appendFormat(customFormat); // 3. Verify by checking the list of formats fcf::NTest::log() << "Formats before update: " << logger.formats().size() << std::endl; // 4. Update the existing format by using the same name customFormat.name = "my-custom-format"; // (Updating other properties if needed) logger.appendFormat(customFormat); // 5. Verify the update fcf::NTest::log() << "Formats after update: " << logger.formats().size() << std::endl; bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

> Formats before update: 2 > Formats after update: 2 Performing the test: "FormatDemo" -> "Logger" -> "AppendFormatTest" ... [SUCCESS] Test completed successfully (0.000`000`165 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`000`165 sec

Launching an application with a custom format:

app --test-format "my-custom-format"

Output:

> Formats before update: 2 > Formats after update: 2 [message: 20002] [message: 40001] [message: 10008] [message: 10003] [message: 10005] [message: 10006]

The appendFormat method ensures that formats are managed by their unique name, allowing for easy updates without needing to clear the entire collection.