1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

expose log level in emit

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2013-01-19 11:17:56 +08:00
parent 3662b663bc
commit 0b31909cce
2 changed files with 20 additions and 17 deletions

View file

@ -2150,37 +2150,40 @@ int lws_confirm_legit_wsi(struct libwebsocket *wsi)
return 0;
}
static void lwsl_emit_stderr(const char *line)
static void lwsl_emit_stderr(int level, const char *line)
{
fprintf(stderr, "%s", line);
char buf[300];
struct timeval tv;
int pos = 0;
int n;
gettimeofday(&tv, NULL);
buf[0] = '\0';
for (n = 0; n < LLL_COUNT; n++)
if (level == (1 << n)) {
pos = sprintf(buf, "[%ld:%04d] %s: ", tv.tv_sec,
(int)(tv.tv_usec / 100), log_level_names[n]);
break;
}
fprintf(stderr, "%s%s", buf, line);
}
void _lws_log(int filter, const char *format, ...)
{
char buf[256];
va_list ap;
int n;
int pos = 0;
struct timeval tv;
if (!(log_level & filter))
return;
gettimeofday(&tv, NULL);
for (n = 0; n < LLL_COUNT; n++)
if (filter == (1 << n)) {
pos = sprintf(buf, "[%ld:%04d] %s: ", tv.tv_sec,
(int)(tv.tv_usec / 100), log_level_names[n]);
break;
}
va_start(ap, format);
vsnprintf(buf + pos, (sizeof buf) - pos, format, ap);
vsnprintf(buf, (sizeof buf), format, ap);
buf[(sizeof buf) - 1] = '\0';
va_end(ap);
lwsl_emit(buf);
lwsl_emit(filter, buf);
}
/**

View file

@ -671,7 +671,7 @@ struct libwebsocket_extension {
};
LWS_EXTERN
void lws_set_log_level(int level, void (*log_emit_function)(const char *line));
void lws_set_log_level(int level, void (*log_emit_function)(int level, const char *line));
LWS_EXTERN struct libwebsocket_context *
libwebsocket_create_context(int port, const char * interf,