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

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

fcf::NTest::Logger::Formats formats()
void formats(fcf::NTest::Logger::Formats a_formats)

Class: fcf::NTest::Logger

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Provides access to the current collection of formatting configurations.

The formats method provides access to the current list of fcf::NTest::Logger::Format objects configured in the logger.

This method has two distinct behaviors depending on whether it is used for reading or writing:

  • Read Mode: When called without arguments, it returns a copy of the current list of formats (fcf::NTest::Logger::Formats). This is useful for inspecting which output formats are currently active.
  • Write Mode: When called with a fcf::NTest::Logger::Formats object as an argument, it replaces the existing collection of formats with the provided one.

Arguments

fcf::NTest::Logger::Formats a_formats
- The new collection of formats to be set in the logger.
Result
fcf::NTest::Logger::Formats
- A copy of the current list of formats.

Example: Reading and Replacing Formats

Demonstrating how to retrieve the current formats and then replace them with a new custom configuration.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DECLARE("FormatDemo", "Logger", "FormatsAccessTest") { fcf::NTest::Logger& logger = fcf::NTest::logger(); // 1. Retrieve the current formats (Read Mode) fcf::NTest::Logger::Formats currentFormats = logger.formats(); fcf::NTest::log() << "Default number of formats: " << currentFormats.size() << std::endl; // 2. Create a new set of formats fcf::NTest::Logger::Format newFormat; newFormat.name = "custom-format"; // Note: handler and dataFactory would be set here in a real scenario fcf::NTest::Logger::Formats newFormats(currentFormats); newFormats.push_back(newFormat); // 3. Replace the existing formats (Write Mode) logger.formats(newFormats); // 4. Display the current list of formats fcf::NTest::log() << "New formats:" << std::endl; for(const fcf::NTest::Logger::Format& format : logger.formats()){ fcf::NTest::log() << " - "<< format.name << std::endl; } fcf::NTest::log() << "This message uses the new format configuration." << std::endl; FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

Performing the test: "FormatDemo" -> "Logger" -> "FormatsAccessTest" ... > Default number of formats: 1 > New formats: > - junit > - custom-format > This message uses the new format configuration. [SUCCESS] Test completed successfully (0.000`019`888 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`019`888 sec

The formats method effectively allows both inspection and complete reconfiguration of the logger's output formatting rules.