LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
streamlog.h
Go to the documentation of this file.
1#pragma once
2#include <Print.h>
3#include <Stream.h>
4#include <Arduino.h>
5#include <HardwareSerial.h>
6#include <inttypes.h>
7
8#if defined (STM32)
9#include <USBSerial.h>
10#endif
11
12#ifndef LOGBUFFER_SIZE
13#define LOGBUFFER_SIZE 85
14#endif
15
16#ifdef SYSLOG_ENABLE
17#include <Syslog.h>
18#endif
19
20extern uint8_t serialDebugLevel;
21extern uint8_t udpDebugLevel;
22
23
24#ifndef SerialPortType
25#define SerialPortType Stream
26#endif
27
28#define LOG_TRACE 9
29#define LOG_DEBUG 7
30#define LOG_INFO 6
31#define LOG_ERROR 3
32
33#define traceSerial if (serialDebugLevel>=LOG_TRACE || udpDebugLevel>=LOG_TRACE) debugSerial
34class Streamlog : public Print
35{
36 public:
37 #ifdef SYSLOG_ENABLE
38 Streamlog (SerialPortType * _serialPort, uint8_t _severity = LOG_DEBUG, Syslog * _syslog = NULL, uint8_t _ledPattern = 0);
39 #else
40 Streamlog (SerialPortType * _serialPort, uint8_t _severity = LOG_DEBUG, uint8_t _ledPattern = 0);
41 #endif
42 //void begin(unsigned long speed);
43 //void end() ;
44
45 int available(void);
46 int peek(void);
47 int read(void);
48 void flush(void);
49 size_t write(uint8_t ch);
50 using Print::write; // pull in write(str) and write(buf, size) from Print
51 operator bool() {return true;};
52 private:
53 uint8_t severity;
54 SerialPortType *serialPort;
55 uint8_t ledPattern;
56 #ifdef SYSLOG_ENABLE
57 Syslog * syslog;
58 #endif
59};
int peek(void)
Definition streamlog.cpp:55
size_t write(uint8_t ch)
Definition streamlog.cpp:74
Streamlog(SerialPortType *_serialPort, uint8_t _severity=LOG_DEBUG, uint8_t _ledPattern=0)
Definition streamlog.cpp:30
int read(void)
Definition streamlog.cpp:61
int available(void)
Definition streamlog.cpp:49
void flush(void)
Definition streamlog.cpp:68
uint8_t serialDebugLevel
Definition streamlog.cpp:12
uint8_t udpDebugLevel
Definition streamlog.cpp:13
#define LOG_DEBUG
Definition streamlog.h:29
#define SerialPortType
Definition streamlog.h:25