Skip to content
Dimo Markov edited this page Jul 11, 2024 · 12 revisions

Main Functions

Logging happens mainly through the following variadic functions, each with its distinct style:

Logger::Section

Logger::Section(...);

Output:

image

Logger::Fatal

Logger::Fatal(...);
Logger::FatalTab(...);

Output:

image

Logger::Error

Logger::Error(...);
Logger::ErrorTab(...);

Output:

image

Logger::Warning

Logger::Warning(...);
Logger::WarningTab(...);

Output:

image

Logger::Verbose

Logger::Verbose(...);
Logger::VerboseTab(...);

Output:

image

Logger::Info

Logger::Info(...);
Logger::InfoTab(...);

Output:

image

Logger::Message

Logger::Message(...);
Logger::MessageTab(...);

Output:

image

Logger::Special

Logger::Special(...);
Logger::SpecialTab(...);

Output:

image

Logger::Flow

Logger::Flow(...);
Logger::FlowTab(...);

Output:

image

Logger::Input

Logger::Input(...);
Logger::InputTab(...);

Output:

image

Logger::Network

Logger::Network(...);
Logger::NetworkTab(...);

Output:

image

Logger::OS

Logger::OS(...);
Logger::OSTab(...);

Output:

image

Logger::Prompt

Logger::Prompt(...);
Logger::PromptTab(...);

Output:

image

Secondary Functions

Additionally, there are a couple of context-dependent calls, that don't modify styling:

Logger::Line

Logger::Line(...)

Logger::Append

Logger::Append(...)

Text arguments

All of the mentioned functions accept all string/character types, as well as types that are convertible to strings (either provided by you, or by {fmt} library). You can provide any number of arguments in two possible ways:

// Provided as variadic function arguments (recommended)
Logger::Special("The answer is ", 42, '!', " It's ", true, ", I tell ya!");
// Provided using std::cout style operator <<
Logger::Special() << "The answer is " << 42 << '!' << " It's " << true << ", I tell ya!";

Output:

image

Command arguments

Logger accepts some special arguments, that change the logging state, such as tabulation, color and style.

Colors

Here's a list of the available colors. These colors are encoded using ANSI/VT100 escape sequences, when logged into consoles, or HTML tags when logged in html files:

Logger::NoForeground // Sets foreground color to the default
Logger::NoBackground // Sets background color to the default

// Foreground colors:
Logger::Black
Logger::DarkRed
Logger::DarkGreen
Logger::DarkYellow
Logger::DarkBlue
Logger::DarkPurple
Logger::DarkCyan
Logger::Gray
Logger::DarkGray
Logger::Red
Logger::Green
Logger::Yellow
Logger::Blue
Logger::Purple
Logger::Cyan
Logger::White

// Background colors
Logger::BlackBgr
Logger::DarkRedBgr
Logger::DarkGreenBgr
Logger::DarkYellowBgr
Logger::DarkBlueBgr
Logger::DarkPurpleBgr
Logger::DarkCyanBgr
Logger::GrayBgr
Logger::DarkGrayBgr
Logger::RedBgr
Logger::GreenBgr
Logger::YellowBgr
Logger::BlueBgr
Logger::PurpleBgr
Logger::CyanBgr
Logger::WhiteBgr

You can set colors, by providing the appropriate value as an argument:

{
   auto scope = Logger::Section(Logger::Reset, "Now testing foreground colors: ");
   Logger::Line(Logger::Black, "Black, ", Logger::Blue, "Blue, ", Logger::Cyan, "Cyan, ", Logger::DarkBlue, "Dark blue, ");
   Logger::Line(Logger::DarkCyan, "Dark cyan, ", Logger::DarkGray, "Dark gray, ", Logger::DarkGreen, "Dark green, ", Logger::DarkPurple, "Dark purple, ");
   Logger::Line(Logger::DarkRed, "Dark red, ", Logger::DarkYellow, "Dark yellow, ", Logger::Gray, "Gray, ", Logger::Green, "Green, ");
   Logger::Line(Logger::Purple, "Purple, ", Logger::Red, "Red, ", Logger::White, "White, ", Logger::Yellow, "Yellow, ");
}
{
   auto scope = Logger::Section(Logger::Reset, "Now testing background colors: ");
   Logger::Line(Logger::BlackBgr, "Black, ", Logger::BlueBgr, "Blue, ", Logger::CyanBgr, "Cyan, ", Logger::DarkBlueBgr, "Dark blue, ");
   Logger::Line(Logger::DarkCyanBgr, "Dark cyan, ", Logger::DarkGrayBgr, "Dark gray, ", Logger::DarkGreenBgr, "Dark green, ", Logger::DarkPurpleBgr, "Dark purple, ");
   Logger::Line(Logger::DarkRedBgr, "Dark red, ", Logger::DarkYellowBgr, "Dark yellow, ", Logger::GrayBgr, "Gray, ", Logger::GreenBgr, "Green, ");
   Logger::Line(Logger::PurpleBgr, "Purple, ", Logger::RedBgr, "Red, ", Logger::WhiteBgr, "White, ", Logger::YellowBgr, "Yellow, ");
}

Output:

image

Clone this wiki locally