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

Base implementation for logging operations. More...

#include <tkrzw_logger.h>

Public Types

enum  DateFormat : int32_t {
  DATE_NONE = 0 , DATE_SIMPLE = 1 , DATE_SIMPLE_MICRO = 2 , DATE_W3CDTF = 3 ,
  DATE_W3CDTF_MICRO = 4 , DATE_RFC1123 = 5 , DATE_EPOCH = 6 , DATE_EPOCH_MICRO = 7
}
 Enumeration of date formats. More...
 
- Public Types inherited from tkrzw::Logger
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

 BaseLogger (Level min_level=LEVEL_INFO, const char *separator=" ", DateFormat date_format=DATE_SIMPLE, int32_t date_td=INT32MIN)
 Constructor. More...
 
virtual ~BaseLogger ()=default
 Destructor. More...
 
virtual void SetSeparator (const char *separator)
 Sets the separator string between fields. More...
 
virtual void SetDateFormat (DateFormat date_format, int32_t date_td=INT32MIN)
 Sets the data format of each log. More...
 
virtual void WriteRaw (std::string_view raw_data)=0
 Writes a log into the media. More...
 
virtual void WriteProperties (Level level, std::string_view message)
 Formats properties of a log into a string and write it. More...
 
void Log (Level level, std::string_view message) override
 Logs a message. More...
 
- Public Member Functions inherited from tkrzw::Logger
 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 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 DateFormat ParseDateFormatStr (std::string_view str)
 Parses a string to get an enum of date formats. More...
 
- Static Public Member Functions inherited from tkrzw::Logger
static Level ParseLevelStr (std::string_view str)
 Parses a string to get an enum of log levels. More...
 

Protected Attributes

std::string_view separator_
 The separator between fields. More...
 
DateFormat date_format_
 The date format. More...
 
int32_t date_td_
 The date time difference. More...
 
- Protected Attributes inherited from tkrzw::Logger
Level min_level_
 The minimum log level to be stored. More...
 

Detailed Description

Base implementation for logging operations.

Member Enumeration Documentation

◆ DateFormat

Enumeration of date formats.

Enumerator
DATE_NONE 

No date data.

DATE_SIMPLE 

Simple format.

DATE_SIMPLE_MICRO 

Simple format in microseconds.

DATE_W3CDTF 

W3CDTF format.

DATE_W3CDTF_MICRO 

Simple format in microseconds.

DATE_RFC1123 

RFC1123 format.

DATE_EPOCH 

Decimal number of the UNIX epoch.

DATE_EPOCH_MICRO 

Decimal number of the UNIX epoch in microseconds.

Constructor & Destructor Documentation

◆ BaseLogger()

tkrzw::BaseLogger::BaseLogger ( Level  min_level = LEVEL_INFO,
const char *  separator = " ",
DateFormat  date_format = DATE_SIMPLE,
int32_t  date_td = INT32MIN 
)
explicit

Constructor.

Parameters
min_levelThe minimum log level to be stored.
separatorThe separator string between fields.
date_formatThe date format.
date_tdthe time difference of the timze zone. If it is INT32MIN, the local time zone is specified.

◆ ~BaseLogger()

virtual tkrzw::BaseLogger::~BaseLogger ( )
virtualdefault

Destructor.

Member Function Documentation

◆ SetSeparator()

virtual void tkrzw::BaseLogger::SetSeparator ( const char *  separator)
virtual

Sets the separator string between fields.

Parameters
separatorThe separator string between fields.

◆ SetDateFormat()

virtual void tkrzw::BaseLogger::SetDateFormat ( DateFormat  date_format,
int32_t  date_td = INT32MIN 
)
virtual

Sets the data format of each log.

Parameters
date_formatThe date format.
date_tdthe time difference of the timze zone. If it is INT32MIN, the local time zone is specified.

◆ WriteRaw()

virtual void tkrzw::BaseLogger::WriteRaw ( std::string_view  raw_data)
pure virtual

Writes a log into the media.

Parameters
raw_dataFormatted log data.

Implemented in tkrzw::StreamLogger.

◆ WriteProperties()

virtual void tkrzw::BaseLogger::WriteProperties ( Level  level,
std::string_view  message 
)
virtual

Formats properties of a log into a string and write it.

Parameters
levelThe log level.
messageThe message to write.

◆ Log()

void tkrzw::BaseLogger::Log ( Level  level,
std::string_view  message 
)
overridevirtual

Logs a message.

Parameters
levelThe log level.
messageThe message to write.

Implements tkrzw::Logger.

◆ ParseDateFormatStr()

static DateFormat tkrzw::BaseLogger::ParseDateFormatStr ( std::string_view  str)
static

Parses a string to get an enum of date formats.

Parameters
strThe string to parse
Returns
The result enum of date formats.

Member Data Documentation

◆ separator_

std::string_view tkrzw::BaseLogger::separator_
protected

The separator between fields.

◆ date_format_

DateFormat tkrzw::BaseLogger::date_format_
protected

The date format.

◆ date_td_

int32_t tkrzw::BaseLogger::date_td_
protected

The date time difference.