mirror of
https://github.com/anklimov/lighthub
synced 2025-12-07 04:09:49 +03:00
sysLog fixed, added logging library (for serial & syslog)
This commit is contained in:
63
lighthub/streamlog.cpp
Normal file
63
lighthub/streamlog.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "streamlog.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
Streamlog::Streamlog (UARTClass * _serialPort, int _severity , Syslog * _syslog )
|
||||
{
|
||||
serialPort=_serialPort;
|
||||
severity=_severity;
|
||||
syslog=_syslog;
|
||||
}
|
||||
|
||||
void Streamlog::begin(unsigned long speed)
|
||||
{
|
||||
if (serialPort) serialPort->begin(speed);
|
||||
};
|
||||
|
||||
void Streamlog::end()
|
||||
{
|
||||
if (serialPort) serialPort->end();
|
||||
};
|
||||
|
||||
int Streamlog::available(void)
|
||||
{
|
||||
if (serialPort) return serialPort->available();
|
||||
return 0;
|
||||
};
|
||||
|
||||
int Streamlog::peek(void)
|
||||
{
|
||||
if (serialPort) return serialPort->peek();
|
||||
return 0;
|
||||
};
|
||||
|
||||
int Streamlog::read(void)
|
||||
{
|
||||
if (serialPort) return serialPort->read();
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
void Streamlog::flush(void)
|
||||
{
|
||||
if (serialPort) serialPort->flush();
|
||||
|
||||
};
|
||||
|
||||
size_t Streamlog::write(uint8_t ch)
|
||||
{
|
||||
#ifdef SYSLOG_ENABLE
|
||||
if (ch=='\n')
|
||||
{
|
||||
logBuffer[logBufferPos]=0;
|
||||
if (syslog) syslog->log(severity,(char *)logBuffer);
|
||||
logBufferPos=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logBufferPos<LOGBUFFER_SIZE-1 && (ch!='\r')) logBuffer[logBufferPos++]=ch;
|
||||
}
|
||||
#endif
|
||||
if (serialPort) return serialPort->write(ch);
|
||||
|
||||
return 1;
|
||||
};
|
||||
Reference in New Issue
Block a user