Log handler for sending messages to a syslog server.
More...
#include <uuid/syslog.h>
Log handler for sending messages to a syslog server.
- Since
- 1.0.0
Definition at line 81 of file syslog.h.
◆ SyslogService()
uuid::syslog::SyslogService::SyslogService |
( |
| ) |
|
|
default |
Create a new syslog service log handler.
- Since
- 1.0.0
◆ add_message()
void uuid::syslog::SyslogService::add_message |
( |
std::shared_ptr< uuid::log::Message > & |
message | ) |
|
|
private |
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] | message | New log message, shared by all handlers. |
- Since
- 2.2.0
Definition at line 255 of file syslog.cpp.
◆ 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 347 of file syslog.cpp.
◆ current_log_messages()
size_t uuid::syslog::SyslogService::current_log_messages |
( |
| ) |
const |
Get the current number of queued log messages.
- Returns
- The current number of queued log messages.
- Since
- 2.1.0
Definition at line 188 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 196 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] | host | IP address of the syslog server. |
[in] | port | UDP port to send messages to. |
- Since
- 2.0.0
Definition at line 200 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 210 of file syslog.cpp.
◆ hostname() [2/2]
void uuid::syslog::SyslogService::hostname |
( |
std::string |
hostname | ) |
|
Set local hostname.
- Parameters
-
[in] | hostname | Hostname of this device. |
- Since
- 2.0.0
Definition at line 214 of file syslog.cpp.
◆ log_level() [1/2]
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 128 of file syslog.cpp.
◆ log_level() [2/2]
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] | level | Minimum log level that will be sent to the syslog server. |
- Since
- 2.0.0
Definition at line 151 of file syslog.cpp.
◆ loop()
void uuid::syslog::SyslogService::loop |
( |
| ) |
|
Dispatch queued log messages.
- Since
- 1.0.0
Definition at line 271 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 222 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] | interval | Mark interval in seconds (0 = disable). |
- Since
- 2.0.0
Definition at line 226 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 168 of file syslog.cpp.
◆ maximum_log_messages() [2/2]
void uuid::syslog::SyslogService::maximum_log_messages |
( |
size_t |
count | ) |
|
◆ operator<<()
void uuid::syslog::SyslogService::operator<< |
( |
std::shared_ptr< uuid::log::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] | message | New log message, shared by all handlers. |
- Since
- 1.0.0
Implements uuid::log::Handler.
Definition at line 263 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
-
- Since
- 1.0.0
Definition at line 132 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 124 of file syslog.cpp.
◆ transmit()
Attempt to transmit one message to the server.
- Parameters
-
[in] | message | Log message to be sent. |
- Returns
- True if the message was successfully set, otherwise false.
- Since
- 1.0.0
Definition at line 472 of file syslog.cpp.
◆ DEFAULT_PORT
constexpr uint16_t uuid::syslog::SyslogService::DEFAULT_PORT = 514 |
|
staticconstexpr |
Default UDP port to send messages to.
- Since
- 1.0.0
Definition at line 84 of file syslog.h.
◆ host_
IPAddress uuid::syslog::SyslogService::host_ |
|
private |
Host to send messages to.
- Since
- 1.0.0
Definition at line 296 of file syslog.h.
◆ hostname_
std::string uuid::syslog::SyslogService::hostname_ {'-'} |
|
private |
Local hostname.
- Since
- 1.0.0
Definition at line 299 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 307 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 298 of file syslog.h.
◆ level_set_
bool uuid::syslog::SyslogService::level_set_ = false |
|
private |
Flag to indicate that the log level has been set at least once.
- Since
- 2.2.0
Definition at line 294 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 304 of file syslog.h.
◆ log_messages_
Queued log messages, in the order they were received.
- Since
- 1.0.0
Definition at line 305 of file syslog.h.
◆ logger_
uuid::log::Logger uuid::syslog::SyslogService::logger_ {FPSTR(__pstr__logger_name), uuid::log::Facility::SYSLOG} |
|
staticprivate |
◆ mark_interval_
uint64_t uuid::syslog::SyslogService::mark_interval_ = 0 |
|
private |
Mark interval in milliseconds.
- Since
- 2.0.0
Definition at line 306 of file syslog.h.
◆ MAX_LOG_MESSAGES
constexpr size_t uuid::syslog::SyslogService::MAX_LOG_MESSAGES = 50 |
|
staticconstexpr |
Maximum number of log messages to buffer before they are output.
- Since
- 1.0.0
Definition at line 83 of file syslog.h.
◆ maximum_log_messages_
Maximum number of log messages to buffer before they are output.
- Since
- 1.0.0
Definition at line 303 of file syslog.h.
◆ mutex_
std::mutex uuid::syslog::SyslogService::mutex_ |
|
mutableprivate |
Mutex for queued log messages.
- Since
- 2.2.0
Definition at line 301 of file syslog.h.
◆ port_
Port to send messages to.
- Since
- 1.0.0
Definition at line 297 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 293 of file syslog.h.
◆ udp_
WiFiUDP uuid::syslog::SyslogService::udp_ |
|
private |
UDP client.
- Since
- 1.0.0
Definition at line 295 of file syslog.h.
The documentation for this class was generated from the following files: