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.
serenity::targets::TargetBase Class Referenceabstract

The base class that derived target classes inherit from. Contains common functions between all targets for message logging and logging settings. More...

+ Inheritance diagram for serenity::targets::TargetBase:

Public Member Functions

 TargetBase ()
 Default constructor that sets the logger name to "Base_Target" and sets all other values to their defaults.
 
 TargetBase (std::string_view name)
 Constructor that will set the logger name to the name paramater passed in and all other values to their defaults. More...
 
 TargetBase (std::string_view name, std::string_view msgPattern)
 Constructor that will set the logger name to the name paramater passed in as well as the format pattern to the msgPattern passed in. All other values will be assigned their default values. 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_PolicyPolicy ()
 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 PrintMessage (std::string_view formatted)=0
 Pure virtual function that all derived classes must implement and is used to write the formatted message to a specific target. More...
 
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_FormatterMsgFmt ()
 Returns a pointer to the handle for the Message_Formatter class instance.
 
msg_details::Message_InfoMsgInfo ()
 Returns a pointer to the handle for the Message_Info class instance.
 

Detailed Description

For All TargetBase Constructors:
The following default values are set regardless of which constructor is used:

  • Flush Policy is set to "never".
  • Log Level is set to "LoggerLevel::trace".
  • Default pattern is set to "|%l| %x %n %T [%N]: %+" which translates to the form of:
    "|T| Sat 29Jan22 [Base_Logger]: The message to log".
  • Time mode used is set to "time_mode::local".

Constructor & Destructor Documentation

◆ TargetBase() [1/2]

serenity::targets::TargetBase::TargetBase ( std::string_view  name)
Parameters
namethe name that the logger itself will use and be identified by

◆ TargetBase() [2/2]

serenity::targets::TargetBase::TargetBase ( std::string_view  name,
std::string_view  msgPattern 
)
Parameters
namethe name that the logger itself will use and be identified by
msgPatternthe format pattern that determines how the prepended text will be displayed before the log message

Member Function Documentation

◆ Debug()

template<typename... Args>
serenity::targets::TargetBase::Debug ( std::string_view  msg,
Args &&...  args 
)

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

Template Parameters
msgThe message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter.
argsVariadic placeholder for any number of and any type of arguments to use in substituion.

◆ Error()

template<typename... Args>
serenity::targets::TargetBase::Error ( std::string_view  msg,
Args &&...  args 
)

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

Template Parameters
msgThe message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter.
argsVariadic placeholder for any number of and any type of arguments to use in substituion.

◆ Fatal()

template<typename... Args>
serenity::targets::TargetBase::Fatal ( std::string_view  msg,
Args &&...  args 
)

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

Template Parameters
msgThe message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter.
argsVariadic placeholder for any number of and any type of arguments to use in substituion.

◆ Info()

template<typename... Args>
serenity::targets::TargetBase::Info ( std::string_view  msg,
Args &&...  args 
)

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

Template Parameters
msgThe message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter.
argsVariadic placeholder for any number of and any type of arguments to use in substituion.

◆ PolicyFlushOn()

serenity::targets::TargetBase::PolicyFlushOn ( )
inlineprotectedvirtual

Reimplemented in serenity::targets::FileTarget.

◆ PrintMessage()

serenity::targets::TargetBase::PrintMessage ( std::string_view  formatted)
protectedpure virtual
Parameters
formattedThe actual message in its entirety to send to the output destination.

For built in targets, the message is formatted before reaching this point by calling Message_Info's SetMessage( ) function. PrintMessage( )'s intended usage is the last stop call before a log message is sent to its destination

Implemented in serenity::targets::ColorConsole, serenity::targets::FileTarget, and serenity::experimental::targets::RotatingTarget.

◆ SetFlushPolicy()

void serenity::targets::TargetBase::SetFlushPolicy ( serenity::experimental::Flush_Policy  pPolicy)
Parameters
pPolicyrefers 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.

◆ SetLoggerName()

void serenity::targets::TargetBase::SetLoggerName ( std::string_view  name)
Parameters
namethe name that the logger itself will use and be identified by

◆ SetLogLevel()

void serenity::targets::TargetBase::SetLogLevel ( LoggerLevel  level)

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

Parameters
level- the logger level threshold that will determine if a message should be logged or not

◆ SetPattern()

void serenity::targets::TargetBase::SetPattern ( std::string_view  pattern)

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

Parameters
pattern- the format pattern to store. This pattern is what determines how the prepended text will be displayed before the log message

◆ Trace()

template<typename... Args>
serenity::targets::TargetBase::Trace ( std::string_view  msg,
Args &&...  args 
)

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

Template Parameters
msgThe message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter.
argsVariadic placeholder for any number of and any type of arguments to use in substituion.

◆ Warn()

template<typename... Args>
serenity::targets::TargetBase::Warn ( std::string_view  msg,
Args &&...  args 
)

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

Template Parameters
msgThe message being passed in. Follows C++20's format library and libfmt's substitution model using "{}" to replace any arguments from the args parameter.
argsVariadic placeholder for any number of and any type of arguments to use in substituion.

◆ WriteToBaseBuffer()

void serenity::targets::TargetBase::WriteToBaseBuffer ( bool  fmtToBuf = true)

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.

Parameters
fmtToBufthe value that controls whether or not buffer writes are enabled/disabled

The documentation for this class was generated from the following files: