diff --git a/lib/mosquitto.h b/lib/mosquitto.h
index a2cfd65d0d..8bc169219b 100644
--- a/lib/mosquitto.h
+++ b/lib/mosquitto.h
@@ -58,6 +58,7 @@ extern "C" {
#define MOSQ_LOG_DEBUG 0x10
#define MOSQ_LOG_SUBSCRIBE 0x20
#define MOSQ_LOG_UNSUBSCRIBE 0x40
+#define MOSQ_LOG_WEBSOCKETS 0x80
#define MOSQ_LOG_ALL 0xFFFF
/* Error values */
diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml
index c220017afb..59b4c8e75c 100644
--- a/man/mosquitto.conf.5.xml
+++ b/man/mosquitto.conf.5.xml
@@ -332,9 +332,12 @@
warning,
notice,
information,
+ subscribe,
+ unsubscribe,
+ websockets,
none,
- all. Defaults to
- error,
+ all.
+ Defaults to error,
warning, notice
and
information. This option
@@ -711,6 +714,20 @@
Not reloaded on reload signal.
+
+ level
+
+ Change the websockets logging level. This is a
+ global option, it is not possible to set per
+ listener. This is an integer that is interpreted by
+ libwebsockets as a bit mask for its lws_log_levels
+ enum. See the libwebsockets documentation for more
+ details.
+ To use this option, must also be enabled.
+ Defaults to 0.
+
+
diff --git a/mosquitto.conf b/mosquitto.conf
index 475db5283a..df1aa8badc 100644
--- a/mosquitto.conf
+++ b/mosquitto.conf
@@ -470,7 +470,7 @@
# Types of messages to log. Use multiple log_type lines for logging
# multiple types of messages.
# Possible types are: debug, error, warning, notice, information,
-# none, subscribe, unsubscribe, all.
+# none, subscribe, unsubscribe, websockets, all.
# Note that debug type messages are for decoding the incoming/outgoing
# network packets. They are not logged in "topics".
#log_type error
@@ -478,6 +478,13 @@
#log_type notice
#log_type information
+# Change the websockets logging level. This is a global option, it is not
+# possible to set per listener. This is an integer that is interpreted by
+# libwebsockets as a bit mask for its lws_log_levels enum. See the
+# libwebsockets documentation for more details. "log_type websockets" must also
+# be enabled.
+#websockets_log_level 0
+
# If set to true, client connection and disconnection messages will be included
# in the log.
#connection_messages true
diff --git a/src/conf.c b/src/conf.c
index 4de24ab4b5..d00af49d84 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -1381,6 +1381,10 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
cr->log_type |= MOSQ_LOG_SUBSCRIBE;
}else if(!strcmp(token, "unsubscribe")){
cr->log_type |= MOSQ_LOG_UNSUBSCRIBE;
+#ifdef WITH_WEBSOCKETS
+ }else if(!strcmp(token, "websockets")){
+ cr->log_type |= MOSQ_LOG_WEBSOCKETS;
+#endif
}else if(!strcmp(token, "all")){
cr->log_type = INT_MAX;
}else{
@@ -1884,6 +1888,12 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
}
#else
_mosquitto_log_printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
+#endif
+ }else if(!strcmp(token, "websockets_log_level")){
+#ifdef WITH_WEBSOCKETS
+ if(_conf_parse_int(&token, "websockets_log_level", &config->websockets_log_level, saveptr)) return MOSQ_ERR_INVAL;
+#else
+ _mosquitto_log_printf(NULL, MOSQ_LOG_WARNING, "Warning: Websockets support not available.");
#endif
}else if(!strcmp(token, "trace_level")
|| !strcmp(token, "ffdc_output")
diff --git a/src/logging.c b/src/logging.c
index e686d9d730..79169f9053 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -170,6 +170,16 @@ int _mosquitto_log_vprintf(struct mosquitto *mosq, int priority, const char *fmt
syslog_priority = EVENTLOG_INFORMATION_TYPE;
#endif
break;
+#ifdef WITH_WEBSOCKETS
+ case MOSQ_LOG_WEBSOCKETS:
+ topic = "$SYS/broker/log/WS";
+#ifndef WIN32
+ syslog_priority = LOG_DEBUG;
+#else
+ syslog_priority = EVENTLOG_INFORMATION_TYPE;
+#endif
+ break;
+#endif
default:
topic = "$SYS/broker/log/E";
#ifndef WIN32
diff --git a/src/mosquitto.c b/src/mosquitto.c
index d454c57a5a..a68f2e8797 100644
--- a/src/mosquitto.c
+++ b/src/mosquitto.c
@@ -330,7 +330,7 @@ int main(int argc, char *argv[])
}
}else if(config.listeners[i].protocol == mp_websockets){
#ifdef WITH_WEBSOCKETS
- config.listeners[i].ws_context = mosq_websockets_init(&config.listeners[i]);
+ config.listeners[i].ws_context = mosq_websockets_init(&config.listeners[i], config.websockets_log_level);
if(!config.listeners[i].ws_context){
_mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to create websockets listener on port %d.", config.listeners[i].port);
return 1;
diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h
index 29c2434b11..333c1f2385 100644
--- a/src/mosquitto_broker.h
+++ b/src/mosquitto_broker.h
@@ -117,6 +117,9 @@ struct mqtt3_config {
bool upgrade_outgoing_qos;
char *user;
bool verbose;
+#ifdef WITH_WEBSOCKETS
+ int websockets_log_level;
+#endif
#ifdef WITH_BRIDGE
struct _mqtt3_bridge *bridges;
int bridge_count;
@@ -476,7 +479,7 @@ void service_run(void);
* Websockets related functions
* ============================================================ */
#ifdef WITH_WEBSOCKETS
-struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listener);
+struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listener, int log_level);
#endif
void do_disconnect(struct mosquitto_db *db, struct mosquitto *context);
diff --git a/src/websockets.c b/src/websockets.c
index ea39da801c..435248ac63 100644
--- a/src/websockets.c
+++ b/src/websockets.c
@@ -477,7 +477,14 @@ static int callback_http(struct libwebsocket_context *context,
return 0;
}
-struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listener)
+static void log_wrap(int level, const char *line)
+{
+ char *l = (char *)line;
+ l[strlen(line)-1] = '\0'; // Remove \n
+ _mosquitto_log_printf(NULL, MOSQ_LOG_WEBSOCKETS, "%s", l);
+}
+
+struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listener, int log_level)
{
struct lws_context_creation_info info;
struct libwebsocket_protocols *p;
@@ -538,7 +545,8 @@ struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listen
info.user = user;
listener->ws_protocol = p;
- lws_set_log_level(0, NULL);
+ printf("log level: %d\n", log_level);
+ lws_set_log_level(log_level, log_wrap);
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Opening websockets listen socket on port %d.", listener->port);
return libwebsocket_create_context(&info);