Serenity Logger
A very fast and effiecient logging library. This library currently can log to files, rotate files when logging, log to the terminal, and is aware if the terminal is being piped during logging.
|
This class is in charge of logging to the terminal and supports color logging and the ability to log without color.
This class inherits from the TargetBase class for common logging functions and logging settings.
More...
Public Member Functions | |
ColorConsole () | |
Default constructor that will set the logger name to "Console_Logger". All other settings will be set to their defaults. | |
ColorConsole (std::string_view name) | |
Constructor that will set the logger name to the parameter name passed in. All other settings will be set to their defaults. More... | |
ColorConsole (std::string_view name, std::string_view msgPattern) | |
Constructor that will set the logger name to the parameter name passed in and set the format pattern via the parameter msgPattern passed in. All other settings will be set to their defaults. More... | |
~ColorConsole () | |
If the output wasn't directed to a terminal, will flush the contents to disk. More... | |
std::string_view | GetMsgColor (LoggerLevel level) |
Returns the log level based color for the current message to use. More... | |
void | SetMsgColor (LoggerLevel level, std::string_view color) |
Sets color specified for the log level specified. More... | |
void | SetConsoleInterface (console_interface mode) |
Sets console mode. Console modes mirror standard outputs. More... | |
const console_interface | ConsoleInterface () |
Returns the current console mode being used. | |
void | ColorizeOutput (bool colorize) |
Enables/Disables colored text output. | |
void | SetOriginalColors () |
Initializes the default colors to use for the log levels. More... | |
bool | IsTerminalType () |
Checks to see if output handle is referring to a terminal type device or not. More... | |
bool | IsValidHandle () |
Checks to see if output handle is valid and not empty. More... | |
void | PrintMessage (std::string_view formatted) override |
Outputs the message (formatted ) to the destination output device. More... | |
void | SetFlushPolicy (serenity::experimental::Flush_Policy pPolicy) |
Sets the current policy in use to defer to the policy passed in from "pPolicy". More... | |
serenity::experimental::Flush_Policy & | Policy () |
Returns the current policy in use. | |
const std::string | LoggerName () |
Returns the logger's name. | |
void | SetPattern (std::string_view pattern) |
Calls the handle to the Message_Formatter's SetPattern( ) function. More... | |
void | ResetPatternToDefault () |
Resets the current format pattern in use to the default format pattern. | |
void | SetLogLevel (LoggerLevel level) |
Sets the log level that messages should be logged at. More... | |
void | WriteToBaseBuffer (bool fmtToBuf=true) |
Enables/Disables writing to a buffer. More... | |
bool | isWriteToBuf () |
Returns true if buffer writes are enabled and false if they are disabled. | |
std::string * | Buffer () |
Returns a pointer to the buffer container. | |
const LoggerLevel | Level () |
Returns the current log level setting (the threshold of whether to log a message or not). | |
void | SetLoggerName (std::string_view name) |
Sets the name of the logger. More... | |
template<typename... Args> | |
void | Trace (std::string_view msg, Args &&...args) |
Logs a message giving the message a LoggerLevel::trace setting. More... | |
template<typename... Args> | |
void | Info (std::string_view msg, Args &&...args) |
Logs a message giving the message a LoggerLevel::info setting. More... | |
template<typename... Args> | |
void | Debug (std::string_view msg, Args &&...args) |
Logs a message giving the message a LoggerLevel::debug setting. More... | |
template<typename... Args> | |
void | Warn (std::string_view msg, Args &&...args) |
Logs a message giving the message a LoggerLevel::warning setting. More... | |
template<typename... Args> | |
void | Error (std::string_view msg, Args &&...args) |
Logs a message giving the message a LoggerLevel::error setting. More... | |
template<typename... Args> | |
void | Fatal (std::string_view msg, Args &&...args) |
Logs a message giving the message a LoggerLevel::fatal setting. More... | |
Protected Member Functions | |
virtual void | PolicyFlushOn () |
Virtual function that can be omitted if derived class has no need to implement and is used to handle how and when the derived target should flush its contents to disk. More... | |
msg_details::Message_Formatter * | MsgFmt () |
Returns a pointer to the handle for the Message_Formatter class instance. | |
msg_details::Message_Info * | MsgInfo () |
Returns a pointer to the handle for the Message_Info class instance. | |
For all Console Target Constructors:
|
explicit |
name | the name that the logger itself will use and be identified by |
|
explicit |
name | the name that the logger itself will use and be identified by |
msgPattern | the format pattern that determines how the prepended text will be displayed before the log message |
serenity::targets::ColorConsole::~ColorConsole | ( | ) |
If on Windows platform, this function will also reset the console mode to default in order to to clear "ENABLE_VIRTUAL_TERMINAL_PROCESSING" flag.
|
inherited |
Checks if the message should be logged via the log level threshold setting. If it isn't, immediately returns. If the message should be logged, this function will then perform a quick check on whether or not writes to the buffer were enabled and will write to the buffer if they were. If writes to the buffers weren't enabled, then PrintMessage( ) will be called and the derived target handles how this is implemented. After writing the message, follows the derived target's PolicyFlushOn( ) implementation
msg | The message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter. |
args | Variadic placeholder for any number of and any type of arguments to use in substituion. |
|
inherited |
Checks if the message should be logged via the log level threshold setting. If it isn't, immediately returns. If the message should be logged, this function will then perform a quick check on whether or not writes to the buffer were enabled and will write to the buffer if they were. If writes to the buffers weren't enabled, then PrintMessage( ) will be called and the derived target handles how this is implemented. After writing the message, follows the derived target's PolicyFlushOn( ) implementation
msg | The message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter. |
args | Variadic placeholder for any number of and any type of arguments to use in substituion. |
|
inherited |
Checks if the message should be logged via the log level threshold setting. If it isn't, immediately returns. If the message should be logged, this function will then perform a quick check on whether or not writes to the buffer were enabled and will write to the buffer if they were. If writes to the buffers weren't enabled, then PrintMessage( ) will be called and the derived target handles how this is implemented. After writing the message, follows the derived target's PolicyFlushOn( ) implementation
msg | The message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter. |
args | Variadic placeholder for any number of and any type of arguments to use in substituion. |
std::string_view serenity::targets::ColorConsole::GetMsgColor | ( | LoggerLevel | level | ) |
level | the level used to recieve the color code for that level. Logger levels are trace, info, debug, warning, error, and fatal. |
level
passed in
|
inherited |
Checks if the message should be logged via the log level threshold setting. If it isn't, immediately returns. If the message should be logged, this function will then perform a quick check on whether or not writes to the buffer were enabled and will write to the buffer if they were. If writes to the buffers weren't enabled, then PrintMessage( ) will be called and the derived target handles how this is implemented. After writing the message, follows the derived target's PolicyFlushOn( ) implementation
msg | The message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter. |
args | Variadic placeholder for any number of and any type of arguments to use in substituion. |
bool serenity::targets::ColorConsole::IsTerminalType | ( | ) |
bool serenity::targets::ColorConsole::IsValidHandle | ( | ) |
|
inlineprotectedvirtualinherited |
Reimplemented in serenity::targets::FileTarget.
|
overridevirtual |
If output handle is valid, will write the message to the output. If color is enabled, will write the message in the color specified for the log level used if the output is to a terminal.
For windows, uses WriteConsole( ) unless the output is not a terminal (in which case, uses WriteFile( ) instead ).
formatted | The actual message in its entirety to send to the output destination. |
Implements serenity::targets::TargetBase.
void serenity::targets::ColorConsole::SetConsoleInterface | ( | console_interface | mode | ) |
For Windows, sets "ENABLE_VIRTUAL_TERMINAL_PROCESSING". (If not defined, a macro is used to define this value). For any other platfrom, sets the standard output to use.
The console_interface values (std_out, std_err, std_log) represent std::out, std::err, and std::clog respectively.
mode | Can be one of the following: console_interface::std_out, console_interface::std_err, or console_interface::std_log |
|
inherited |
pPolicy | refers to any settings that are added or changed by the user, including whether to flush always, never, or periodically. |
On top of having options to never flush, always flush, and periodically flush, the Flush_Policy class includes the settings for whether flushing should occur based on a time-interval or log level if the periodical flushing option is enabled.
|
inherited |
name | the name that the logger itself will use and be identified by |
|
inherited |
For example, if "SetLogLevel(LoggerLevel::Error);" is used, then no messages below LoggerLevel::Error will be logged, however once a Fatal or Error message is made, then they would be logged to the output destination
level | - the logger level threshold that will determine if a message should be logged or not |
void serenity::targets::ColorConsole::SetMsgColor | ( | LoggerLevel | level, |
std::string_view | color | ||
) |
level | The logger level to bind the color code to from color variable |
color | The color code to bind to the level passed in. This color code is expected to be an ansi code. |
void serenity::targets::ColorConsole::SetOriginalColors | ( | ) |
The default colors used are as follows:
Logger Level | Color Used |
---|---|
info | Bright Green On Black |
trace | Bright White On Black |
debug | Bright Cyan On Black |
warning | Bright Yellow On Black |
error | Basic Red On Black |
fatal | Bright Yellow On Red |
off | Reset To Default Terminal Colors |
|
inherited |
Sets the format pattern variable and parses the format string for internal storage and usage of this pattern by initializing and moving the initialized formatter struct in charge of the respective flag to a Formatters container
pattern | - the format pattern to store. This pattern is what determines how the prepended text will be displayed before the log message |
|
inherited |
Checks if the message should be logged via the log level threshold setting. If it isn't, immediately returns. If the message should be logged, this function will then perform a quick check on whether or not writes to the buffer were enabled and will write to the buffer if they were. If writes to the buffers weren't enabled, then PrintMessage( ) will be called and the derived target handles how this is implemented. After writing the message, follows the derived target's PolicyFlushOn( ) implementation
msg | The message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter. |
args | Variadic placeholder for any number of and any type of arguments to use in substituion. |
|
inherited |
Checks if the message should be logged via the log level threshold setting. If it isn't, immediately returns. If the message should be logged, this function will then perform a quick check on whether or not writes to the buffer were enabled and will write to the buffer if they were. If writes to the buffers weren't enabled, then PrintMessage( ) will be called and the derived target handles how this is implemented. After writing the message, follows the derived target's PolicyFlushOn( ) implementation
msg | The message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter. |
args | Variadic placeholder for any number of and any type of arguments to use in substituion. |
|
inherited |
When writing to the buffer, messages will be appended with the platform-specific end of line before being added to the buffer. When Flush( ) is called, if writing to the buffer was enabled, the buffer contents will now be written to the file and then flushed to disk. Disabled by default.
fmtToBuf | the value that controls whether or not buffer writes are enabled/disabled |