Tkrzw
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
tkrzw::Logger Class Referenceabstract

Interface for logging operations. More...

#include <tkrzw_logger.h>

Public Types

enum  Level : int32_t {
  LEVEL_NONE = 0 , LEVEL_DEBUG = 1 , LEVEL_INFO = 2 , LEVEL_WARN = 3 ,
  LEVEL_ERROR = 4 , LEVEL_FATAL = 5
}
 Enumeration of log levels. More...
 

Public Member Functions

 Logger (Level min_level=LEVEL_INFO)
 Constructor. More...
 
virtual ~Logger ()=default
 Destructor. More...
 
virtual void SetMinLevel (Level min_level)
 Sets the minimum log level. More...
 
virtual bool CheckLevel (Level level) const
 Checks whether a log level is worth storing. More...
 
virtual void Log (Level level, std::string_view message)=0
 Logs a message. More...
 
virtual void LogF (Level level, const char *format,...)
 Logs a formatted message. More...
 
template<typename FIRST , typename... REST>
void LogCat (Level level, const FIRST &first, const REST &... rest)
 Logs a message made of substrings. More...
 

Static Public Member Functions

static Level ParseLevelStr (std::string_view str)
 Parses a string to get an enum of log levels. More...
 

Protected Attributes

Level min_level_
 The minimum log level to be stored. More...
 

Detailed Description

Interface for logging operations.

Member Enumeration Documentation

◆ Level

enum tkrzw::Logger::Level : int32_t

Enumeration of log levels.

Enumerator
LEVEL_NONE 

No log is recorded.

LEVEL_DEBUG 

For data only for debugging.

LEVEL_INFO 

For data informative for normal operations.

LEVEL_WARN 

For issues which potentially cause application oddities.

LEVEL_ERROR 

For errors which should be fixed.

LEVEL_FATAL 

For critical errors which immediately stop the service.

Constructor & Destructor Documentation

◆ Logger()

tkrzw::Logger::Logger ( Level  min_level = LEVEL_INFO)
explicit

Constructor.

Parameters
min_levelThe minimum log level to be stored.

◆ ~Logger()

virtual tkrzw::Logger::~Logger ( )
virtualdefault

Destructor.

Member Function Documentation

◆ SetMinLevel()

virtual void tkrzw::Logger::SetMinLevel ( Level  min_level)
virtual

Sets the minimum log level.

Parameters
min_levelThe minimum log level to be stored.

◆ CheckLevel()

virtual bool tkrzw::Logger::CheckLevel ( Level  level) const
virtual

Checks whether a log level is worth storing.

Returns
True if the log level is worth storing.

◆ Log()

virtual void tkrzw::Logger::Log ( Level  level,
std::string_view  message 
)
pure virtual

Logs a message.

Parameters
levelThe log level.
messageThe message to write.

Implemented in tkrzw::BaseLogger.

◆ LogF()

virtual void tkrzw::Logger::LogF ( Level  level,
const char *  format,
  ... 
)
virtual

Logs a formatted message.

Parameters
levelThe log level.
formatThe format string.
...The other arguments.

◆ LogCat()

template<typename FIRST , typename... REST>
void tkrzw::Logger::LogCat ( Level  level,
const FIRST &  first,
const REST &...  rest 
)

Logs a message made of substrings.

Parameters
levelThe log level.
firstThe first substring.
restThe rest substrings.

◆ ParseLevelStr()

static Level tkrzw::Logger::ParseLevelStr ( std::string_view  str)
static

Parses a string to get an enum of log levels.

Parameters
strThe string to parse
Returns
The result enum of log levels.

Member Data Documentation

◆ min_level_

Level tkrzw::Logger::min_level_
protected

The minimum log level to be stored.