OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
WLogStream Class Reference

Class implementing a capsule for an output stream and the needed level and format information. More...

#include <WLogStream.h>

+ Collaboration diagram for WLogStream:

Public Types

typedef std::shared_ptr< WLogStreamSharedPtr
 shared pointer type More...
 
typedef WLogStreamPtr
 pointer type More...
 
typedef WLogStreamRef
 reference More...
 
typedef const WLogStreamConstRef
 const reference More...
 

Public Member Functions

 WLogStream (std::ostream &output, LogLevel logLevel=LL_DEBUG, std::string format="*%l [%s] %m \n", bool colored=true)
 Constructor. More...
 
void printEntry (const WLogEntry &entry)
 Prints the specified entry to the output stream in the right format if the log level matches. More...
 
void setLogLevel (LogLevel logLevel)
 Sets the new log level. More...
 
LogLevel getLogLevel () const
 Gets the currently set log level. More...
 
void setFormat (std::string format)
 Sets the format string. More...
 
std::string getFormat () const
 Returns the currently set format string. More...
 
void setColored (bool colors)
 Set whether to use colors or not. More...
 
bool isColored () const
 Getter determining whether to use colors or not. More...
 

Private Member Functions

 WLogStream (const WLogStream &rhs)
 Disallow copy. More...
 
WLogStreamoperator= (const WLogStream &rhs)
 Disallow assignment. More...
 

Private Attributes

std::ostream & m_output
 The output stream. More...
 
LogLevel m_logLevel
 The logging level. More...
 
std::string m_format
 The format of the message. More...
 
bool m_color
 True if colors should be used. More...
 

Detailed Description

Class implementing a capsule for an output stream and the needed level and format information.

Definition at line 38 of file WLogStream.h.

Member Typedef Documentation

◆ ConstRef

const reference

Definition at line 44 of file WLogStream.h.

◆ Ptr

pointer type

Definition at line 42 of file WLogStream.h.

◆ Ref

reference

Definition at line 43 of file WLogStream.h.

◆ SharedPtr

typedef std::shared_ptr< WLogStream > WLogStream::SharedPtr

shared pointer type

Definition at line 41 of file WLogStream.h.

Constructor & Destructor Documentation

◆ WLogStream() [1/2]

WLogStream::WLogStream ( std::ostream &  output,
LogLevel  logLevel = LL_DEBUG,
std::string  format = "*%l [%s] %m \n",
bool  colored = true 
)

Constructor.

Create a new stream instance. The output stream is a mandatory parameter. The others are predefined with some defaults.

Parameters
outputthe stream where to print log messages to
logLevellogging level, i.e. verboseness
formatthe format used for output
coloredtrue if coloring should be used.

Definition at line 30 of file WLogStream.cpp.

◆ WLogStream() [2/2]

WLogStream::WLogStream ( const WLogStream rhs)
private

Disallow copy.

Parameters
rhsthe stream to copy

Member Function Documentation

◆ getFormat()

std::string WLogStream::getFormat ( ) const

Returns the currently set format string.

Returns
format string.

Definition at line 66 of file WLogStream.cpp.

References m_format.

◆ getLogLevel()

LogLevel WLogStream::getLogLevel ( ) const

Gets the currently set log level.

Returns
the current log level

Definition at line 56 of file WLogStream.cpp.

References m_logLevel.

◆ isColored()

bool WLogStream::isColored ( ) const

Getter determining whether to use colors or not.

Returns
true if colors should be used.

Definition at line 76 of file WLogStream.cpp.

References m_color.

◆ operator=()

WLogStream& WLogStream::operator= ( const WLogStream rhs)
private

Disallow assignment.

Parameters
rhsthe stream to assign to this
Returns
this

◆ printEntry()

void WLogStream::printEntry ( const WLogEntry entry)

Prints the specified entry to the output stream in the right format if the log level matches.

Parameters
entrythe entry to print-

Definition at line 39 of file WLogStream.cpp.

References WLogEntry::getLogLevel(), WLogEntry::getLogString(), m_color, m_format, m_logLevel, and m_output.

+ Here is the call graph for this function:

◆ setColored()

void WLogStream::setColored ( bool  colors)

Set whether to use colors or not.

Note: this is only useful on Linux systems currently.

Parameters
colorstrue if colors should be used.

Definition at line 71 of file WLogStream.cpp.

References m_color.

◆ setFormat()

void WLogStream::setFormat ( std::string  format)

Sets the format string.

Parameters
formatthe format string.

Definition at line 61 of file WLogStream.cpp.

References m_format.

◆ setLogLevel()

void WLogStream::setLogLevel ( LogLevel  logLevel)

Sets the new log level.

All new incoming logs will be filtered according to this level.

Parameters
logLevelthe level

Definition at line 51 of file WLogStream.cpp.

References m_logLevel.

Member Data Documentation

◆ m_color

bool WLogStream::m_color
private

True if colors should be used.

This requires a compatible terminal.

Definition at line 140 of file WLogStream.h.

Referenced by isColored(), printEntry(), and setColored().

◆ m_format

std::string WLogStream::m_format
private

The format of the message.

Definition at line 135 of file WLogStream.h.

Referenced by getFormat(), printEntry(), and setFormat().

◆ m_logLevel

LogLevel WLogStream::m_logLevel
private

The logging level.

All messages below this level are discarded.

Definition at line 130 of file WLogStream.h.

Referenced by getLogLevel(), printEntry(), and setLogLevel().

◆ m_output

std::ostream& WLogStream::m_output
private

The output stream.

Definition at line 125 of file WLogStream.h.

Referenced by printEntry().


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