From f84ffdc98951f0b46c7d0b9b0d47b3e8f24619db Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 18 Jun 2016 20:03:42 -0700 Subject: [PATCH] Allow syslog to be disabled, as in #128 --- Makefile | 2 +- esp-link/cgiservices.c | 20 ++++++++++++++------ esp-link/main.c | 14 ++++++++++---- html/services.js | 3 ++- serial/serbridge.c | 4 ++++ 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 4138886..fb58cb1 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ LED_SERIAL_PIN ?= 14 # --------------- esp-link modules config options --------------- # Optional Modules mqtt -MODULES ?= mqtt rest syslog +MODULES ?= mqtt rest #syslog # --------------- esphttpd config options --------------- diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index 6b3f553..200039d 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -2,9 +2,11 @@ #include "cgiwifi.h" #include "cgi.h" #include "config.h" -#include "syslog.h" #include "sntp.h" #include "cgimqtt.h" +#ifdef SYSLOG +#include "syslog.h" +#endif #ifdef CGISERVICES_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -92,10 +94,10 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) { } void ICACHE_FLASH_ATTR cgiServicesSNTPInit() { - if (flashConfig.sntp_server[0] != '\0') { + if (flashConfig.sntp_server[0] != '\0') { sntp_stop(); if (true == sntp_set_timezone(flashConfig.timezone_offset)) { - sntp_setservername(0, flashConfig.sntp_server); + sntp_setservername(0, flashConfig.sntp_server); sntp_init(); } DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset); @@ -107,23 +109,27 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - os_sprintf(buff, + os_sprintf(buff, "{ " +#ifdef SYSLOG "\"syslog_host\": \"%s\", " "\"syslog_minheap\": %d, " "\"syslog_filter\": %d, " "\"syslog_showtick\": \"%s\", " "\"syslog_showdate\": \"%s\", " +#endif "\"timezone_offset\": %d, " "\"sntp_server\": \"%s\", " "\"mdns_enable\": \"%s\", " "\"mdns_servername\": \"%s\"" - " }", + " }", +#ifdef SYSLOG flashConfig.syslog_host, flashConfig.syslog_minheap, flashConfig.syslog_filter, flashConfig.syslog_showtick ? "enabled" : "disabled", flashConfig.syslog_showdate ? "enabled" : "disabled", +#endif flashConfig.timezone_offset, flashConfig.sntp_server, flashConfig.mdns_enable ? "enabled" : "disabled", @@ -151,9 +157,11 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { syslog |= getBoolArg(connData, "syslog_showdate", &flashConfig.syslog_showdate); if (syslog < 0) return HTTPD_CGI_DONE; +#ifdef SYSLOG if (syslog > 0) { syslog_init(flashConfig.syslog_host); } +#endif int8_t sntp = 0; sntp |= getInt8Arg(connData, "timezone_offset", &flashConfig.timezone_offset); @@ -168,7 +176,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { int8_t mdns = 0; mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); if (mdns < 0) return HTTPD_CGI_DONE; - + if (mdns > 0) { if (flashConfig.mdns_enable){ DBG("Services: MDNS Enabled\n"); diff --git a/esp-link/main.c b/esp-link/main.c index bf8c6ef..ba2cf8d 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -29,13 +29,19 @@ #include "config.h" #include "log.h" #include "gpio.h" -#include "syslog.h" #include "cgiservices.h" -#define NOTICE(format, ...) do { \ - LOG_NOTICE(format, ## __VA_ARGS__ ); \ - os_printf(format "\n", ## __VA_ARGS__); \ +#ifdef SYSLOG +#include "syslog.h" +#define NOTICE(format, ...) do { \ + LOG_NOTICE(format, ## __VA_ARGS__ ); \ + os_printf(format "\n", ## __VA_ARGS__); \ } while ( 0 ) +#else +#define NOTICE(format, ...) do { \ + os_printf(format "\n", ## __VA_ARGS__); \ +} while ( 0 ) +#endif /* This is the main url->function dispatching data struct. diff --git a/html/services.js b/html/services.js index 17075ff..aedeea3 100644 --- a/html/services.js +++ b/html/services.js @@ -51,7 +51,8 @@ function displayServices(data) { $("#sntp-spinner").setAttribute("hidden", ""); $("#mdns-spinner").setAttribute("hidden", ""); - $("#Syslog-form").removeAttribute("hidden"); + if (data.syslog_host !== undefined) + $("#Syslog-form").removeAttribute("hidden"); $("#SNTP-form").removeAttribute("hidden"); $("#mDNS-form").removeAttribute("hidden"); diff --git a/serial/serbridge.c b/serial/serbridge.c index 1e82e3d..66b180c 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -10,7 +10,11 @@ #include "console.h" #include "slip.h" #include "cmd.h" +#ifdef SYSLOG #include "syslog.h" +#else +#define syslog(X1...) +#endif #define SKIP_AT_RESET