Cogs.Core
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Cogs::Logging::ThrottledConsumer Class Referenceabstract

ThrottledConsumer is a log message consumer that attempts to throttle messages to reduce log spam. More...

#include <ThrottledConsumer.h>

Inheritance diagram for Cogs::Logging::ThrottledConsumer:
Cogs::Logging::Consumer Cogs::Logging::ConsoleLogger

Classes

struct  Message
 

Public Member Functions

virtual void consumeMessage (const char *source, Category category, uint32_t errorNumber, const char *message, const char *filename, int lineNumber) override
 Consumes a message being sent through the logging system.
 
void flush (bool flushAll=true)
 Flushes some or all messages currently queued and awaiting a suitable time to be output.
 
- Public Member Functions inherited from Cogs::Logging::Consumer
 Consumer ()
 Constructs a new Consumer instance.
 
virtual ~Consumer ()
 Unregisters this consumer from the LogManager and destroys this instance.
 
virtual void consumeMessage (const char *source, Category category, uint32_t errorNumber, const char *message, const char *filename, int lineNumber)=0
 
Category getMinimumCategory () const
 
void setMinimumCategory (Category category)
 Set the minimum category level of messages that this consumer will output.
 
void enableFilenames (bool enable)
 

Static Public Member Functions

static void setEnabled (bool enable)
 Enables or disables throttling of messages.
 
- Static Public Member Functions inherited from Cogs::Logging::Consumer
static void setDefaultMinimumCategory (Category category)
 Sets the default minimum category for all future consumers.
 
static const char * getCategoryName (Category category)
 Retrieves a human-friendly name for the given category level.
 
static const char * getCategoryNameColor (Category category)
 

Private Types

using MessageMap = std::map< size_t, Message >
 

Private Member Functions

virtual void outputMessage (const std::string &prefix, const Message &message)=0
 

Private Attributes

MessageMap messages
 
Mutex messagesMutex
 

Additional Inherited Members

- Protected Attributes inherited from Cogs::Logging::Consumer
Mutex mutex
 Mutex available for implementations to use if needed.
 
bool outputFilenames = false
 Flag controlling whether or not to include the filenames for message sources.
 

Detailed Description

ThrottledConsumer is a log message consumer that attempts to throttle messages to reduce log spam.

Derived implementations (I.e., consumers that want throttled messages) should override outputMessage and deal with the message data as required.

Definition at line 17 of file ThrottledConsumer.h.

Member Typedef Documentation

◆ MessageMap

using Cogs::Logging::ThrottledConsumer::MessageMap = std::map<size_t, Message>
private

Definition at line 35 of file ThrottledConsumer.h.

Member Function Documentation

◆ consumeMessage()

void Cogs::Logging::ThrottledConsumer::consumeMessage ( const char *  source,
Category  category,
uint32_t  errorNumber,
const char *  message,
const char *  filename,
int  lineNumber 
)
overridevirtual

Consumes a message being sent through the logging system.

This throttling consumer may prevent the message from being output immediately to reduce spam from overly enthusiastic systems. *============================================================================================

Implements Cogs::Logging::Consumer.

Definition at line 26 of file ThrottledConsumer.cpp.

References Cogs::Logging::ThrottledConsumer::Message::category, Cogs::Logging::ThrottledConsumer::Message::count, Cogs::Logging::ThrottledConsumer::Message::file, Cogs::hashSequence(), Cogs::Logging::ThrottledConsumer::Message::line, Cogs::Logging::ThrottledConsumer::Message::message, Cogs::Logging::ThrottledConsumer::Message::outputTime, and Cogs::Logging::ThrottledConsumer::Message::source.

◆ flush()

void Cogs::Logging::ThrottledConsumer::flush ( bool  flushAll = true)

Flushes some or all messages currently queued and awaiting a suitable time to be output.

*============================================================================================

Definition at line 48 of file ThrottledConsumer.cpp.

References Cogs::Logging::ThrottledConsumer::Message::count, and Cogs::Logging::ThrottledConsumer::Message::outputTime.

◆ setEnabled()

void Cogs::Logging::ThrottledConsumer::setEnabled ( bool  enable)
static

Enables or disables throttling of messages.

This setting will be applied to all throttled consumers. *============================================================================================

Definition at line 16 of file ThrottledConsumer.cpp.

Member Data Documentation

◆ messages

MessageMap Cogs::Logging::ThrottledConsumer::messages
private

Definition at line 37 of file ThrottledConsumer.h.

◆ messagesMutex

Mutex Cogs::Logging::ThrottledConsumer::messagesMutex
private

Definition at line 38 of file ThrottledConsumer.h.


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