Add websockets logging options.
This commit is contained in:
parent
6fd38b8c47
commit
db86809ee9
@ -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 */
|
||||
|
@ -332,9 +332,12 @@
|
||||
<replaceable>warning</replaceable>,
|
||||
<replaceable>notice</replaceable>,
|
||||
<replaceable>information</replaceable>,
|
||||
<replaceable>subscribe</replaceable>,
|
||||
<replaceable>unsubscribe</replaceable>,
|
||||
<replaceable>websockets</replaceable>,
|
||||
<replaceable>none</replaceable>,
|
||||
<replaceable>all</replaceable>. Defaults to
|
||||
<replaceable>error</replaceable>,
|
||||
<replaceable>all</replaceable>.</para>
|
||||
<para>Defaults to <replaceable>error</replaceable>,
|
||||
<replaceable>warning</replaceable>, <replaceable>notice
|
||||
</replaceable>and
|
||||
<replaceable>information</replaceable>. This option
|
||||
@ -711,6 +714,20 @@
|
||||
<para>Not reloaded on reload signal.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>websockets_log_level</option> <replaceable>level</replaceable></term>
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
<para>To use this option, <option>log_type
|
||||
websockets</option> must also be enabled.
|
||||
Defaults to 0.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect2>
|
||||
<refsect2>
|
||||
|
@ -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
|
||||
|
10
src/conf.c
10
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")
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user