64 EXTENSION
128 CLIENT
+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.
+
Websocket version supported
---------------------------
#endif
static int log_level = LLL_ERR | LLL_WARN;
+static void lwsl_emit_stderr(const char *line);
+static void (*lwsl_emit)(const char *line) = lwsl_emit_stderr;
static const char *log_level_names[] = {
"ERR",
"WARN",
return wsi->user_space;
}
+
+static void lwsl_emit_stderr(const char *line)
+{
+ fprintf(stderr, "%s", line);
+}
+
void _lws_log(int filter, const char *format, ...)
{
+ char buf[256];
va_list ap;
int n;
+ int pos = 0;
if (!(log_level & filter))
return;
for (n = 0; n < LLL_COUNT; n++)
if (filter == (1 << n)) {
- fprintf(stderr, "%s: ", log_level_names[n]);
+ pos = sprintf(buf, "%s: ", log_level_names[n]);
break;
}
va_start(ap, format);
- vfprintf(stderr, format, ap);
- va_end(ap);
+ vsnprintf(buf + pos, (sizeof buf) - pos, format, ap);
+ buf[(sizeof buf) - 1] = '\0';
+ va_end(ap);
+
+ lwsl_emit(buf);
}
/**
* lws_set_log_level() - Set the logging bitfield
* @level: OR together the LLL_ debug contexts you want output from
+ * @log_emit_function: NULL to leave it as it is, or a user-supplied
+ * function to perform log string emission instead of
+ * the default stderr one.
*
- *
- * defaults to err and warn contexts enabled
+ * log level defaults to "err" and "warn" contexts enabled only and
+ * emission on stderr.
*/
-void lws_set_log_level(int level)
+void lws_set_log_level(int level, void (*log_emit_function)(const char *line))
{
log_level = level;
+ if (log_emit_function)
+ lwsl_emit = log_emit_function;
}
-
<h2>lws_set_log_level - Set the logging bitfield</h2>
<i>void</i>
<b>lws_set_log_level</b>
-(<i>int</i> <b>level</b>)
+(<i>int</i> <b>level</b>,
+<i>void (*</i><b>log_emit_function</b>) <i>(const char *line)</i>)
<h3>Arguments</h3>
<dl>
<dt><b>level</b>
<dd>OR together the LLL_ debug contexts you want output from
+<dt><b>log_emit_function</b>
+<dd>NULL to leave it as it is, or a user-supplied
+function to perform log string emission instead of
+the default stderr one.
</dl>
<h3>Description</h3>
<blockquote>
-<p>
-defaults to err and warn contexts enabled
+log level defaults to "err" and "warn" contexts enabled only and
+emission on stderr.
</blockquote>
<hr>
<h2>libwebsocket_write - Apply protocol then write data to client</h2>