Class: fcf::NTest::Logger
Package: fcfTest
File:
test.hpp
(
link_to_the_declaration_in_the_file
,
link_to_the_implementation_in_the_file
)
Available from version: 1.0.4
Returns or sets a new log level value in string format
Data Return Mode:
Returns a pointer to a static string representing the current log level name
The
levelStr() method converts the current
fcf::NTest::ELogLevel of the logger into its human-readable string representation (
"off",
"ftl",
"err",
"wrn",
"att",
"log",
"inf",
"dbg",
"trc",
"all"). This is useful for logging the current verbosity level or for debugging the logger's state
Data Recording Mode:
Sets the logger's verbosity threshold using a string identifier (e.g., "dbg", "err")
The
levelStr method provides a convenient way to adjust the logging threshold at runtime using human-readable string identifiers. It internally maps the provided string to the corresponding
fcf::NTest::ELogLevel enumeration
Arguments
cons char* a_level
- A pointer to a null-terminated string representing the desired log level. Valid identifiers include: "off", "ftl", "err", "wrn", "att", "log", "inf", "dbg", "trc", "all".
Result
const char*
- A pointer to a static string containing the level name
Example: Printing the current log level
fcf::NTest::logger().levelStr("dbg");
std::cout << "Current log level: " << fcf::NTest::logger().levelStr() << std::endl;
// Output: Current log level: dbg
Example: Using within a custom prefix
fcf::NTest::logger().appendPrefixFunc([]( fcf::NTest::Logger& a_logger, fcf::NTest::Logger::MessageContext& a_messageContext) {
return "[" + fcf::NTest::Logger::toLevelStr(a_messageContext.level) + "] ";
});
fcf::NTest::log() << "Message with level in prefix." << std::endl;
Example: Simple recording
Switching the logger to debug mode using a string.
// Set level to Debug
fcf::NTest::logger().levelStr("dbg");
fcf::NTest::dbg() << "Debug information is now visible." << std::endl;
Example: Integration with command-line logic
Commonly used when parsing configuration or command-line arguments to set verbosity
std::string userConfiguredLevel = "err";
fcf::NTest::logger().levelStr(userConfiguredLevel.c_str());
fcf::NTest::inf() << "This message will not be displayed.";
fcf::NTest::err() << "This message will be displayed.";