LOGGING: Add syslog log target
diff --git a/include/osmocore/logging.h b/include/osmocore/logging.h
index 5b780a3..d4d632d 100644
--- a/include/osmocore/logging.h
+++ b/include/osmocore/logging.h
@@ -127,6 +127,8 @@
 void log_target_destroy(struct log_target *target);
 struct log_target *log_target_create_stderr(void);
 struct log_target *log_target_create_file(const char *fname);
+struct log_target *log_target_create_syslog(const char *ident, int option,
+					    int facility);
 int log_target_file_reopen(struct log_target *tgt);
 
 void log_add_target(struct log_target *target);
diff --git a/src/Makefile.am b/src/Makefile.am
index d4c6e12..94492c5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,8 +12,9 @@
 libosmocore_la_SOURCES = timer.c select.c signal.c msgb.c rxlev_stat.c bits.c \
 			 tlv_parser.c bitvec.c comp128.c gsm_utils.c statistics.c \
 			 write_queue.c utils.c rsl.c gsm48.c gsm48_ie.c \
-			 logging.c gsm0808.c rate_ctr.c gsmtap_util.c \
-			 gprs_cipher_core.c crc16.c panic.c process.c gsm0480.c
+			 logging.c logging_syslog.c gsm0808.c rate_ctr.c \
+			 gsmtap_util.c gprs_cipher_core.c crc16.c panic.c \
+			 process.c gsm0480.c
 
 if ENABLE_PLUGIN
 libosmocore_la_SOURCES += plugin.c
diff --git a/src/logging_syslog.c b/src/logging_syslog.c
new file mode 100644
index 0000000..b65e819
--- /dev/null
+++ b/src/logging_syslog.c
@@ -0,0 +1,72 @@
+/* Syslog logging support code */
+
+/* (C) 2011 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include "../config.h"
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#include <osmocore/talloc.h>
+#include <osmocore/utils.h>
+#include <osmocore/logging.h>
+
+static const int logp2syslog_level(unsigned int level)
+{
+	if (level >= LOGL_FATAL)
+		return LOG_CRIT;
+	else if (level >= LOGL_ERROR)
+		return LOG_ERR;
+	else if (level >= LOGL_NOTICE)
+		return LOG_NOTICE;
+	else if (level >= LOGL_INFO)
+		return LOG_INFO;
+	else
+		return LOG_DEBUG;
+}
+
+static void _syslog_output(struct log_target *target,
+			   unsigned int level, const char *log)
+{
+	syslog(logp2syslog_level(level), "%s", log);
+}
+
+struct log_target *log_target_create_syslog(const char *ident, int option,
+					    int facility)
+{
+	struct log_target *target;
+
+	target = log_target_create();
+	if (!target)
+		return NULL;
+
+	target->output = _syslog_output;
+
+	openlog(ident, option, facility);
+
+	return target;
+}