Provides logging utilities, either to the standard/error output or to a file, with multiple criticality levels.
More...
#include <Logger.hpp>
|
enum | Domain {
GPU = 0
, Resources
, Input
, Utilities
,
Config
} |
| Domain prefix that will be appended before a line.
|
|
|
const std::vector< std::string > | _domainStrings = {"GPU", "Resources", "Input", "Utilities", "Config"} |
| Domain prefix strings.
|
|
const std::vector< std::string > | _levelStrings = {"", "(!) ", "(X) ", ""} |
| Levels prefix strings.
|
|
const std::vector< std::string > | _colorStrings = {"\x1B[0m\x1B[39m", "\x1B[0m\x1B[33m", "\x1B[0m\x1B[31m", "\x1B[2m\x1B[37m"} |
| Colors prefix strings.
|
|
Level | _level = Level::INFO |
| The current criticality level.
|
|
bool | _logToStdOut = true |
| Should the logs be output to standard output.
|
|
std::ofstream | _file |
| The output log file stream.
|
|
std::stringstream | _stream |
| Internal log string stream.
|
|
bool | _verbose = false |
| Is the logger verbose.
|
|
bool | _ignoreUntilFlush = false |
| Internal flag to ignore the current line if it is verbose.
|
|
bool | _appendPrefix = false |
| Should a domain or level prefix be appended to the current line.
|
|
bool | _useColors = false |
| Should color formatting be used.
|
|
|
static Log * | _defaultLogger = new Log() |
| Default static logger.
|
|
Provides logging utilities, either to the standard/error output or to a file, with multiple criticality levels.
◆ Level
Criticality level.
Enumerator |
---|
VERBOSE | Will only be logged if verbose is enabled.
|
◆ Log() [1/2]
Default constructor, will use standard output
◆ Log() [2/2]
Log::Log |
( |
const std::string & |
filePath, |
|
|
bool |
logToStdin, |
|
|
bool |
verbose = false |
|
) |
| |
Constructor
- Parameters
-
filePath | the file to write the logs to |
logToStdin | should the logs also be sent to the standard output |
verbose | should verbose messages be output |
◆ appendIfNeeded()
void Log::appendIfNeeded |
( |
| ) |
|
|
private |
Append the current domain/level prefix if it is needed.
◆ Error()
The default logger with an "Error" level.
- Returns
- itself for chaining
◆ flush()
◆ Info()
The default logger with an "Info" level.
- Returns
- itself for chaining
◆ operator<<() [1/4]
Log & Log::operator<< |
( |
const Domain & |
domain | ) |
|
Domain stream operator
- Parameters
-
domain | the domain to use for the next log line |
- Returns
- itself for chaining
- Note
- The domain is only applied to the incoming line.
◆ operator<<() [2/4]
template<class T >
Log & Log::operator<< |
( |
const T & |
input | ) |
|
|
inline |
Default stream operator
- Parameters
-
- Returns
- itself for chaining
◆ operator<<() [3/4]
Log & Log::operator<< |
( |
std::ios_base &(*)(std::ios_base &) |
modif | ) |
|
Modifier stream operator
- Parameters
-
- Returns
- itself for chaining
◆ operator<<() [4/4]
Log & Log::operator<< |
( |
std::ostream &(*)(std::ostream &) |
modif | ) |
|
Modifier stream operator
- Parameters
-
- Returns
- itself for chaining
◆ set()
Set the criticality level.
- Parameters
-
- Note
- Level is not modified directly, but through the use of Log::Info, Log::Error, etc., mimicking std::cout and std::cerr.
◆ setDefaultFile()
void Log::setDefaultFile |
( |
const std::string & |
filePath | ) |
|
|
static |
Set the default logger output file.
- Parameters
-
filePath | the path to the output file |
◆ setDefaultVerbose()
void Log::setDefaultVerbose |
( |
bool |
verbose | ) |
|
|
static |
Set the default logger verbosity.
- Parameters
-
◆ setFile()
void Log::setFile |
( |
const std::string & |
filePath, |
|
|
bool |
flushExisting = true |
|
) |
| |
|
private |
Change the output log file.
- Parameters
-
filePath | the file to write the logs to |
flushExisting | should the existing unwritten messages be flushed |
◆ setVerbose()
void Log::setVerbose |
( |
bool |
verbose | ) |
|
Set the verbosity level.
- Parameters
-
◆ Verbose()
The default logger with a verbose level.
- Returns
- itself for chaining
◆ Warning()
The default logger with a "Warning" level.
- Returns
- itself for chaining
The documentation for this class was generated from the following files:
- src/engine/system/Logger.hpp
- src/engine/system/Logger.cpp