nomlib
Loading...
Searching...
No Matches
nom::SDL2Logger Class Reference

Category & priority message logging API. More...

#include <SDL2Logger.hpp>

Public Types

typedef SDL2Logger self_type

Public Member Functions

 SDL2Logger ()
 Default constructor; initialize the log category to NOM and the log priority to LogPriority::NOM_LOG_PRIORITY_INFO.
 SDL2Logger (int cat, nom::LogPriority prio)
 Construct a logging object.
 ~SDL2Logger ()
 Destructor; the logging category, logging priority level and output stream is sent to the underlying implementation at this time. Care must be taken when using this interface outside the provided macros, as the message is not output until this point.
template<typename Type, typename ... Args>
void write (const Type &f, const Args &... rest)
 Write one or more log messages to the output stream.
template<typename Type>
void write (const Type &f)
 Write a log message to the output stream.
void write (uint8_t f)
void write ()
 Write a log message to the output stream.
int category () const
 Get the logging category.
LogPriority priority () const
 Get the logging priority level.
std::ostringstream & output_stream ()
 Get the log message.

Static Public Member Functions

static bool initialized (void)
 Get initialization status of the default logging category priorities.
static void initialize ()
 Set the default logging category priority levels.
static LogPriority priority (SDL_LogPriority prio)
 Convert an underlying implementation's logging priority level.
static SDL_LogPriority SDL_priority (LogPriority prio)
 Convert the logging priority level to the underlying implementation's type.
static void set_logging_priorities (LogPriority prio)
 Set the logging priority for all logging categories.
static void set_logging_priority (int cat, LogPriority prio)
 Set the logging priority for a log category.

Static Public Attributes

static const std::string priority_prefixes_ [NOM_NUM_LOG_PRIORITIES]
 Human-friendly descriptions of the logging priorities.

Private Member Functions

 SDL2Logger (const self_type &rhs)=delete
 Copy constructor.
self_type & operator= (const self_type &rhs)=delete
 Copy assignment constructor.

Private Attributes

int category_
 The logging category of the log message.
nom::LogPriority priority_
 The logging priority of the log message.
std::ostringstream os_
 The log message stream.

Static Private Attributes

static bool initialized_
 Ensure one-time initialization of the setting of logging category priorities.

Detailed Description

Category & priority message logging API.

A simple category & priority based logging facility.

If you are debugging nomlib, you might want to call:

nom::SDL2Logger::set_logging_priorities( nom::LogPriority::NOM_LOG_PRIORITY_WARN );
static void set_logging_priorities(LogPriority prio)
Set the logging priority for all logging categories.
Note
This implementation is a C++ wrapper for SDL2's logging facilities, and is intended to be fully compatible & consistent with except where explicitly stated otherwise.
Remarks
Logging priorities are reset upon a call to SDL_Quit.
See also
SDL2 Logging API
This implementation was inspired by a Q&A blog and by a SDL2 C++ wrapper.
Convenience logging macros – NOM_LOG_* – for the primary usage API.

Definition at line 189 of file SDL2Logger.hpp.

Member Typedef Documentation

◆ self_type

typedef SDL2Logger nom::SDL2Logger::self_type

Definition at line 192 of file SDL2Logger.hpp.

Constructor & Destructor Documentation

◆ SDL2Logger() [1/2]

nom::SDL2Logger::SDL2Logger ( int cat,
nom::LogPriority prio )

Construct a logging object.

Parameters
catThe logging category to assign.
prioA nom::LogPriority enumeration value to use as the logging priority.
See also
::write.

◆ ~SDL2Logger()

nom::SDL2Logger::~SDL2Logger ( )

Destructor; the logging category, logging priority level and output stream is sent to the underlying implementation at this time. Care must be taken when using this interface outside the provided macros, as the message is not output until this point.

If you wish to set a custom log output function for logging, you should do so before destruction occurs.

◆ SDL2Logger() [2/2]

nom::SDL2Logger::SDL2Logger ( const self_type & rhs)
privatedelete

Copy constructor.

Remarks
This object cannot be copied.
Note
The object cannot be copied because of the usage of std::ostringstream.

Member Function Documentation

◆ initialize()

void nom::SDL2Logger::initialize ( )
static

Set the default logging category priority levels.

See also
NOM_LOG_CATEGORY enumeration.

◆ operator=()

self_type & nom::SDL2Logger::operator= ( const self_type & rhs)
privatedelete

Copy assignment constructor.

Remarks
This object cannot be copy assigned.
Note
The object cannot be copied because of the usage of std::ostringstream.

◆ output_stream()

std::ostringstream & nom::SDL2Logger::output_stream ( )

Get the log message.

Returns
A reference to the logger's C++ output stream.

◆ priority()

LogPriority nom::SDL2Logger::priority ( SDL_LogPriority prio)
static

Convert an underlying implementation's logging priority level.

Returns
The equivalent nom::LogPriority enumeration type.

◆ set_logging_priorities()

void nom::SDL2Logger::set_logging_priorities ( LogPriority prio)
static

Set the logging priority for all logging categories.

Remarks
This is a wrapper for SDL_SetAllPriority.

◆ set_logging_priority()

void nom::SDL2Logger::set_logging_priority ( int cat,
LogPriority prio )
static

Set the logging priority for a log category.

Remarks
This is a wrapper for SDL_SetPriority.

◆ write() [1/4]

void nom::SDL2Logger::write ( )

Write a log message to the output stream.

Remarks
This is an intentional method overload when the desire is to not write anything.
See also
::write( const Type&, const Args& )

◆ write() [2/4]

template<typename Type>
void nom::SDL2Logger::write ( const Type & f)
inline

Write a log message to the output stream.

Remarks
This method supports writing to the output buffer with a single string literal / object.
See also
::write( const Type&, const Args& )

Definition at line 249 of file SDL2Logger.hpp.

◆ write() [3/4]

template<typename Type, typename ... Args>
void nom::SDL2Logger::write ( const Type & f,
const Args &... rest )
inline

Write one or more log messages to the output stream.

Parameters
restVariable list of std::ostringstream compatible arguments.

Definition at line 233 of file SDL2Logger.hpp.

◆ write() [4/4]

void nom::SDL2Logger::write ( uint8_t f)
inline

Definition at line 254 of file SDL2Logger.hpp.

Member Data Documentation

◆ category_

int nom::SDL2Logger::category_
private

The logging category of the log message.

Definition at line 315 of file SDL2Logger.hpp.

◆ initialized_

bool nom::SDL2Logger::initialized_
staticprivate

Ensure one-time initialization of the setting of logging category priorities.

See also
NOM_LOG_CATEGORY_* enumeration.

Definition at line 327 of file SDL2Logger.hpp.

◆ os_

std::ostringstream nom::SDL2Logger::os_
private

The log message stream.

Definition at line 321 of file SDL2Logger.hpp.

◆ priority_

nom::LogPriority nom::SDL2Logger::priority_
private

The logging priority of the log message.

Definition at line 318 of file SDL2Logger.hpp.

◆ priority_prefixes_

const std::string nom::SDL2Logger::priority_prefixes_[NOM_NUM_LOG_PRIORITIES]
static

Human-friendly descriptions of the logging priorities.

Definition at line 195 of file SDL2Logger.hpp.


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