Fix log_timestamp_format not applying to log_dest topic.

Closes #1862. Thanks to Kaushik-27.
This commit is contained in:
Roger A. Light 2020-10-27 10:35:45 +00:00
parent 88b5daee66
commit 916c3744f3
2 changed files with 9 additions and 4 deletions

View File

@ -57,6 +57,7 @@ Broker:
- Add "deny" acl type. Closes #1611. - Add "deny" acl type. Closes #1611.
- The broker now sends the receive-maximum property for MQTT v5 CONNACKs. - The broker now sends the receive-maximum property for MQTT v5 CONNACKs.
- mosquitto_password now forbids the : character. Closes #1833. - mosquitto_password now forbids the : character. Closes #1833.
- Fix `log_timestamp_format` not applying to `log_dest topic`. Closes #1862.
Client library: Client library:
- Client no longer generates random client ids for v3.1.1 clients, these are - Client no longer generates random client ids for v3.1.1 clients, these are

View File

@ -309,8 +309,8 @@ int log__vprintf(unsigned int priority, const char *fmt, va_list va)
if(log_timestamp && log_timestamp_format){ if(log_timestamp && log_timestamp_format){
struct tm *ti = NULL; struct tm *ti = NULL;
get_time(&ti); get_time(&ti);
if(strftime(time_buf, 50, log_timestamp_format, ti) == 0){ if(strftime(time_buf, sizeof(time_buf), log_timestamp_format, ti) == 0){
snprintf(time_buf, 50, "Time error"); snprintf(time_buf, sizeof(time_buf), "Time error");
} }
} }
if(log_destinations & MQTT3_LOG_STDOUT){ if(log_destinations & MQTT3_LOG_STDOUT){
@ -356,13 +356,17 @@ int log__vprintf(unsigned int priority, const char *fmt, va_list va)
} }
if(log_destinations & MQTT3_LOG_TOPIC && priority != MOSQ_LOG_DEBUG && priority != MOSQ_LOG_INTERNAL){ if(log_destinations & MQTT3_LOG_TOPIC && priority != MOSQ_LOG_DEBUG && priority != MOSQ_LOG_INTERNAL){
if(log_timestamp){ if(log_timestamp){
len += 30; len += sizeof(time_buf);;
st = mosquitto__malloc(len*sizeof(char)); st = mosquitto__malloc(len*sizeof(char));
if(!st){ if(!st){
mosquitto__free(s); mosquitto__free(s);
return MOSQ_ERR_NOMEM; return MOSQ_ERR_NOMEM;
} }
snprintf(st, len, "%d: %s", (int)now, s); if(log_timestamp_format){
snprintf(st, len, "%s: %s", time_buf, s);
}else{
snprintf(st, len, "%d: %s", (int)now, s);
}
db__messages_easy_queue(&int_db, NULL, topic, 2, (uint32_t)strlen(st), st, 0, 20, NULL); db__messages_easy_queue(&int_db, NULL, topic, 2, (uint32_t)strlen(st), st, 0, 20, NULL);
mosquitto__free(st); mosquitto__free(st);
}else{ }else{