LightHub
streamlog.h
Go to the documentation of this file.
1 #include <Print.h>
2 #include <HardwareSerial.h>
3 #include <inttypes.h>
4 
5 #ifndef LOGBUFFER_SIZE
6 #define LOGBUFFER_SIZE 80
7 #endif
8 
9 #ifdef SYSLOG_ENABLE
10 #include <Syslog.h>
11 static char logBuffer[LOGBUFFER_SIZE];
12 static int logBufferPos=0;
13 #endif
14 
15 #define LOG_DEBUG 7
16 #define LOG_INFO 6
17 #define LOG_ERROR 3
18 
19 static uint8_t serialDebugLevel = 7;
20 static uint8_t udpDebugLevel =7;
21 
22 class Streamlog : public Print
23 {
24  public:
25  #ifdef SYSLOG_ENABLE
26  Streamlog (HardwareSerial * _serialPort, int _severity = LOG_DEBUG, Syslog * _syslog = NULL, uint8_t _ledPattern = 0);
27  #else
28  Streamlog (HardwareSerial * _serialPort, int _severity = LOG_DEBUG, uint8_t _ledPattern = 0);
29  #endif
30  // {serialPort=_serialPort;severity=_severity; syslog=_syslog; }
31  void begin(unsigned long speed);
32  void end() ;
33 
34  int available(void);
35  int peek(void);
36  int read(void);
37  void flush(void);
38  size_t write(uint8_t ch);
39  using Print::write; // pull in write(str) and write(buf, size) from Print
40  operator bool() {return true;};
41  private:
42  uint16_t severity;
43  HardwareSerial *serialPort;
44  #ifdef SYSLOG_ENABLE
45  Syslog * syslog;
46  uint8_t ledPattern;
47  #endif
48 };
Streamlog::end
void end()
Definition: streamlog.cpp:31
Streamlog::available
int available(void)
Definition: streamlog.cpp:36
LOGBUFFER_SIZE
#define LOGBUFFER_SIZE
Definition: streamlog.h:6
Streamlog::write
size_t write(uint8_t ch)
Definition: streamlog.cpp:61
Streamlog::flush
void flush(void)
Definition: streamlog.cpp:55
Streamlog::peek
int peek(void)
Definition: streamlog.cpp:42
Streamlog::begin
void begin(unsigned long speed)
Definition: streamlog.cpp:26
Streamlog
Definition: streamlog.h:23
Streamlog::read
int read(void)
Definition: streamlog.cpp:48
Streamlog::Streamlog
Streamlog(HardwareSerial *_serialPort, int _severity=LOG_DEBUG, uint8_t _ledPattern=0)
Definition: streamlog.cpp:19
LOG_DEBUG
#define LOG_DEBUG
Definition: streamlog.h:15