EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0
From: mdavidsaver via Core-talk <[email protected]>
To: [email protected]
Date: Tue, 24 Sep 2019 01:28:24 -0000
mdavidsaver has proposed merging ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0.

Requested reviews:
  EPICS Core Developers (epics-core)

For more details, see:
https://code.launchpad.net/~epics-core/epics-base/+git/Com/+merge/373098

Bridge from IOC errlog to syslog
    
If supported (!WIN32 && !vxWorks), and if $EPICS_IOC_LOG_IDENT is set,
then errlog messages will be passed to syslog().
The value of $EPICS_IOC_LOG_IDENT is used as the syslog identifier.

The idea being that an admin/init system will define EPICS_IOC_LOG_IDENT
appropriately if desired, so there is no need for boilerplate in every st.cmd.

By default this is only enabled for IOCs by calling errlogToSyslog()
from iocBuild().  (in case an IOC indirectly execs eg. caget)

-- 
Your team EPICS Core Developers is requested to review the proposed merge of ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0.
diff --git a/configure/CONFIG_ENV b/configure/CONFIG_ENV
index 59e72d8..c325fe6 100644
--- a/configure/CONFIG_ENV
+++ b/configure/CONFIG_ENV
@@ -54,6 +54,10 @@ EPICS_IOC_IGNORE_SERVERS=""
 # EPICS_IOC_LOG_PORT Log server port number etc.
 EPICS_IOC_LOG_PORT=7004
 
+# Log Client:
+# If set, log to local syslog() with this identifier
+EPICS_IOC_LOG_IDENT=
+
 # Other services:
 
 EPICS_CMD_PROTO_PORT=
diff --git a/modules/database/src/ioc/misc/iocInit.c b/modules/database/src/ioc/misc/iocInit.c
index 05bf788..44bb56c 100644
--- a/modules/database/src/ioc/misc/iocInit.c
+++ b/modules/database/src/ioc/misc/iocInit.c
@@ -194,6 +194,8 @@ int iocBuild(void)
 {
     int status;
 
+    errlogToSyslog();
+
     status = iocBuild_1();
     if (status) return status;
 
diff --git a/modules/libcom/src/env/envDefs.h b/modules/libcom/src/env/envDefs.h
index 8be00a9..41e3d85 100644
--- a/modules/libcom/src/env/envDefs.h
+++ b/modules/libcom/src/env/envDefs.h
@@ -71,6 +71,7 @@ epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_INET;
 epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_LIMIT;
 epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_NAME;
 epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_COMMAND;
+epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_IDENT;
 epicsShareExtern const ENV_PARAM EPICS_CMD_PROTO_PORT;
 epicsShareExtern const ENV_PARAM EPICS_AR_PORT;
 epicsShareExtern const ENV_PARAM IOCSH_PS1;
diff --git a/modules/libcom/src/error/errlog.h b/modules/libcom/src/error/errlog.h
index e8a4fb5..33385d6 100644
--- a/modules/libcom/src/error/errlog.h
+++ b/modules/libcom/src/error/errlog.h
@@ -84,6 +84,14 @@ epicsShareFunc int errlogVprintfNoConsole(const char *pformat,va_list pvar);
 
 epicsShareFunc void errSymLookup(long status, char *pBuf, size_t bufLength);
 
+/** @brief (maybe) send errlog message to syslog.
+ *
+ * If supported (!WIN32 && !vxWorks), and if $EPICS_IOC_LOG_IDENT is set,
+ * then errlog messages will be passed to syslog().
+ * The value of $EPICS_IOC_LOG_IDENT is used as the syslog identifier.
+ */
+epicsShareFunc void errlogToSyslog(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/modules/libcom/src/log/Makefile b/modules/libcom/src/log/Makefile
index 7d7a6b6..092a2fc 100644
--- a/modules/libcom/src/log/Makefile
+++ b/modules/libcom/src/log/Makefile
@@ -12,6 +12,7 @@ INC += iocLog.h
 INC += logClient.h
 Com_SRCS += iocLog.c
 Com_SRCS += logClient.c
+Com_SRCS += syslogSink.c
 
 PROD_HOST += iocLogServer
 
diff --git a/modules/libcom/src/log/syslogSink.c b/modules/libcom/src/log/syslogSink.c
new file mode 100644
index 0000000..b80c8dd
--- /dev/null
+++ b/modules/libcom/src/log/syslogSink.c
@@ -0,0 +1,43 @@
+/*************************************************************************\
+* Copyright (c) 2019 Michael Davidsaver
+* EPICS BASE Versions 3.13.7
+* and higher are distributed subject to a Software License Agreement found
+* in file LICENSE that is included with this distribution.
+\*************************************************************************/
+
+#if !defined(_WIN32) && !defined(vxWorks)
+
+#include <syslog.h>
+
+#define epicsExportSharedSymbols
+#include <errlog.h>
+#include <envDefs.h>
+
+static
+void err2sys(void *unused, const char *message)
+{
+    (void)unused;
+    syslog(LOG_INFO, "%s", message);
+}
+
+void errlogToSyslog(void)
+{
+    const char *ident = envGetConfigParamPtr(&EPICS_IOC_LOG_IDENT);
+
+    if(!ident || !ident[0])
+        return;
+
+    openlog(ident, 0, LOG_USER);
+
+    errlogAddListener(err2sys, 0);
+    syslog(LOG_DEBUG, "Syslog connected");
+}
+
+#else /* !_WIN32 && !vxWorks */
+
+#define epicsExportSharedSymbols
+#include <errlog.h>
+
+void errlogToSyslog(void) {}
+
+#endif /* _WIN32 && !vxWorks */

Replies:
Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 Andrew Johnson via Core-talk
Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 Andrew Johnson via Core-talk
Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 Martin Konrad via Core-talk
Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 Andrew Johnson via Core-talk

Navigate by Date:
Prev: Re: [Merge] ~dirk.zimoch/epics-base:iocLogClientFixesTry2 into epics-base:7.0 mdavidsaver via Core-talk
Next: Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 mdavidsaver via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: EPICS 7 build failures on Appveyor/Windows Freddie Akeroyd - UKRI STFC via Core-talk
Next: Re: [Merge] ~epics-core/epics-base/+git/Com:errlog2syslog into epics-base:7.0 mdavidsaver via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
ANJ, 26 Nov 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·