From 351184b3a2b597193234d09090281b8501f659c6 Mon Sep 17 00:00:00 2001
From: John Hodge <tpg@ucc.asn.au>
Date: Fri, 21 Mar 2014 22:55:25 +0800
Subject: [PATCH] Allow logging to be disabled, rename 'add' account

---
 dispsrv.conf         |  2 ++
 src/cokebank.h       |  2 +-
 src/server/logging.c | 26 ++++++++++++++++++++++++--
 src/server/main.c    |  3 +++
 4 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/dispsrv.conf b/dispsrv.conf
index 2043708..ae1d954 100644
--- a/dispsrv.conf
+++ b/dispsrv.conf
@@ -14,6 +14,8 @@ coke_modbus_address 0.0.0.0
 test_mode no
 #test_mode yes
 
+disable_syslog yes
+
 # Used to set dispense into a dummy mode when the coke machine is out of action
 # and we're dispensing drinks from the fridge (or manually)
 coke_dummy_mode no
diff --git a/src/cokebank.h b/src/cokebank.h
index 1ea8120..1328c11 100644
--- a/src/cokebank.h
+++ b/src/cokebank.h
@@ -18,7 +18,7 @@
 
 #define COKEBANK_SALES_ACCT	">sales"	//!< Sales made into
 #define COKEBANK_SALES_PREFIX	">sales:"	//!< Sales made into
-#define COKEBANK_ADDSRC_ACCT	">delta"	//!< Credit taken out of
+#define COKEBANK_ADDSRC_ACCT	">additions"	//!< Credit taken out of
 #define COKEBANK_DEBT_ACCT	">countersum"	//!< Balancing account (causes sum to be 0)
 #define COKEBANK_FREE_ACCT	">freeitems"	//!< ODay drink costs taken out of
 #define COKEBANK_DONATE_ACCT	">donations"	//!< Donations go here
diff --git a/src/server/logging.c b/src/server/logging.c
index d7313c9..dc3cc4c 100644
--- a/src/server/logging.c
+++ b/src/server/logging.c
@@ -6,16 +6,29 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include "common.h"
 #include <syslog.h>
 
+// === GLOBALS ===
+bool	gbSyslogEnabled = true;
+
 // === CODE ==
 void Log_Error(const char *Format, ...)
 {
 	va_list	args;
 
 	va_start(args, Format);
-	vsyslog(LOG_WARNING, Format, args);
+	if( gbSyslogEnabled )
+	{
+		vsyslog(LOG_WARNING, Format, args);
+	}
+	else
+	{
+		fprintf(stderr, "WARNING: ");
+		vfprintf(stderr, Format, args);
+		fprintf(stderr, "\n");
+	}
 	va_end(args);
 }
 
@@ -24,7 +37,16 @@ void Log_Info(const char *Format, ...)
 	va_list	args;
 	
 	va_start(args, Format);
-	vsyslog(LOG_INFO, Format, args);
+	if( gbSyslogEnabled )
+	{
+		vsyslog(LOG_INFO, Format, args);
+	}
+	else
+	{
+		fprintf(stderr, "WARNING: ");
+		vfprintf(stderr, Format, args);
+		fprintf(stderr, "\n");
+	}
 	va_end(args);
 }
 
diff --git a/src/server/main.c b/src/server/main.c
index 247533e..284002b 100644
--- a/src/server/main.c
+++ b/src/server/main.c
@@ -9,6 +9,7 @@
  */
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <string.h>
 #include <signal.h>
 #include "common.h"
@@ -30,6 +31,7 @@ extern int	giServer_Port;
 extern const char	*gsItemListFile;
 extern const char	*gsCoke_ModbusAddress;
 extern const char	*gsDoor_SerialPort;
+extern bool	gbSyslogEnabled;
 
 // === PROTOTYPES ===
 void	*Periodic_Thread(void *Unused);
@@ -128,6 +130,7 @@ int main(int argc, char *argv[])
 	gsItemListFile       = Config_GetValue("items_file", 0);
 
 	gbNoCostMode         = (Config_GetValue_Bool("test_mode", 0) == 1);
+	gbSyslogEnabled      = (Config_GetValue_Bool("disable_syslog", 0) == 0);
 
 	signal(SIGINT, sigint_handler);
 	signal(SIGTERM, sigint_handler);
-- 
GitLab