helper api: log through syslog 41/2941/1
authorAndy Green <andy.green@linaro.org>
Sat, 19 Jan 2013 03:12:16 +0000 (11:12 +0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:27 +0000 (13:01 -0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
README-test-server
lib/libwebsockets.c
lib/libwebsockets.h

index cd0e789..4f0926c 100644 (file)
@@ -426,6 +426,10 @@ Also using lws_set_log_level api you may provide a custom callback to actually
 emit the log string.  By default, this points to an internal emit function
 that sends to stderr.  Setting it to NULL leaves it as it is instead.
 
+A helper function lwsl_emit_syslog() is exported from the library to simplify
+logging to syslog.  You still need to use setlogmask, openlog and closelog
+in your user code.
+
 
 Websocket version supported
 ---------------------------
index fda2a95..6113f9b 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "private-libwebsockets.h"
+#include <syslog.h>
 
 #ifdef WIN32
 #include <tchar.h>
@@ -2171,6 +2172,27 @@ static void lwsl_emit_stderr(int level, const char *line)
        fprintf(stderr, "%s%s", buf, line);
 }
 
+void lwsl_emit_syslog(int level, const char *line)
+{
+       int syslog_level = LOG_DEBUG;
+
+       switch (level) {
+       case LLL_ERR:
+               syslog_level = LOG_ERR;
+               break;
+       case LLL_WARN:
+               syslog_level = LOG_WARNING;
+               break;
+       case LLL_NOTICE:
+               syslog_level = LOG_NOTICE;
+               break;
+       case LLL_INFO:
+               syslog_level = LOG_INFO;
+               break;
+       }
+       syslog(syslog_level, line);
+}
+
 void _lws_log(int filter, const char *format, ...)
 {
        char buf[256];
index c565491..a5e283d 100644 (file)
@@ -674,6 +674,9 @@ struct libwebsocket_extension {
 LWS_EXTERN
 void lws_set_log_level(int level, void (*log_emit_function)(int level, const char *line));
 
+LWS_EXTERN void
+lwsl_emit_syslog(int level, const char *line);
+
 LWS_EXTERN struct libwebsocket_context *
 libwebsocket_create_context(int port, const char * interf,
                  struct libwebsocket_protocols *protocols,