C++ Utilities
Loading...
Searching...
No Matches
utilities::message

A utilities::message object captures a location where the message was created and optionally a payload string. More...

#include <log.h>

Public Types

using handler_type = void(const message&)
 Messages are handled by a function with this signature – there is just one handler at a time.

Public Member Functions

 message (std::string_view func, std::string_view path, std::size_t line, std::string_view type, std::string_view payload="")
 Constructor for message objects.
std::string to_string () const
 Returns the whole message as a string e.g. "[DEBUG] 'foobar' foo.cpp line 25: x = 10, y = 11".
void dispatch () const
 Dispatch this message to the message handler.

Static Public Member Functions

static handler_type *& handler ()
 Class method that lets you set a custom message handling function.
static void use_default_handler ()
 Class method that sets the message handler back to the default value.
static void default_handler (const message &message)
 The default message handler just prints the message to the default stream.
static std::string filename (std::string_view path)
 Reduce a full path to just the filename.

Static Public Attributes

static std::ostream * stream = &std::cout
 The stream used by the default message handler.

Detailed Description

A utilities::message object captures a location where the message was created and optionally a payload string.

Note: These are created by the MAKE_MESSAGE(...) macro above that inserts the needed location information.

Member Typedef Documentation

◆ handler_type

Messages are handled by a function with this signature – there is just one handler at a time.

The default handler just prints the message to a default stream.

Constructor & Destructor Documentation

◆ message()

utilities::message::message ( std::string_view func,
std::string_view path,
std::size_t line,
std::string_view type,
std::string_view payload = "" )
inline

Constructor for message objects.

In practice, these are best created using a macro that inserts the needed source code location information.

Member Function Documentation

◆ use_default_handler()

void utilities::message::use_default_handler ( )
inlinestatic

Class method that sets the message handler back to the default value.

The default handler just prints the messages to a default stream

Member Data Documentation

◆ stream

std::ostream* utilities::message::stream = &std::cout
inlinestatic

The stream used by the default message handler.

You can set it to say a file stream instead if you wanted to store the messages.