ZeroErr
zeroerr::LogStream Class Reference

LogStream is a class to manage the log messages. More...

#include <log.h>

Public Types

enum  FlushMode { FLUSH_AT_ONCE , FLUSH_WHEN_FULL , FLUSH_MANUALLY }
 
enum  LogMode { ASYNC , SYNC }
 
enum  DirMode { SINGLE_FILE = 0 , DAILY_FILE = 1 , SPLIT_BY_SEVERITY = 1 << 1 , SPLIT_BY_CATEGORY = 1 << 2 }
 

Public Member Functions

 LogStream ()
 
virtual ~LogStream ()
 
template<typename... T>
PushResult push (T &&... args)
 push a log message to the stream More...
 
template<typename T >
getLog (std::string func, unsigned line, std::string name)
 get a log message from the stream More...
 
template<typename T >
getLog (std::string func, std::string msg, std::string name)
 get a log message from the stream More...
 
LogIterator begin (std::string message="", std::string function_name="", int line=-1)
 
LogIterator end ()
 
LogIterator current (std::string message="", std::string function_name="", int line=-1)
 
void flush ()
 
void setFileLogger (std::string name, DirMode mode1=SINGLE_FILE, DirMode mode2=SINGLE_FILE, DirMode mode3=SINGLE_FILE)
 
void setStdoutLogger ()
 
void setStderrLogger ()
 
void setFlushAtOnce ()
 
void setFlushWhenFull ()
 
void setFlushManually ()
 
void setAsyncLog ()
 
void setSyncLog ()
 
FlushMode getFlushMode () const
 
void setFlushMode (FlushMode mode)
 
LogMode getLogMode () const
 
void setLogMode (LogMode mode)
 

Static Public Member Functions

static LogStreamgetDefault ()
 

Public Attributes

bool use_lock_free = true
 

Friends

class LogIterator
 

Detailed Description

LogStream is a class to manage the log messages.

LogStream is a class to manage the log messages. It can be used to create log messages and push them to the logger. A default LogStream is created when the first time you call getDefault() function (or first log happens). You can also adjust the way to flush the messages and how the log messages are written to the log file.

Member Enumeration Documentation

◆ DirMode

Enumerator
SINGLE_FILE 
DAILY_FILE 
SPLIT_BY_SEVERITY 
SPLIT_BY_CATEGORY 

◆ FlushMode

Enumerator
FLUSH_AT_ONCE 
FLUSH_WHEN_FULL 
FLUSH_MANUALLY 

◆ LogMode

Enumerator
ASYNC 
SYNC 

Constructor & Destructor Documentation

◆ LogStream()

zeroerr::LogStream::LogStream ( )

◆ ~LogStream()

zeroerr::LogStream::~LogStream ( )
virtual

Member Function Documentation

◆ begin()

LogIterator zeroerr::LogStream::begin ( std::string  message = "",
std::string  function_name = "",
int  line = -1 
)
inline

◆ current()

LogIterator zeroerr::LogStream::current ( std::string  message = "",
std::string  function_name = "",
int  line = -1 
)

◆ end()

LogIterator zeroerr::LogStream::end ( )
inline

◆ flush()

void zeroerr::LogStream::flush ( )

◆ getDefault()

LogStream & zeroerr::LogStream::getDefault ( )
static

◆ getFlushMode()

FlushMode zeroerr::LogStream::getFlushMode ( ) const
inline

◆ getLog() [1/2]

template<typename T >
T zeroerr::LogStream::getLog ( std::string  func,
std::string  msg,
std::string  name 
)
inline

get a log message from the stream

Template Parameters
TThe type of the log message
Parameters
funcThe function name of the log message
msgThe message of the log message
nameThe name of field you want to get

This function is used to get a log message from the stream and extract the field with the name. The function will return the field with the type T. However, this type must be specified by the caller.

◆ getLog() [2/2]

template<typename T >
T zeroerr::LogStream::getLog ( std::string  func,
unsigned  line,
std::string  name 
)
inline

get a log message from the stream

Template Parameters
TThe type of the log message
Parameters
funcThe function name of the log message
lineThe line number of the log message
nameThe name of field you want to get

This function is used to get a log message from the stream and extract the field with the name. The function will return the field with the type T. However, this type must be specified by the caller.

◆ getLogMode()

LogMode zeroerr::LogStream::getLogMode ( ) const
inline

◆ push()

template<typename... T>
PushResult zeroerr::LogStream::push ( T &&...  args)
inline

push a log message to the stream

Template Parameters
TThe types of the arguments
Parameters
argsThe arguments
Returns
PushResult The result of the push

This function is used to push a log message to the stream. You can pass any type of arguments to this function and it will create a log message with the arguments. The log message is not written to the log file until the stream is flushed.

The log message is structured as a tuple of the arguments in the inner implementation class LogMessageImpl. After the log message is created, it used type erasure to return a LogMessage pointer to the caller.

The stored data type is determined by the to_store_type_t<T> template. For all the string type in raw pointer like const char* or char[], it will be converted to std::string. All reference type (including right value reference) will be converted to the original type.

◆ setAsyncLog()

void zeroerr::LogStream::setAsyncLog ( )
inline

◆ setFileLogger()

void zeroerr::LogStream::setFileLogger ( std::string  name,
DirMode  mode1 = SINGLE_FILE,
DirMode  mode2 = SINGLE_FILE,
DirMode  mode3 = SINGLE_FILE 
)

◆ setFlushAtOnce()

void zeroerr::LogStream::setFlushAtOnce ( )
inline

◆ setFlushManually()

void zeroerr::LogStream::setFlushManually ( )
inline

◆ setFlushMode()

void zeroerr::LogStream::setFlushMode ( FlushMode  mode)
inline

◆ setFlushWhenFull()

void zeroerr::LogStream::setFlushWhenFull ( )
inline

◆ setLogMode()

void zeroerr::LogStream::setLogMode ( LogMode  mode)
inline

◆ setStderrLogger()

void zeroerr::LogStream::setStderrLogger ( )

◆ setStdoutLogger()

void zeroerr::LogStream::setStdoutLogger ( )

◆ setSyncLog()

void zeroerr::LogStream::setSyncLog ( )
inline

Friends And Related Function Documentation

◆ LogIterator

friend class LogIterator
friend

Member Data Documentation

◆ use_lock_free

bool zeroerr::LogStream::use_lock_free = true

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