mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 17:29:50 +03:00
updated uuid libs
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* uuid-syslog - Syslog service
|
||||
* Copyright 2019 Simon Arlott
|
||||
* uuid-syslog - Microcontroller syslog service
|
||||
* Copyright 2019,2021-2022 Simon Arlott
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -20,21 +20,34 @@
|
||||
#define UUID_SYSLOG_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#else
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
#include <WiFiUdp.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <uuid/log.h>
|
||||
|
||||
#ifndef UUID_LOG_THREAD_SAFE
|
||||
#define UUID_LOG_THREAD_SAFE 0
|
||||
#endif
|
||||
|
||||
#ifndef UUID_COMMON_STD_MUTEX_AVAILABLE
|
||||
#define UUID_COMMON_STD_MUTEX_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
#if UUID_COMMON_STD_MUTEX_AVAILABLE
|
||||
#define UUID_SYSLOG_THREAD_SAFE 1
|
||||
#else
|
||||
#define UUID_SYSLOG_THREAD_SAFE 0
|
||||
#endif
|
||||
|
||||
#if UUID_LOG_THREAD_SAFE
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
namespace uuid {
|
||||
|
||||
/**
|
||||
@@ -45,6 +58,17 @@ namespace uuid {
|
||||
*/
|
||||
namespace syslog {
|
||||
|
||||
/**
|
||||
* Thread-safe status of the library.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
#if UUID_COMMON_THREAD_SAFE && UUID_LOG_THREAD_SAFE && UUID_SYSLOG_THREAD_SAFE
|
||||
static constexpr bool thread_safe = true;
|
||||
#else
|
||||
static constexpr bool thread_safe = false;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Log handler for sending messages to a syslog server.
|
||||
*
|
||||
@@ -60,9 +84,8 @@ class SyslogService : public uuid::log::Handler {
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
SyslogService() = default;
|
||||
|
||||
~SyslogService();
|
||||
SyslogService() = default;
|
||||
~SyslogService() = default;
|
||||
|
||||
/**
|
||||
* Register the log handler with the logging framework.
|
||||
@@ -110,6 +133,14 @@ class SyslogService : public uuid::log::Handler {
|
||||
*/
|
||||
void maximum_log_messages(size_t count);
|
||||
|
||||
/**
|
||||
* Get the current number of queued log messages.
|
||||
*
|
||||
* @return The current number of queued log messages.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
size_t current_log_messages() const;
|
||||
|
||||
/**
|
||||
* Get the server to send messages to.
|
||||
*
|
||||
@@ -129,7 +160,6 @@ class SyslogService : public uuid::log::Handler {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
void destination(IPAddress host, uint16_t port = DEFAULT_PORT);
|
||||
void destination(const char * host, uint16_t port = DEFAULT_PORT);
|
||||
|
||||
/**
|
||||
* Get local hostname.
|
||||
@@ -185,7 +215,7 @@ class SyslogService : public uuid::log::Handler {
|
||||
virtual void operator<<(std::shared_ptr<uuid::log::Message> message);
|
||||
|
||||
/**
|
||||
* added MichaelDvP
|
||||
* added for EMS-ESP
|
||||
* query status variables
|
||||
*/
|
||||
size_t queued() {
|
||||
@@ -227,14 +257,27 @@ class SyslogService : public uuid::log::Handler {
|
||||
QueuedLogMessage(unsigned long id, std::shared_ptr<uuid::log::Message> && content);
|
||||
~QueuedLogMessage() = default;
|
||||
|
||||
unsigned long id_; /*!< Sequential identifier for this log message. @since 1.0.0 */
|
||||
struct timeval time_; /*!< Time message was received. @since 1.0.0 */
|
||||
const std::shared_ptr<const uuid::log::Message> content_; /*!< Log message content. @since 1.0.0 */
|
||||
unsigned long id_; /*!< Sequential identifier for this log message. @since 1.0.0 */
|
||||
struct timeval time_; /*!< Time message was received. @since 1.0.0 */
|
||||
std::shared_ptr<const uuid::log::Message> content_; /*!< Log message content. @since 1.0.0 */
|
||||
|
||||
private:
|
||||
static bool time_good_; /*!< System time appears to be valid. @since 1.0.0 */
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param[in] message New log message, shared by all handlers.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
void add_message(std::shared_ptr<uuid::log::Message> & message);
|
||||
|
||||
/**
|
||||
* Remove messages that were queued before the log level was set.
|
||||
*
|
||||
@@ -264,20 +307,25 @@ class SyslogService : public uuid::log::Handler {
|
||||
|
||||
static uuid::log::Logger logger_; /*!< uuid::log::Logger instance for syslog services. @since 1.0.0 */
|
||||
|
||||
bool started_ = false; /*!< Flag to indicate that messages have started being transmitted. @since 1.0.0 */
|
||||
WiFiUDP udp_; /*!< UDP client. @since 1.0.0 */
|
||||
IPAddress ip_; /*!< Host-IP to send messages to. @since 1.0.0 */
|
||||
std::string host_; /*!< Host to send messages to. */
|
||||
uint16_t port_ = DEFAULT_PORT; /*!< Port to send messages to. @since 1.0.0 */
|
||||
uint64_t last_transmit_ = 0; /*!< Last transmit time. @since 1.0.0 */
|
||||
std::string hostname_{'-'}; /*!< Local hostname. @since 1.0.0 */
|
||||
bool started_ = false; /*!< Flag to indicate that messages have started being transmitted. @since 1.0.0 */
|
||||
bool level_set_ = false; /*!< Flag to indicate that the log level has been set at least once. @since 2.2.0 */
|
||||
WiFiUDP udp_; /*!< UDP client. @since 1.0.0 */
|
||||
IPAddress host_; /*!< Host to send messages to. @since 1.0.0 */
|
||||
uint16_t port_ = DEFAULT_PORT; /*!< Port to send messages to. @since 1.0.0 */
|
||||
uint64_t last_transmit_ = 0; /*!< Last transmit time. @since 1.0.0 */
|
||||
std::string hostname_{'-'}; /*!< Local hostname. @since 1.0.0 */
|
||||
#if UUID_SYSLOG_THREAD_SAFE
|
||||
mutable std::mutex mutex_; /*!< Mutex for queued log messages. @since 2.2.0 */
|
||||
#endif
|
||||
size_t maximum_log_messages_ = MAX_LOG_MESSAGES; /*!< Maximum number of log messages to buffer before they are output. @since 1.0.0 */
|
||||
unsigned long log_message_id_ = 0; /*!< The next identifier to use for queued log messages. @since 1.0.0 */
|
||||
std::list<QueuedLogMessage> log_messages_; /*!< Queued log messages, in the order they were received. @since 1.0.0 */
|
||||
std::atomic<bool> log_messages_overflow_{false}; /*!< Check if log messages have overflowed the buffer. @since 1.0.0 */
|
||||
uint64_t mark_interval_ = 0; /*!< Mark interval in milliseconds. @since 2.0.0 */
|
||||
uint64_t last_message_ = 0; /*!< Last message/mark time. @since 2.0.0 */
|
||||
unsigned long log_message_fails_ = 0;
|
||||
uint64_t mark_interval_ = 0; /*!< Mark interval in milliseconds. @since 2.0.0 */
|
||||
uint64_t last_message_ = 0; /*!< Last message/mark time. @since 2.0.0 */
|
||||
|
||||
// added by MichaelDvP for EMS-ESP
|
||||
IPAddress ip_; /*!< Host-IP to send messages to. @since 1.0.0 */
|
||||
unsigned long log_message_fails_ = 0;
|
||||
};
|
||||
|
||||
} // namespace syslog
|
||||
|
||||
Reference in New Issue
Block a user