My Project
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
uuid::log::PrintHandler Class Reference

Basic log handler for writing messages to any object supporting the Print interface. More...

#include <uuid/log.h>

Inheritance diagram for uuid::log::PrintHandler:
Inheritance graph
[legend]
Collaboration diagram for uuid::log::PrintHandler:
Collaboration graph
[legend]

Public Member Functions

 PrintHandler (Print &print)
 Create a new Print log handler. More...
 
size_t maximum_log_messages () const
 Get the maximum number of queued log messages. More...
 
void maximum_log_messages (size_t count)
 Set the maximum number of queued log messages. More...
 
void loop (size_t count=SIZE_MAX)
 Dispatch queued log messages. More...
 
void operator<< (std::shared_ptr< Message > message) override
 Add a new log message. More...
 

Static Public Attributes

static constexpr size_t MAX_LOG_MESSAGES = 50
 

Private Attributes

Print & print_
 
std::mutex mutex_
 
size_t maximum_log_messages_ = MAX_LOG_MESSAGES
 
std::list< std::shared_ptr< Message > > log_messages_
 

Detailed Description

Basic log handler for writing messages to any object supporting the Print interface.

Outputs all queued messages by default, which may result in the application blocking until writes complete if the Print destination buffer is full.

Since
2.2.0

Definition at line 792 of file log.h.

Constructor & Destructor Documentation

◆ PrintHandler()

uuid::log::PrintHandler::PrintHandler ( Print &  print)
explicit

Create a new Print log handler.

Parameters
[in]printDestination for output of log messages.
Since
2.2.0

Definition at line 32 of file print_handler.cpp.

Member Function Documentation

◆ loop()

void uuid::log::PrintHandler::loop ( size_t  count = SIZE_MAX)

Dispatch queued log messages.

Parameters
[in]countMaximum number of messages to output.
Since
2.2.0

Definition at line 55 of file print_handler.cpp.

◆ maximum_log_messages() [1/2]

size_t uuid::log::PrintHandler::maximum_log_messages ( ) const

Get the maximum number of queued log messages.

Returns
The maximum number of queued log messages.
Since
2.2.0

Definition at line 35 of file print_handler.cpp.

◆ maximum_log_messages() [2/2]

void uuid::log::PrintHandler::maximum_log_messages ( size_t  count)

Set the maximum number of queued log messages.

Defaults to PrintHandler::MAX_LOG_MESSAGES.

Since
2.2.0

Definition at line 43 of file print_handler.cpp.

◆ operator<<()

void uuid::log::PrintHandler::operator<< ( std::shared_ptr< Message message)
overridevirtual

Add a new log message.

This will be put in a queue for output at the next loop() process. The queue has a maximum size of get_maximum_log_messages() and will discard the oldest message first.

Parameters
[in]messageNew log message, shared by all handlers.
Since
2.2.0

Implements uuid::log::Handler.

Definition at line 91 of file print_handler.cpp.

Member Data Documentation

◆ log_messages_

std::list<std::shared_ptr<Message> > uuid::log::PrintHandler::log_messages_
private

Queued log messages, in the order they were received.

Since
2.2.0

Definition at line 848 of file log.h.

◆ MAX_LOG_MESSAGES

constexpr size_t uuid::log::PrintHandler::MAX_LOG_MESSAGES = 50
staticconstexpr

Maximum number of log messages to buffer before they are output.

Since
2.2.0

Definition at line 794 of file log.h.

◆ maximum_log_messages_

size_t uuid::log::PrintHandler::maximum_log_messages_ = MAX_LOG_MESSAGES
private

Maximum number of log messages to buffer before they are output.

Since
2.2.0

Definition at line 847 of file log.h.

◆ mutex_

std::mutex uuid::log::PrintHandler::mutex_
mutableprivate

Mutex for configuration, state and queued log messages.

Since
2.3.0

Definition at line 845 of file log.h.

◆ print_

Print& uuid::log::PrintHandler::print_
private

Destination for output of log messages.

Since
2.2.0

Definition at line 843 of file log.h.


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