diff --git a/ChangeLog.txt b/ChangeLog.txt index 55ef2661c..ee17cd2a7 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -73,6 +73,7 @@ Broker: - TLS v1.1 now not enabled by default. It is still possible to explicitly choose TLS v1.1, but this is not recommended and will be removed in a future version. +- Add -q option to allow logging to be disabled at the command line. Plugins / plugin interface: - Add support for modifying outgoing messages using MOSQ_EVT_MESSAGE_OUT. diff --git a/man/mosquitto.8.xml b/man/mosquitto.8.xml index 3696c17ab..b8a4313d6 100644 --- a/man/mosquitto.8.xml +++ b/man/mosquitto.8.xml @@ -23,6 +23,7 @@ --daemon -p port number + -q -v --tls-keylog file @@ -68,6 +69,18 @@ file, then the options are IGNORED. + + + + + Disable all logging. This is equivalent to setting + to in + the configuration file. This overrides any logging + options given in the configuration file and also + overrides . + + + file @@ -91,7 +104,7 @@ Use verbose logging. This is equivalent to setting to in - the configuration file. This overrides and logging + the configuration file. This overrides any logging options given in the configuration file. diff --git a/src/conf.c b/src/conf.c index c56164c7a..4e6521bfa 100644 --- a/src/conf.c +++ b/src/conf.c @@ -274,7 +274,9 @@ static void config__init_reload(struct mosquitto__config *config) #else config->log_facility = LOG_DAEMON; config->log_dest = MQTT3_LOG_STDERR | MQTT3_LOG_DLT; - if(db.verbose){ + if(db.quiet){ + config->log_type = 0; + }else if(db.verbose){ config->log_type = UINT_MAX; }else{ config->log_type = MOSQ_LOG_ERR | MOSQ_LOG_WARNING | MOSQ_LOG_NOTICE | MOSQ_LOG_INFO; @@ -490,6 +492,8 @@ static void print_usage(void) printf(" -h : display this help.\n"); printf(" -p : start the broker listening on the specified port.\n"); printf(" Not recommended in conjunction with the -c option.\n"); + printf(" -q : quiet mode - disable all logging types. This overrides\n"); + printf(" any logging options given in the config file, and -v.\n"); printf(" -v : verbose mode - enable all logging types. This overrides\n"); printf(" any logging options given in the config file.\n"); printf(" --test-config : test config file and exit\n"); @@ -558,6 +562,8 @@ int config__parse_args(struct mosquitto__config *config, int argc, char *argv[]) fprintf(stderr, "Error: TLS support not available so --tls-keylog is not available.\n"); return MOSQ_ERR_INVAL; #endif + }else if(!strcmp(argv[i], "-q") || !strcmp(argv[i], "--quiet")){ + db.quiet = true; }else if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose")){ db.verbose = true; }else if(!strcmp(argv[i], "--test-config")){ @@ -576,7 +582,9 @@ int config__parse_args(struct mosquitto__config *config, int argc, char *argv[]) return MOSQ_ERR_NOMEM; } } - if(db.verbose){ + if(db.quiet){ + config->log_type = 0; + }else if(db.verbose){ config->log_type = UINT_MAX; } @@ -791,7 +799,9 @@ int config__read(struct mosquitto__config *config, bool reload) if(cr.log_dest_set){ config->log_dest = cr.log_dest; } - if(db.verbose){ + if(db.quiet){ + config->log_type = 0; + }else if(db.verbose){ config->log_type = UINT_MAX; }else if(cr.log_type_set){ config->log_type = cr.log_type; diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 2bf92ff23..0f8cd1890 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -490,6 +490,7 @@ struct mosquitto_db{ unsigned long msg_store_bytes; char *config_file; struct mosquitto__config *config; + bool quiet; bool verbose; #ifdef WITH_SYS_TREE int subscription_count;