Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
uuid::syslog::SyslogService Class Reference

Log handler for sending messages to a syslog server. More...

#include <uuid/syslog.h>

Inheritance diagram for uuid::syslog::SyslogService:
Inheritance graph
[legend]
Collaboration diagram for uuid::syslog::SyslogService:
Collaboration graph
[legend]

Classes

class  QueuedLogMessage
 Log message that has been queued. More...
 

Public Member Functions

 SyslogService ()=default
 Create a new syslog service log handler. More...
 
void start ()
 Register the log handler with the logging framework. More...
 
uuid::log::Level log_level () const
 Get the current log level. More...
 
void log_level (uuid::log::Level level)
 Set the current log level. 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...
 
std::pair< IPAddress, uint16_t > destination () const
 Get the server to send messages to. More...
 
void destination (IPAddress host, uint16_t port=DEFAULT_PORT)
 Set the server to send messages to. More...
 
std::string hostname () const
 Get local hostname. More...
 
void hostname (std::string hostname)
 Set local hostname. More...
 
unsigned long mark_interval () const
 Get mark interval. More...
 
void mark_interval (unsigned long interval)
 Set mark interval. More...
 
void loop ()
 Dispatch queued log messages. More...
 
virtual void operator<< (std::shared_ptr< uuid::log::Message > message)
 Add a new log message. More...
 

Static Public Attributes

static constexpr size_t MAX_LOG_MESSAGES = 50
 
static constexpr uint16_t DEFAULT_PORT = 514
 

Private Member Functions

void remove_queued_messages (uuid::log::Level level)
 Remove messages that were queued before the log level was set. More...
 
bool can_transmit ()
 Check if it is possible to transmit to the server. More...
 
bool transmit (const QueuedLogMessage &message)
 Attempt to transmit one message to the server. More...
 

Private Attributes

bool started_ = false
 
WiFiUDP udp_
 
IPAddress host_
 
uint16_t port_ = DEFAULT_PORT
 
uint64_t last_transmit_ = 0
 
std::string hostname_ {'-'}
 
size_t maximum_log_messages_ = MAX_LOG_MESSAGES
 
unsigned long log_message_id_ = 0
 
std::list< QueuedLogMessagelog_messages_
 
std::atomic< bool > log_messages_overflow_ {false}
 
uint64_t mark_interval_ = 0
 
uint64_t last_message_ = 0
 

Static Private Attributes

static uuid::log::Logger logger_ {FPSTR(__pstr__logger_name), uuid::log::Facility::SYSLOG}
 

Detailed Description

Log handler for sending messages to a syslog server.

Since
1.0.0

Definition at line 53 of file syslog.h.

Constructor & Destructor Documentation

◆ SyslogService()

uuid::syslog::SyslogService::SyslogService ( )
default

Create a new syslog service log handler.

Since
1.0.0

Member Function Documentation

◆ can_transmit()

bool uuid::syslog::SyslogService::can_transmit ( )
private

Check if it is possible to transmit to the server.

Returns
True if it is safe to transmit a message to the server, otherwise false.
Since
1.0.0

Definition at line 256 of file syslog.cpp.

◆ destination() [1/2]

std::pair< IPAddress, uint16_t > uuid::syslog::SyslogService::destination ( ) const

Get the server to send messages to.

Since
2.0.0
Returns
IP address and UDP port of the syslog server.

Definition at line 153 of file syslog.cpp.

◆ destination() [2/2]

void uuid::syslog::SyslogService::destination ( IPAddress  host,
uint16_t  port = DEFAULT_PORT 
)

Set the server to send messages to.

To disable sending messages, set the host to 0.0.0.0 and the log level to uuid::log::Level::OFF (otherwise they will be queued but not sent).

Parameters
[in]hostIP address of the syslog server.
[in]portUDP port to send messages to.
Since
2.0.0

Definition at line 157 of file syslog.cpp.

◆ hostname() [1/2]

std::string uuid::syslog::SyslogService::hostname ( ) const

Get local hostname.

Since
2.0.0
Returns
Hostname of this device.

Definition at line 167 of file syslog.cpp.

◆ hostname() [2/2]

void uuid::syslog::SyslogService::hostname ( std::string  hostname)

Set local hostname.

Parameters
[in]hostnameHostname of this device.
Since
2.0.0

Definition at line 171 of file syslog.cpp.

◆ log_level() [1/2]

uuid::log::Level uuid::syslog::SyslogService::log_level ( ) const

Get the current log level.

This only affects newly received log messages, not messages that have already been queued.

Returns
The current log level.
Since
2.0.0

Definition at line 103 of file syslog.cpp.

◆ log_level() [2/2]

void uuid::syslog::SyslogService::log_level ( uuid::log::Level  level)

Set the current log level.

Unless this is the first time the log level is being set, this only affects newly received log messages, not messages that have already been queued.

Parameters
[in]levelMinimum log level that will be sent to the syslog server.
Since
2.0.0

Definition at line 123 of file syslog.cpp.

◆ loop()

void uuid::syslog::SyslogService::loop ( )

Dispatch queued log messages.

Since
1.0.0

Definition at line 220 of file syslog.cpp.

◆ mark_interval() [1/2]

unsigned long uuid::syslog::SyslogService::mark_interval ( ) const

Get mark interval.

Since
2.0.0
Returns
Mark interval in seconds (0 = disable).

Definition at line 179 of file syslog.cpp.

◆ mark_interval() [2/2]

void uuid::syslog::SyslogService::mark_interval ( unsigned long  interval)

Set mark interval.

When no messages have been sent for this period of time, a -- MARK -- message will be generated automatically.

Parameters
[in]intervalMark interval in seconds (0 = disable).
Since
2.0.0

Definition at line 183 of file syslog.cpp.

◆ maximum_log_messages() [1/2]

size_t uuid::syslog::SyslogService::maximum_log_messages ( ) const

Get the maximum number of queued log messages.

Returns
The maximum number of queued log messages.
Since
2.0.0

Definition at line 141 of file syslog.cpp.

◆ maximum_log_messages() [2/2]

void uuid::syslog::SyslogService::maximum_log_messages ( size_t  count)

Set the maximum number of queued log messages.

Defaults to SyslogService::MAX_LOG_MESSAGES.

Since
2.0.0

Definition at line 145 of file syslog.cpp.

◆ operator<<()

void uuid::syslog::SyslogService::operator<< ( std::shared_ptr< uuid::log::Message message)
virtual

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
1.0.0

Implements uuid::log::Handler.

Definition at line 211 of file syslog.cpp.

◆ remove_queued_messages()

void uuid::syslog::SyslogService::remove_queued_messages ( uuid::log::Level  level)
private

Remove messages that were queued before the log level was set.

Parameters
[in]levelNew log level
Since
1.0.0

Definition at line 107 of file syslog.cpp.

◆ start()

void uuid::syslog::SyslogService::start ( )

Register the log handler with the logging framework.

Since
1.0.0

Definition at line 99 of file syslog.cpp.

◆ transmit()

bool uuid::syslog::SyslogService::transmit ( const QueuedLogMessage message)
private

Attempt to transmit one message to the server.

Parameters
[in]messageLog message to be sent.
Returns
True if the message was successfully set, otherwise false.
Since
1.0.0

Definition at line 381 of file syslog.cpp.

Member Data Documentation

◆ DEFAULT_PORT

constexpr uint16_t uuid::syslog::SyslogService::DEFAULT_PORT = 514
static

Default UDP port to send messages to.

Since
1.0.0

Definition at line 56 of file syslog.h.

◆ host_

IPAddress uuid::syslog::SyslogService::host_
private

Host to send messages to.

Since
1.0.0

Definition at line 246 of file syslog.h.

◆ hostname_

std::string uuid::syslog::SyslogService::hostname_ {'-'}
private

Local hostname.

Since
1.0.0

Definition at line 249 of file syslog.h.

◆ last_message_

uint64_t uuid::syslog::SyslogService::last_message_ = 0
private

Last message/mark time.

Since
2.0.0

Definition at line 255 of file syslog.h.

◆ last_transmit_

uint64_t uuid::syslog::SyslogService::last_transmit_ = 0
private

Last transmit time.

Since
1.0.0

Definition at line 248 of file syslog.h.

◆ log_message_id_

unsigned long uuid::syslog::SyslogService::log_message_id_ = 0
private

The next identifier to use for queued log messages.

Since
1.0.0

Definition at line 251 of file syslog.h.

◆ log_messages_

std::list<QueuedLogMessage> uuid::syslog::SyslogService::log_messages_
private

Queued log messages, in the order they were received.

Since
1.0.0

Definition at line 252 of file syslog.h.

◆ log_messages_overflow_

std::atomic<bool> uuid::syslog::SyslogService::log_messages_overflow_ {false}
private

Check if log messages have overflowed the buffer.

Since
1.0.0

Definition at line 253 of file syslog.h.

◆ logger_

uuid::log::Logger uuid::syslog::SyslogService::logger_ {FPSTR(__pstr__logger_name), uuid::log::Facility::SYSLOG}
staticprivate

uuid::log::Logger instance for syslog services.

Since
1.0.0

Definition at line 242 of file syslog.h.

◆ mark_interval_

uint64_t uuid::syslog::SyslogService::mark_interval_ = 0
private

Mark interval in milliseconds.

Since
2.0.0

Definition at line 254 of file syslog.h.

◆ MAX_LOG_MESSAGES

constexpr size_t uuid::syslog::SyslogService::MAX_LOG_MESSAGES = 50
static

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

Since
1.0.0

Definition at line 55 of file syslog.h.

◆ maximum_log_messages_

size_t uuid::syslog::SyslogService::maximum_log_messages_ = MAX_LOG_MESSAGES
private

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

Since
1.0.0

Definition at line 250 of file syslog.h.

◆ port_

uint16_t uuid::syslog::SyslogService::port_ = DEFAULT_PORT
private

Port to send messages to.

Since
1.0.0

Definition at line 247 of file syslog.h.

◆ started_

bool uuid::syslog::SyslogService::started_ = false
private

Flag to indicate that messages have started being transmitted.

Since
1.0.0

Definition at line 244 of file syslog.h.

◆ udp_

WiFiUDP uuid::syslog::SyslogService::udp_
private

UDP client.

Since
1.0.0

Definition at line 245 of file syslog.h.


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