mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-21 16:26:03 +01:00
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#ifndef StringLogger_h
|
|
#define StringLogger_h
|
|
|
|
#include "MemStream.h"
|
|
#include "RingStream.h"
|
|
#include "StringFormatter.h"
|
|
#include <stdarg.h>
|
|
|
|
// stream for diagnostics in addition to serial you should be able to configure
|
|
// additional (besides Serial) 'outputs' to e.g. Ethernet or MQTT or WIFI etc ...
|
|
// Serial outpout is managed in StringFormatter on top for formatting the message
|
|
// which gets printed char by char
|
|
|
|
#define MAXWRITERS 10
|
|
|
|
typedef void (*DiagWriter)(const char *msg, const int length);
|
|
|
|
class StringLogger
|
|
{
|
|
|
|
private:
|
|
// Methods
|
|
StringLogger() = default;
|
|
StringLogger(const StringLogger &); // non construction-copyable
|
|
StringLogger &operator=(const StringLogger &); // non copyable
|
|
|
|
// Members
|
|
static StringLogger singleton; // unique instance of the MQTTInterface object
|
|
DiagWriter writers[MAXWRITERS];
|
|
int registered = 0; // number of registered writers ( Serial is not counted as always used )
|
|
|
|
public:
|
|
// Methods
|
|
static StringLogger &get() noexcept
|
|
{ // return a reference to the unique instance
|
|
return singleton;
|
|
}
|
|
void diag(const FSH *input...);
|
|
void addDiagWriter(DiagWriter l);
|
|
~StringLogger() = default;
|
|
|
|
// Members
|
|
};
|
|
|
|
#endif |