Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Log Class Reference

Provides logging utilities, either to the standard/error output or to a file, with multiple criticality levels. More...

#include <Logger.hpp>

Public Types

enum  Domain {
  GPU = 0 , Resources , Input , Utilities ,
  Config
}
 Domain prefix that will be appended before a line.
 

Public Member Functions

 Log ()
 
 Log (const std::string &filePath, bool logToStdin, bool verbose=false)
 
void setVerbose (bool verbose)
 
template<class T >
Logoperator<< (const T &input)
 
Logoperator<< (const Domain &domain)
 
Logoperator<< (std::ostream &(*modif)(std::ostream &))
 
Logoperator<< (std::ios_base &(*modif)(std::ios_base &))
 

Static Public Member Functions

Default logger
static void setDefaultFile (const std::string &filePath)
 
static void setDefaultVerbose (bool verbose)
 
static LogInfo ()
 
static LogWarning ()
 
static LogError ()
 
static LogVerbose ()
 

Private Types

enum class  Level : int { INFO = 0 , WARNING , ERROR , VERBOSE }
 Criticality level. More...
 

Private Member Functions

void set (Level l)
 
void setFile (const std::string &filePath, bool flushExisting=true)
 
void flush ()
 
void appendIfNeeded ()
 

Private Attributes

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 Private Attributes

static Log_defaultLogger = new Log()
 Default static logger.
 

Detailed Description

Provides logging utilities, either to the standard/error output or to a file, with multiple criticality levels.

Member Enumeration Documentation

◆ Level

enum class Log::Level : int
strongprivate

Criticality level.

Enumerator
VERBOSE 

Will only be logged if verbose is enabled.

Constructor & Destructor Documentation

◆ Log() [1/2]

Log::Log ( )

Default constructor, will use standard output

◆ Log() [2/2]

Log::Log ( const std::string &  filePath,
bool  logToStdin,
bool  verbose = false 
)

Constructor

Parameters
filePaththe file to write the logs to
logToStdinshould the logs also be sent to the standard output
verboseshould verbose messages be output

Member Function Documentation

◆ appendIfNeeded()

void Log::appendIfNeeded ( )
private

Append the current domain/level prefix if it is needed.

◆ Error()

Log & Log::Error ( )
static

The default logger with an "Error" level.

Returns
itself for chaining

◆ flush()

void Log::flush ( )
private

Flush the log stream.

◆ Info()

Log & Log::Info ( )
static

The default logger with an "Info" level.

Returns
itself for chaining

◆ operator<<() [1/4]

Log & Log::operator<< ( const Domain domain)

Domain stream operator

Parameters
domainthe 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
inputthe object to log
Returns
itself for chaining

◆ operator<<() [3/4]

Log & Log::operator<< ( std::ios_base &(*)(std::ios_base &)  modif)

Modifier stream operator

Parameters
modifthe stream modifier
Returns
itself for chaining

◆ operator<<() [4/4]

Log & Log::operator<< ( std::ostream &(*)(std::ostream &)  modif)

Modifier stream operator

Parameters
modifthe stream modifier
Returns
itself for chaining

◆ set()

void Log::set ( Level  l)
private

Set the criticality level.

Parameters
lthe new level
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
filePaththe path to the output file

◆ setDefaultVerbose()

void Log::setDefaultVerbose ( bool  verbose)
static

Set the default logger verbosity.

Parameters
verbosetoggle verbosity

◆ setFile()

void Log::setFile ( const std::string &  filePath,
bool  flushExisting = true 
)
private

Change the output log file.

Parameters
filePaththe file to write the logs to
flushExistingshould the existing unwritten messages be flushed

◆ setVerbose()

void Log::setVerbose ( bool  verbose)

Set the verbosity level.

Parameters
verbosetoggle verbosity

◆ Verbose()

Log & Log::Verbose ( )
static

The default logger with a verbose level.

Returns
itself for chaining

◆ Warning()

Log & Log::Warning ( )
static

The default logger with a "Warning" level.

Returns
itself for chaining

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