logging: Switch to using libosmocore logging for all the code
diff --git a/sgsnemu/Makefile.am b/sgsnemu/Makefile.am
index 8ce1b61..4d02eca 100644
--- a/sgsnemu/Makefile.am
+++ b/sgsnemu/Makefile.am
@@ -2,8 +2,8 @@
 
 AM_LDFLAGS = @EXEC_LDFLAGS@
 
-AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb
+AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS)
 
-sgsnemu_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a
+sgsnemu_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS)
 sgsnemu_DEPENDENCIES = ../gtp/libgtp.la ../lib/libmisc.a
 sgsnemu_SOURCES = sgsnemu.c cmdline.c cmdline.h
diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c
index 79494c9..5b56751 100644
--- a/sgsnemu/sgsnemu.c
+++ b/sgsnemu/sgsnemu.c
@@ -18,7 +18,8 @@
 #define _GNU_SOURCE 1		/* strdup() prototype, broken arpa/inet.h */
 #endif
 
-#include <syslog.h>
+#include <osmocom/core/application.h>
+
 #include <ctype.h>
 #include <netdb.h>
 #include <signal.h>
@@ -377,7 +378,7 @@
 	printf("\n");
 	if (args_info.dns_arg) {
 		if (!(host = gethostbyname(args_info.dns_arg))) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"Invalid DNS address: %s!", args_info.dns_arg);
 			return -1;
 		} else {
@@ -398,7 +399,7 @@
 	/* Do hostname lookup to translate hostname to IP address       */
 	if (args_info.listen_arg) {
 		if (!(host = gethostbyname(args_info.listen_arg))) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"Invalid listening address: %s!",
 				args_info.listen_arg);
 			return -1;
@@ -409,7 +410,7 @@
 			       args_info.listen_arg, inet_ntoa(options.listen));
 		}
 	} else {
-		sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+		SYS_ERR(DSGSN, LOGL_ERROR, 0,
 			"Listening address must be specified: %s!",
 			args_info.listen_arg);
 		return -1;
@@ -420,7 +421,7 @@
 	/* Do hostname lookup to translate hostname to IP address       */
 	if (args_info.remote_arg) {
 		if (!(host = gethostbyname(args_info.remote_arg))) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"Invalid remote address: %s!",
 				args_info.remote_arg);
 			return -1;
@@ -431,7 +432,7 @@
 			       args_info.remote_arg, inet_ntoa(options.remote));
 		}
 	} else {
-		sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+		SYS_ERR(DSGSN, LOGL_ERROR, 0,
 			"No remote address given!");
 		return -1;
 	}
@@ -844,7 +845,7 @@
 	if (args_info.net_arg) {
 		if (ippool_aton
 		    (&options.net, &options.mask, args_info.net_arg, 0)) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"Invalid network address: %s!",
 				args_info.net_arg);
 			exit(1);
@@ -880,7 +881,7 @@
 	/* Store ping host as in_addr                                   */
 	if (args_info.pinghost_arg) {
 		if (!(host = gethostbyname(args_info.pinghost_arg))) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"Invalid ping host: %s!",
 				args_info.pinghost_arg);
 			return -1;
@@ -1179,7 +1180,7 @@
 	    (struct timeval *)&p8[CREATEPING_IP + CREATEPING_ICMP];
 
 	if (datasize > CREATEPING_MAX) {
-		sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+		SYS_ERR(DSGSN, LOGL_ERROR, 0,
 			"Ping size to large: %d!", datasize);
 		return -1;
 	}
@@ -1410,15 +1411,7 @@
 	struct timeval tv;
 	int diff;
 
-	/* open a connection to the syslog daemon */
-	/*openlog(PACKAGE, LOG_PID, LOG_DAEMON); */
-	/* TODO: Only use LOG__PERROR for linux */
-
-#ifdef __linux__
-	openlog(PACKAGE, (LOG_PID | LOG_PERROR), LOG_DAEMON);
-#else
-	openlog(PACKAGE, (LOG_PID), LOG_DAEMON);
-#endif
+	osmo_init_logging(&log_info);
 
 	/* Process options given in configuration file and command line */
 	if (process_options(argc, argv))
@@ -1426,7 +1419,7 @@
 
 	printf("\nInitialising GTP library\n");
 	if (gtp_new(&gsn, options.statedir, &options.listen, GTP_MODE_SGSN)) {
-		sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Failed to create gtp");
+		SYS_ERR(DSGSN, LOGL_ERROR, 0, "Failed to create gtp");
 		exit(1);
 	}
 	if (gsn->fd0 > maxfd)
@@ -1447,7 +1440,7 @@
 		printf("Setting up interface\n");
 		/* Create a tunnel interface */
 		if (tun_new((struct tun_t **)&tun)) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"Failed to create tun");
 			exit(1);
 		}
@@ -1498,7 +1491,7 @@
 
 		if (options.gtpversion == 0) {
 			if (options.qos.l - 1 > sizeof(pdp->qos_req0)) {
-				sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+				SYS_ERR(DSGSN, LOGL_ERROR, 0,
 					"QoS length too big");
 				exit(1);
 			} else {
@@ -1535,7 +1528,7 @@
 		pdp->norecovery_given = options.norecovery_given;
 
 		if (options.apn.l > sizeof(pdp->apn_use.v)) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"APN length too big");
 			exit(1);
 		} else {
@@ -1549,7 +1542,7 @@
 		memcpy(pdp->gsnlu.v, &options.listen, sizeof(options.listen));
 
 		if (options.msisdn.l > sizeof(pdp->msisdn.v)) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"MSISDN length too big");
 			exit(1);
 		} else {
@@ -1559,7 +1552,7 @@
 		ipv42eua(&pdp->eua, NULL);	/* Request dynamic IP address */
 
 		if (options.pco.l > sizeof(pdp->pco_req.v)) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"PCO length too big");
 			exit(1);
 		} else {
@@ -1674,7 +1667,7 @@
 
 		switch (select(maxfd + 1, &fds, NULL, NULL, &idleTime)) {
 		case -1:
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"Select returned -1");
 			break;
 		case 0:
@@ -1685,7 +1678,7 @@
 		}
 
 		if ((tun) && FD_ISSET(tun->fd, &fds) && tun_decaps(tun) < 0) {
-			sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+			SYS_ERR(DSGSN, LOGL_ERROR, 0,
 				"TUN decaps failed");
 		}