Index: include/libroar/debug.h
===================================================================
--- include/libroar/debug.h	(revision 3607)
+++ include/libroar/debug.h	(revision 3611)
@@ -43,4 +43,13 @@
 #define ROAR_WARNING_ALWAYS      2
 
+#define ROAR_DEBUG_TYPE_ERROR    1
+#define ROAR_DEBUG_TYPE_WARNING  2
+#define ROAR_DEBUG_TYPE_INFO     3
+#define ROAR_DEBUG_TYPE_DEBUG    4
+
+#define ROAR_DEBUG_MODE_SYSIO    0
+#define ROAR_DEBUG_MODE_VIO      1
+#define ROAR_DEBUG_MODE_SYSLOG   2
+
 #if 1
 #define roar_debug_warn_sysio(f,n,i) roar_debug_warn_sysio_real((f),(n),(i))
@@ -55,4 +64,5 @@
 
 void   roar_debug_set_stderr_fh(int fh);
+void   roar_debug_set_stderr_mode(int mode);
 
 struct roar_vio_calls * roar_debug_get_stderr(void);
@@ -60,4 +70,6 @@
 void roar_debug_msg_simple(const char *format, ...);
 
+void roar_debug_msg(int type, unsigned long int line, char * file, char * prefix, char * format, ...);
+
 #endif
 
Index: include/libroar/libroar.h
===================================================================
--- include/libroar/libroar.h	(revision 3567)
+++ include/libroar/libroar.h	(revision 3611)
@@ -53,4 +53,8 @@
 #ifdef ROAR_HAVE_H_SIGNAL
 #include <signal.h>
+#endif
+
+#ifdef ROAR_HAVE_SYSLOG
+#include <syslog.h>
 #endif
 
Index: libroar/debug.c
===================================================================
--- libroar/debug.c	(revision 3607)
+++ libroar/debug.c	(revision 3611)
@@ -36,5 +36,6 @@
 #include "libroar.h"
 
-static int roar_debug_stderr_fh = ROAR_STDERR;
+static int roar_debug_stderr_mode = ROAR_DEBUG_MODE_SYSIO;
+static int roar_debug_stderr_fh   = ROAR_STDERR;
 
 void roar_debug_warn_sysio_real(char * func, char * newfunc, char * info) {
@@ -54,13 +55,24 @@
 }
 
+void   roar_debug_set_stderr_mode(int mode) {
+ roar_debug_stderr_mode = mode;
+}
+
 struct roar_vio_calls * roar_debug_get_stderr(void) {
  static struct roar_vio_calls STDERR;
 
- if ( roar_debug_stderr_fh == -1 )
-  return NULL;
+ switch (roar_debug_stderr_mode) {
+  case ROAR_DEBUG_MODE_SYSIO:
+    if ( roar_debug_stderr_fh == -1 )
+     return NULL;
 
- roar_vio_open_fh(&STDERR, roar_debug_stderr_fh);
+    roar_vio_open_fh(&STDERR, roar_debug_stderr_fh);
 
- return &STDERR;
+    return &STDERR;
+   break;
+  default:
+    return NULL;
+   break;
+ }
 }
 
@@ -70,7 +82,7 @@
  int ret;
  char buf[8192];
+ size_t len;
 
- if ( (vio = roar_debug_get_stderr()) == NULL )
-  return;
+ vio = roar_debug_get_stderr();
 
  va_start(ap, format);
@@ -78,6 +90,80 @@
  va_end(ap);
 
- roar_vio_write(vio, buf, ret);
+ if ( vio != NULL ) {
+  roar_vio_write(vio, buf, ret);
+ } else {
+  switch (roar_debug_stderr_mode) {
+#ifdef ROAR_HAVE_SYSLOG
+   case ROAR_DEBUG_MODE_SYSLOG:
+     // strip \n if needed for syslog:
+     len = strlen(buf);
+     if ( buf[len-1] == '\n' )
+      buf[len-1] = 0;
+
+     syslog(LOG_ERR, "%s", buf); // bad to use some defaults
+    break;
+#endif
+   default:
+     return;
+    break;
+  }
+ }
 }
 
+void roar_debug_msg(int type, unsigned long int line, char * file, char * prefix, char * format, ...) {
+ struct roar_vio_calls * vio;
+ va_list ap;
+ char    buf[8192];
+ char  * bufp = buf;
+ char  * typename;
+ int     ret;
+ int     priority;
+ size_t  len;
+
+ switch (type) {
+  case ROAR_DEBUG_TYPE_ERROR:   typename = "Error";   break;
+  case ROAR_DEBUG_TYPE_WARNING: typename = "Warning"; break;
+  case ROAR_DEBUG_TYPE_INFO:    typename = "Info";    break;
+  case ROAR_DEBUG_TYPE_DEBUG:   typename = "Debug";   break;
+  default: typename = "Unknown Type"; break;
+ }
+
+ ret = snprintf(buf, sizeof(buf), "(%s: %s:%lu): %s: ", prefix, file, line, typename);
+
+ if ( ret > 0 && ret < sizeof(buf) ) {
+  bufp += ret;
+ } else {
+  ret = 0;
+ }
+
+ len = ret;
+
+ va_start(ap, format);
+ ret = vsnprintf(bufp, sizeof(buf)-ret, format, ap);
+ va_end(ap);
+
+ len += ret;
+
+ switch (roar_debug_stderr_mode) {
+  case ROAR_DEBUG_MODE_SYSIO:
+  case ROAR_DEBUG_MODE_VIO:
+    if ( (vio = roar_debug_get_stderr()) == NULL )
+     return;
+    roar_vio_write(vio, buf, len);
+    roar_vio_write(vio, "\n", 1);
+   break;
+#ifdef ROAR_HAVE_SYSLOG
+  case ROAR_DEBUG_MODE_SYSLOG:
+    switch (type) {
+     case ROAR_DEBUG_TYPE_ERROR:   priority = LOG_ERR;     break;
+     case ROAR_DEBUG_TYPE_WARNING: priority = LOG_WARNING; break;
+     case ROAR_DEBUG_TYPE_INFO:    priority = LOG_INFO;    break;
+     case ROAR_DEBUG_TYPE_DEBUG:   priority = LOG_DEBUG;   break;
+     default: priority = LOG_ERR; break;
+    }
+    syslog(priority, "%s", buf);
+   break;
+#endif
+ }
+}
 //ll
