cli: Introduce a logfile command to log errors to a file

The evolution would be to introduce libosmocore and start using
the logging framework. But even then we can map this option to
the file target.

Fixes: SYS#263
diff --git a/lib/syserr.c b/lib/syserr.c
index 048cd45..66a2067 100644
--- a/lib/syserr.c
+++ b/lib/syserr.c
@@ -20,6 +20,13 @@
 
 #include "syserr.h"
 
+static FILE* err_log;
+
+void sys_err_setlogfile(FILE* log)
+{
+	err_log = log;
+}
+
 void sys_err(int pri, char *fn, int ln, int en, char *fmt, ...)
 {
 	va_list args;
@@ -29,11 +36,17 @@
 	vsnprintf(buf, SYSERR_MSGSIZE, fmt, args);
 	va_end(args);
 	buf[SYSERR_MSGSIZE - 1] = 0;	/* Make sure it is null terminated */
-	if (en)
+	if (en) {
+		if (err_log)
+			fprintf(err_log, "%s: %d: %d (%s) %s\n",
+				fn, ln, en, strerror(en), buf);
 		syslog(pri, "%s: %d: %d (%s) %s", fn, ln, en, strerror(en),
 		       buf);
-	else
+	} else {
+		if (err_log)
+			fprintf(err_log, "%s: %d: %s\n", fn, ln, buf);
 		syslog(pri, "%s: %d: %s", fn, ln, buf);
+	}
 }
 
 void sys_errpack(int pri, char *fn, int ln, int en, struct sockaddr_in *peer,
@@ -65,10 +78,16 @@
 	}
 	buf2[pos] = 0;
 
-	if (en)
+	if (en) {
+		if (err_log)
+			fprintf(err_log, "%s: %d: %d (%s) %s. %s\n",
+				fn, ln, en, strerror(en), buf, buf2);
 		syslog(pri, "%s: %d: %d (%s) %s. %s", fn, ln, en, strerror(en),
 		       buf, buf2);
-	else
+	} else {
+		if (err_log)
+			fprintf(err_log, "%s: %d: %s. %s\n", fn, ln, buf, buf2);
 		syslog(pri, "%s: %d: %s. %s", fn, ln, buf, buf2);
+	}
 
 }