diff --git a/ChangeLog.txt b/ChangeLog.txt index 696c25e4..f09e2135 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -11,6 +11,8 @@ Broker: #189. - Fix persistence saving of subscription QoS on big-endian machines. - Fix will retained flag handling on Windows. Closes #222. +- Broker now displays an error if it is unable to open the log file. Closes + #234. Client library: - Support OpenSSL 1.1.0. diff --git a/src/logging.c b/src/logging.c index 79169f90..f1a58111 100644 --- a/src/logging.c +++ b/src/logging.c @@ -71,6 +71,8 @@ int mqtt3_log_init(struct mqtt3_config *config) } config->log_fptr = _mosquitto_fopen(config->log_file, "at"); if(!config->log_fptr){ + log_destinations = MQTT3_LOG_STDERR; + log_priorities = MOSQ_LOG_ERR; _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open log file %s for writing.", config->log_file); return MOSQ_ERR_INVAL; } diff --git a/src/mosquitto.c b/src/mosquitto.c index 55ff678c..9777ad80 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -287,7 +287,10 @@ int main(int argc, char *argv[]) /* Initialise logging only after initialising the database in case we're * logging to topics */ - mqtt3_log_init(&config); + if(mqtt3_log_init(&config)){ + rc = 1; + return rc; + } _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "mosquitto version %s (build date %s) starting", VERSION, TIMESTAMP); if(config.config_file){ _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Config loaded from %s.", config.config_file);