Tkrzw
Public Member Functions | Protected Attributes | List of all members
tkrzw::StreamLogger Class Reference

Stream implementation for logging operations. More...

#include <tkrzw_logger.h>

Public Member Functions

 StreamLogger (std::ostream *stream=nullptr, Level min_level=LEVEL_INFO, const char *separator=" ", DateFormat date_format=DATE_SIMPLE, int32_t date_td=INT32MIN)
 Constructor. More...
 
virtual ~StreamLogger ()=default
 Destructor. More...
 
virtual void SetStream (std::ostream *stream)
 Sets the stream object. More...
 
void WriteRaw (std::string_view raw_data) override
 Writes a log into the media. More...
 
- Public Member Functions inherited from tkrzw::BaseLogger
 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 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...
 

Protected Attributes

std::ostream * stream_
 The output stream. More...
 
SpinMutex mutex_
 The mutex for the stream. More...
 
- Protected Attributes inherited from tkrzw::BaseLogger
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...
 

Additional Inherited Members

- Public Types inherited from tkrzw::BaseLogger
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...
 
- Static Public Member Functions inherited from tkrzw::BaseLogger
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...
 

Detailed Description

Stream implementation for logging operations.

Constructor & Destructor Documentation

◆ StreamLogger()

tkrzw::StreamLogger::StreamLogger ( std::ostream *  stream = nullptr,
Level  min_level = LEVEL_INFO,
const char *  separator = " ",
DateFormat  date_format = DATE_SIMPLE,
int32_t  date_td = INT32MIN 
)
explicit

Constructor.

Parameters
streamThe pointer to the output stream. The ownership is not taken. If it is nullptr, logging is not done.
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.

◆ ~StreamLogger()

virtual tkrzw::StreamLogger::~StreamLogger ( )
virtualdefault

Destructor.

Member Function Documentation

◆ SetStream()

virtual void tkrzw::StreamLogger::SetStream ( std::ostream *  stream)
virtual

Sets the stream object.

Parameters
streamThe pointer to the output stream. The ownership is not taken. If it is nullptr, logging is not done.

◆ WriteRaw()

void tkrzw::StreamLogger::WriteRaw ( std::string_view  raw_data)
overridevirtual

Writes a log into the media.

Parameters
raw_dataFormatted log data.

Implements tkrzw::BaseLogger.

Member Data Documentation

◆ stream_

std::ostream* tkrzw::StreamLogger::stream_
protected

The output stream.

◆ mutex_

SpinMutex tkrzw::StreamLogger::mutex_
protected

The mutex for the stream.