{"schema":"libjg2-1",
"vpath":"/git/",
"avatar":"/git/avatar/",
"alang":"",
"gen_ut":1752657795,
"reponame":"libwebsockets",
"desc":"libwebsockets lightweight C networking library",
"owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets",
"f":3,
"items": [
{"schema":"libjg2-1",
"cid":"f0977f3c485f56b4b349efc186bf3eba",
"commit": {"type":"commit",
"time": 1357953462,
"time_ofs": 480,
"oid_tree": { "oid": "672b228e18e18fa2fcd1e06c82f972a3686b554e", "alias": []},
"oid":{ "oid": "de8f27a80b0bf015ea26bdb6b9958bc5283c8cb1", "alias": []},
"msg": "logging extend level set api to allow setting emission function",
"sig_commit": { "git_time": { "time": 1357953462, "offset": 480 }, "name": "Andy Green", "email": "andy.green@linaro.org", "md5": "4863edaebb4491aa6049a4d2d9c98c2c" },
"sig_author": { "git_time": { "time": 1357953462, "offset": 480 }, "name": "Andy Green", "email": "andy.green@linaro.org", "md5": "4863edaebb4491aa6049a4d2d9c98c2c" }},
"body": "logging extend level set api to allow setting emission function\n\nSigned-off-by: Andy Green \u003candy.green@linaro.org\u003e\n"
,
"diff": "diff --git a/README-test-server b/README-test-server\nindex 234f43d..a8d9999 100644\n--- a/README-test-server\n+++ b/README-test-server\n@@ -262,6 +262,10 @@ available are (OR together the numbers to select multiple)\n 64 EXTENSION\n 128 CLIENT\n \n+Also using lws_set_log_level api you may provide a custom callback to actually\n+emit the log string. By default, this points to an internal emit function\n+that sends to stderr. Setting it to NULL leaves it as it is instead.\n+\n \n Websocket version supported\n ---------------------------\ndiff --git a/lib/libwebsockets.c b/lib/libwebsockets.c\nindex b0e7a6d..53e71e0 100644\n--- a/lib/libwebsockets.c\n+++ b/lib/libwebsockets.c\n@@ -44,6 +44,8 @@ int openssl_websocket_private_data_index;\n #endif\n \n static int log_level \u003d LLL_ERR | LLL_WARN;\n+static void lwsl_emit_stderr(const char *line);\n+static void (*lwsl_emit)(const char *line) \u003d lwsl_emit_stderr;\n static const char *log_level_names[] \u003d {\n \t\u0022ERR\u0022,\n \t\u0022WARN\u0022,\n@@ -3273,35 +3275,50 @@ libwebsocket_ensure_user_space(struct libwebsocket *wsi)\n \treturn wsi-\u003euser_space;\n }\n \n+\n+static void lwsl_emit_stderr(const char *line)\n+{\n+\tfprintf(stderr, \u0022%s\u0022, line);\n+}\n+\n void _lws_log(int filter, const char *format, ...)\n {\n+\tchar buf[256];\n \tva_list ap;\n \tint n;\n+\tint pos \u003d 0;\n \n \tif (!(log_level \u0026 filter))\n \t\treturn;\n \n \tfor (n \u003d 0; n \u003c LLL_COUNT; n++)\n \t\tif (filter \u003d\u003d (1 \u003c\u003c n)) {\n-\t\t\tfprintf(stderr, \u0022%s: \u0022, log_level_names[n]);\n+\t\t\tpos \u003d sprintf(buf, \u0022%s: \u0022, log_level_names[n]);\n \t\t\tbreak;\n \t\t}\n \n \tva_start(ap, format);\n-\tvfprintf(stderr, format, ap);\n-\tva_end(ap); \n+\tvsnprintf(buf + pos, (sizeof buf) - pos, format, ap);\n+\tbuf[(sizeof buf) - 1] \u003d '\u005c0';\n+\tva_end(ap);\n+\n+\tlwsl_emit(buf);\n }\n \n /**\n * lws_set_log_level() - Set the logging bitfield\n * @level:\tOR together the LLL_ debug contexts you want output from\n+ * @log_emit_function:\tNULL to leave it as it is, or a user-supplied\n+ *\t\t\tfunction to perform log string emission instead of\n+ *\t\t\tthe default stderr one.\n *\n- *\n- *\tdefaults to err and warn contexts enabled\n+ *\tlog level defaults to \u0022err\u0022 and \u0022warn\u0022 contexts enabled only and\n+ *\temission on stderr.\n */\n \n-void lws_set_log_level(int level)\n+void lws_set_log_level(int level, void (*log_emit_function)(const char *line))\n {\n \tlog_level \u003d level;\n+\tif (log_emit_function)\n+\t\tlwsl_emit \u003d log_emit_function;\n }\n-\ndiff --git a/lib/libwebsockets.h b/lib/libwebsockets.h\nindex 25aa554..ef951d6 100644\n--- a/lib/libwebsockets.h\n+++ b/lib/libwebsockets.h\n@@ -655,7 +655,7 @@ struct libwebsocket_extension {\n };\n \n LWS_EXTERN\n-void lws_set_log_level(int level);\n+void lws_set_log_level(int level, void (*log_emit_function)(const char *line));\n \n LWS_EXTERN struct libwebsocket_context *\n libwebsocket_create_context(int port, const char * interf,\ndiff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html\nindex b41b4c7..acda2b5 100644\n--- a/libwebsockets-api-doc.html\n+++ b/libwebsockets-api-doc.html\n@@ -353,16 +353,21 @@ having to take any care about data visibility between the processes, it'll\n \u003ch2\u003elws_set_log_level - Set the logging bitfield\u003c/h2\u003e\n \u003ci\u003evoid\u003c/i\u003e\n \u003cb\u003elws_set_log_level\u003c/b\u003e\n-(\u003ci\u003eint\u003c/i\u003e \u003cb\u003elevel\u003c/b\u003e)\n+(\u003ci\u003eint\u003c/i\u003e \u003cb\u003elevel\u003c/b\u003e,\n+\u003ci\u003evoid (*\u003c/i\u003e\u003cb\u003elog_emit_function\u003c/b\u003e) \u003ci\u003e(const char *line)\u003c/i\u003e)\n \u003ch3\u003eArguments\u003c/h3\u003e\n \u003cdl\u003e\n \u003cdt\u003e\u003cb\u003elevel\u003c/b\u003e\n \u003cdd\u003eOR together the LLL_ debug contexts you want output from\n+\u003cdt\u003e\u003cb\u003elog_emit_function\u003c/b\u003e\n+\u003cdd\u003eNULL to leave it as it is, or a user-supplied\n+function to perform log string emission instead of\n+the default stderr one.\n \u003c/dl\u003e\n \u003ch3\u003eDescription\u003c/h3\u003e\n \u003cblockquote\u003e\n-\u003cp\u003e\n-defaults to err and warn contexts enabled\n+log level defaults to \u0022err\u0022 and \u0022warn\u0022 contexts enabled only and\n+emission on stderr.\n \u003c/blockquote\u003e\n \u003chr\u003e\n \u003ch2\u003elibwebsocket_write - Apply protocol then write data to client\u003c/h2\u003e\ndiff --git a/test-server/test-client.c b/test-server/test-client.c\nindex 4d8d474..9f65269 100644\n--- a/test-server/test-client.c\n+++ b/test-server/test-client.c\n@@ -222,7 +222,7 @@ int main(int argc, char **argv)\n \t\t\tcontinue;\n \t\tswitch (n) {\n \t\tcase 'd':\n-\t\t\tlws_set_log_level(atoi(optarg));\n+\t\t\tlws_set_log_level(atoi(optarg), NULL);\n \t\t\tbreak;\n \t\tcase 's':\n \t\t\tuse_ssl \u003d 2; /* 2 \u003d allow selfsigned */\ndiff --git a/test-server/test-fraggle.c b/test-server/test-fraggle.c\nindex 14cc3cd..2e899de 100644\n--- a/test-server/test-fraggle.c\n+++ b/test-server/test-fraggle.c\n@@ -264,7 +264,7 @@ int main(int argc, char **argv)\n \t\t\tcontinue;\n \t\tswitch (n) {\n \t\tcase 'd':\n-\t\t\tlws_set_log_level(atoi(optarg));\n+\t\t\tlws_set_log_level(atoi(optarg), NULL);\n \t\t\tbreak;\n \t\tcase 's':\n \t\t\tuse_ssl \u003d 1;\ndiff --git a/test-server/test-ping.c b/test-server/test-ping.c\nindex 93df59e..bc03100 100644\n--- a/test-server/test-ping.c\n+++ b/test-server/test-ping.c\n@@ -339,7 +339,7 @@ int main(int argc, char **argv)\n \t\t\tcontinue;\n \t\tswitch (n) {\n \t\tcase 'd':\n-\t\t\tlws_set_log_level(atoi(optarg));\n+\t\t\tlws_set_log_level(atoi(optarg), NULL);\n \t\t\tbreak;\n \t\tcase 'm':\n \t\t\tuse_mirror \u003d 1;\ndiff --git a/test-server/test-server-extpoll.c b/test-server/test-server-extpoll.c\nindex 470997c..6266e9f 100644\n--- a/test-server/test-server-extpoll.c\n+++ b/test-server/test-server-extpoll.c\n@@ -460,7 +460,7 @@ int main(int argc, char **argv)\n \t\t\tcontinue;\n \t\tswitch (n) {\n \t\tcase 'd':\n-\t\t\tlws_set_log_level(atoi(optarg));\n+\t\t\tlws_set_log_level(atoi(optarg), NULL);\n \t\t\tbreak;\n \t\tcase 's':\n \t\t\tuse_ssl \u003d 1;\ndiff --git a/test-server/test-server.c b/test-server/test-server.c\nindex 110b475..06bfd6e 100644\n--- a/test-server/test-server.c\n+++ b/test-server/test-server.c\n@@ -417,7 +417,7 @@ int main(int argc, char **argv)\n \t\t\tcontinue;\n \t\tswitch (n) {\n \t\tcase 'd':\n-\t\t\tlws_set_log_level(atoi(optarg));\n+\t\t\tlws_set_log_level(atoi(optarg), NULL);\n \t\t\tbreak;\n \t\tcase 's':\n \t\t\tuse_ssl \u003d 1;\n","s":{"c":1752657795,"u": 7645}}
],"g": 8879,"chitpc": 0,"ehitpc": 0,"indexed":0
,
"ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}