Gorgon Game Engine
Logger Class Reference

Eases logging procedure by appending necessary information to the given data and streams to a standard c++ stream. More...

Public Types

enum  State { Message, Error, Notice, Success }
 

Public Member Functions

 Logger (bool marktime, bool markdate=false)
 
 Logger (const char *section, bool marktime=true, bool markdate=false)
 Default constructor. Allows you to specify a section. More...
 
 Logger (const std::string &section="", bool marktime=true, bool markdate=false)
 Default constructor. Allows you to specify a section. More...
 
 Logger (std::ostream &stream, const std::string &section="", bool marktime=true, bool markdate=false)
 
 ~Logger ()
 
void CleanUp ()
 Cleans the stream. More...
 
void DisableColor ()
 Disable color output. More...
 
void EnableColor ()
 Enables color support, however, if the underlying stream does not allow coloring this will not have any effect. More...
 
bool GetMarkDate () const
 Returns whether date is being marked. More...
 
bool GetMarkTime () const
 Returns whether time is being marked. More...
 
std::string GetSection () const
 Returns the current section of this logger. More...
 
void InitializeConsole ()
 
void InitializeFile (const std::string &filename)
 Opens and initializer the logger using the given filename. More...
 
void InitializeStream (std::ostream &stream)
 Initializes the logger to direct its input to the given stream. More...
 
bool IsColorEnabled () const
 Whether color is enabled, a value of true is not a warranty that color output is working, use IsColorFunctional to make sure. More...
 
bool IsColorFunctional () const
 Returns whether the color output is currently working. More...
 
template<class T_ >
helper Log (const T_ &v, State state=Error)
 Streams out the given value to the underlying stream. More...
 
template<class T_ >
helper operator<< (const T_ &v)
 Streams out the given value to the underlying stream. More...
 
void SetColorEnabled (bool value)
 Sets color enabled state. More...
 
void SetMarkDate (bool value)
 Sets whether to mark the date on log output. More...
 
void SetMarkTime (bool value)
 Sets whether to mark the time on log output. More...
 
void SetSection (const std::string &value)
 Sets the section of this logger. More...
 
void SetWidth (int width)
 Sets the width to break lines from. Set to 0 to disable. More...
 

Protected Member Functions

void reset (std::ostream &stream)
 

Protected Attributes

bool color
 
Console console
 
bool hasconsole
 
bool markdate
 
bool marktime
 
bool owner
 
std::string section
 
std::ostream * stream
 
int width
 

Detailed Description

Eases logging procedure by appending necessary information to the given data and streams to a standard c++ stream.

The log entries are prettified by indentation. The width of the output is determined for consoles, if not, 80 will be used as default. The lines for streams will not be broken automatically, unless a SetWidth function is called.

Member Enumeration Documentation

◆ State

enum State
Enumerator
Message 
Error 
Notice 
Success 

Constructor & Destructor Documentation

◆ Logger() [1/4]

Logger ( const std::string &  section = "",
bool  marktime = true,
bool  markdate = false 
)

Default constructor. Allows you to specify a section.

◆ Logger() [2/4]

Logger ( const char *  section,
bool  marktime = true,
bool  markdate = false 
)

Default constructor. Allows you to specify a section.

◆ Logger() [3/4]

Logger ( bool  marktime,
bool  markdate = false 
)

◆ Logger() [4/4]

Logger ( std::ostream &  stream,
const std::string &  section = "",
bool  marktime = true,
bool  markdate = false 
)

◆ ~Logger()

~Logger ( )

References Logger::CleanUp().

Member Function Documentation

◆ CleanUp()

void CleanUp ( )

Cleans the stream.

If it is built by this object, it will be destroyed. After this point nothing will be logged.

References Logger::console, Logger::owner, and Logger::stream.

◆ DisableColor()

void DisableColor ( )

Disable color output.

References Logger::color.

◆ EnableColor()

void EnableColor ( )

Enables color support, however, if the underlying stream does not allow coloring this will not have any effect.

You may use ForceColor to output color coding to a device that does not support color.

References Logger::color.

◆ GetMarkDate()

bool GetMarkDate ( ) const

Returns whether date is being marked.

References Logger::markdate.

◆ GetMarkTime()

bool GetMarkTime ( ) const

Returns whether time is being marked.

References Logger::marktime.

◆ GetSection()

std::string GetSection ( ) const

Returns the current section of this logger.

References Logger::section.

◆ InitializeConsole()

void InitializeConsole ( )

◆ InitializeFile()

void InitializeFile ( const std::string &  filename)

Opens and initializer the logger using the given filename.

The file will automatically be closed when CleanUp is performed.

References Logger::CleanUp(), Logger::owner, and Logger::stream.

◆ InitializeStream()

void InitializeStream ( std::ostream &  stream)

Initializes the logger to direct its input to the given stream.

Ownership is not transferred

References Logger::CleanUp(), Logger::owner, and Logger::stream.

◆ IsColorEnabled()

bool IsColorEnabled ( ) const

Whether color is enabled, a value of true is not a warranty that color output is working, use IsColorFunctional to make sure.

References Logger::color.

◆ IsColorFunctional()

bool IsColorFunctional ( ) const

Returns whether the color output is currently working.

References Logger::color, Logger::console, Logger::hasconsole, and Console::IsColorSupported().

◆ Log()

helper Log ( const T_ &  v,
State  state = Error 
)

Streams out the given value to the underlying stream.

This function will automatically add requested information in front. Always cascade entries. Every time a new logger << ... is called, header information will be printed out. You may use std::endl in your logs, but a new line will be added for all entries. An extra empty line will be inserted for multiline entries. Do not use "\n" as it will not be detected. ,

logger.Log("Unexpected error: ", Utils::Logger::Error)<<ex.what();

References Logger::console, Gorgon::Graphics::Color::Cyan, Logger::Error, Logger::helper, Logger::IsColorFunctional(), Logger::markdate, Logger::marktime, Logger::Message, Date::Now(), Logger::reset(), Logger::section, Console::SetBold(), Console::SetColor(), Logger::stream, and Logger::width.

◆ operator<<()

helper operator<< ( const T_ &  v)

Streams out the given value to the underlying stream.

This function will automatically add requested information in front. Always cascade entries. Every time a new logger << ... is called, header information will be printed out. You may use std::endl in your logs, but a new line will be added for all entries. An extra empty line will be inserted for multiline entries. Do not use "\n" as it will not be detected. Message state is used for this case.

References Logger::Log(), and Logger::Message.

◆ reset()

void reset ( std::ostream &  stream)
protected

◆ SetColorEnabled()

void SetColorEnabled ( bool  value)

Sets color enabled state.

If color is enabled and the underlying stream does not allow coloring setting coloring to true will not have any effect. You may use ForceColor to output color coding to a device that does not support color.

References Logger::color.

◆ SetMarkDate()

void SetMarkDate ( bool  value)

Sets whether to mark the date on log output.

References Logger::markdate.

◆ SetMarkTime()

void SetMarkTime ( bool  value)

Sets whether to mark the time on log output.

References Logger::marktime.

◆ SetSection()

void SetSection ( const std::string &  value)

Sets the section of this logger.

References Logger::section.

◆ SetWidth()

void SetWidth ( int  width)

Sets the width to break lines from. Set to 0 to disable.

References Logger::width.

Member Data Documentation

◆ color

bool color
protected

◆ console

Console console
protected

◆ hasconsole

bool hasconsole
protected

◆ markdate

bool markdate
protected

◆ marktime

bool marktime
protected

◆ owner

bool owner
protected

◆ section

std::string section
protected

◆ stream

std::ostream* stream
protected

◆ width

int width
protected

The documentation for this class was generated from the following file:
Gorgon::Utils::Logger::Error
@ Error
Definition: Logging.h:110