[rtems-libbsd commit] Default syslog priority to INFO. Add rtems_setlogpriority to configure the priority.

Chris Johns chrisj at rtems.org
Wed Jun 29 23:20:11 UTC 2016


Module:    rtems-libbsd
Branch:    master
Commit:    4a2b84469e41786a2cde2b59447f0f135a99e614
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=4a2b84469e41786a2cde2b59447f0f135a99e614

Author:    Chris Johns <chrisj at rtems.org>
Date:      Thu Jun 30 09:14:55 2016 +1000

Default syslog priority to INFO. Add rtems_setlogpriority to configure the priority.

The rc.conf has 'syslog_priority' where the priority is the name, eg

 syslog_priority="debug"

sets the priority to "debug".

---

 rtemsbsd/include/rtems/bsd/bsd.h |  9 +++++++++
 rtemsbsd/rtems/syslog.c          | 37 +++++++++++++++++++++++++++++++------
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/rtemsbsd/include/rtems/bsd/bsd.h b/rtemsbsd/include/rtems/bsd/bsd.h
index 1583dc9..f687eaf 100644
--- a/rtemsbsd/include/rtems/bsd/bsd.h
+++ b/rtemsbsd/include/rtems/bsd/bsd.h
@@ -221,6 +221,15 @@ void rtems_bsd_set_vprintf_handler(int (*new_vprintf_handler)
  */
 int rtems_bsd_vprintf(int level, const char *fmt, va_list ap);
 
+/**
+ * @brief Set the syslog priority. See syslog.h for the names.
+ *
+ * @param priority One of the standard names.
+ * @retval 0 Priority set.
+ * @retval errno Otherwise.
+ */
+int rtems_bsd_setlogpriority(const char* priority);
+
 /** @} */
 
 #ifdef __cplusplus
diff --git a/rtemsbsd/rtems/syslog.c b/rtemsbsd/rtems/syslog.c
index 7616256..f356690 100644
--- a/rtemsbsd/rtems/syslog.c
+++ b/rtemsbsd/rtems/syslog.c
@@ -37,25 +37,35 @@
  * SUCH DAMAGE.
  */
 
+#include <errno.h>
+#include <stddef.h>
+#include <strings.h>
+
+#define SYSLOG_NAMES
 #include <syslog.h>
 
 #include <rtems/bsd/bsd.h>
 
+static int syslog_priority = LOG_NOTICE;
+
 void
 syslog(int priority, const char *format, ...)
 {
-	va_list ap;
+	if (priority <= syslog_priority) {
+		va_list ap;
 
-	va_start(ap, format);
-	vsyslog(priority, format, ap);
-	va_end(ap);
+		va_start(ap, format);
+		vsyslog(priority, format, ap);
+		va_end(ap);
+	}
 }
 
 void
 vsyslog(int priority, const char *format, va_list ap)
 {
-
-	rtems_bsd_vprintf(priority, format, ap);
+	if (priority <= syslog_priority) {
+		rtems_bsd_vprintf(priority, format, ap);
+	}
 }
 
 void
@@ -75,3 +85,18 @@ setlogmask(int mask)
 {
 	/* TODO */
 }
+
+int
+rtems_bsd_setlogpriority(const char* priority)
+{
+	CODE* c = &prioritynames[0];
+	while (c->c_name != NULL) {
+		if (strcasecmp(c->c_name, priority) == 0) {
+			syslog_priority = c->c_val;
+			return 0;
+		}
+		++c;
+	}
+	errno = ENOENT;
+	return -1;
+}



More information about the vc mailing list