Skip to content

Commit

Permalink
Fix "slow" file based logging by switching to line based buffering.
Browse files Browse the repository at this point in the history
Closes #1689. Closes #1741. Thanks to Brett M. Gordon and tt92.
  • Loading branch information
ralight committed Jul 15, 2020
1 parent 8234d24 commit 54f3b68
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -13,6 +13,8 @@ Broker:
Closes #1726.
- Fix websockets clients sometimes not being disconnected promptly.
Closes #1718.
- Fix "slow" file based logging by switching to line based buffering.
Closes #1689. Closes #1741.

Client library:
- Improved documentation around connect callback return codes. Close #1730.
Expand Down
8 changes: 1 addition & 7 deletions src/logging.c
Expand Up @@ -115,6 +115,7 @@ int log__init(struct mosquitto__config *config)
log_priorities = MOSQ_LOG_ERR;
log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open log file %s for writing.", config->log_file);
}
setvbuf(config->log_fptr, NULL, _IOLBF, 0);
restore_privileges();
}
#ifdef WITH_DLT
Expand Down Expand Up @@ -181,7 +182,6 @@ int log__vprintf(int priority, const char *fmt, va_list va)
const char *topic;
int syslog_priority;
time_t now = time(NULL);
static time_t last_flush = 0;
char time_buf[50];
bool log_timestamp = true;
char *log_timestamp_format = NULL;
Expand Down Expand Up @@ -293,7 +293,6 @@ int log__vprintf(int priority, const char *fmt, va_list va)
}else{
fprintf(stdout, "%s\n", s);
}
fflush(stdout);
}
if(log_destinations & MQTT3_LOG_STDERR){
if(log_timestamp){
Expand All @@ -305,7 +304,6 @@ int log__vprintf(int priority, const char *fmt, va_list va)
}else{
fprintf(stderr, "%s\n", s);
}
fflush(stderr);
}
if(log_destinations & MQTT3_LOG_FILE && log_fptr){
if(log_timestamp){
Expand All @@ -317,10 +315,6 @@ int log__vprintf(int priority, const char *fmt, va_list va)
}else{
fprintf(log_fptr, "%s\n", s);
}
if(now - last_flush > 1){
fflush(log_fptr);
last_flush = now;
}
}
if(log_destinations & MQTT3_LOG_SYSLOG){
#ifndef WIN32
Expand Down

0 comments on commit 54f3b68

Please sign in to comment.