Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/Syslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ Syslog &Syslog::server(const char* server, uint16_t port) {
return *this;
}

Syslog &Syslog::server(IPAddress ip, uint16_t port) {
this->_ip = ip;
this->_port = port;
return *this;
}


Syslog &Syslog::deviceHostname(const char* deviceHostname) {
this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname;
return *this;
Expand Down Expand Up @@ -102,6 +109,35 @@ Syslog &Syslog::logf(const char *fmt, ...) {
return *this;
}

Syslog &Syslog::vlogf_P(uint16_t pri, PGM_P formatP, ...) {
va_list arg;
va_start(arg, formatP);
char* temp = new char[64];
if(!temp){
return *this;
}
char* buffer = temp;
size_t len = vsnprintf_P(temp, 64, formatP, arg);
va_end(arg);
if (len > 63) {
buffer = new char[len + 1];
if (!buffer) {
return *this;
}
va_start(arg, formatP);
vsnprintf_P(buffer, len + 1, formatP, arg);
va_end(arg);
}
this->_sendLog(pri, buffer);
if (buffer != temp) {
delete[] buffer;
}
delete[] temp;
return *this;
}



Syslog &Syslog::log(const __FlashStringHelper *message) {
return this->_sendLog(this->_priDefault, message);
}
Expand All @@ -119,7 +155,7 @@ Syslog &Syslog::log(const char *message) {
Syslog &Syslog::_sendLog(uint16_t pri, const char *message) {
int result;

if (this->_server == NULL || this->_port == 0)
if ( (this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0)
return *this;

// Check priority against priMask values.
Expand Down
7 changes: 6 additions & 1 deletion src/Syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <IPAddress.h>
#include <Udp.h>

#if defined(__SAMD21G18A__)
#define vsnprintf_P vsnprintf
#endif

// undefine ugly logf macro from avr's math.h
// this fix compilation errors on AtmelAVR platforms
#if defined(logf)
Expand Down Expand Up @@ -109,7 +113,8 @@ class Syslog {
Syslog &log(uint16_t pri, const char *message);

Syslog &vlogf(uint16_t pri, const char *fmt, va_list args);

Syslog &vlogf_P(uint16_t pri, PGM_P formatP, ...) __attribute__ ((format (printf, 3, 4)));

Syslog &logf(uint16_t pri, const char *fmt, ...);
Syslog &logf(const char *fmt, ...);

Expand Down