1
0
mirror of https://github.com/eclipse/mosquitto.git synced 2025-05-09 01:01:11 +08:00

Fix file logging on Windows.

Closes #1880. Thanks to J1EXA, richl, and EnneiteZer.
This commit is contained in:
Roger A. Light 2020-11-17 11:08:20 +00:00
parent 47f4cb8159
commit f02c67fecf
2 changed files with 8 additions and 1 deletions

View File

@ -81,6 +81,7 @@ Broker:
- Fix listener not being reassociated with client when reloading a persistence
file and `per_listener_settings true` is set and the client did not set a
username. Closes #1891.
- Fix file logging on Windows. Closes #1880.
Client library:
- Client no longer generates random client ids for v3.1.1 clients, these are

View File

@ -37,6 +37,8 @@ Contributors:
HANDLE syslog_h;
#endif
static char log_fptr_buffer[BUFSIZ];
/* Options for logging should be:
*
* A combination of:
@ -113,7 +115,7 @@ int log__init(struct mosquitto__config *config)
if(log_destinations & MQTT3_LOG_FILE){
config->log_fptr = mosquitto__fopen(config->log_file, "at", true);
if(config->log_fptr){
setvbuf(config->log_fptr, NULL, _IOLBF, 0);
setvbuf(config->log_fptr, log_fptr_buffer, _IOLBF, sizeof(log_fptr_buffer));
}else{
log_destinations = MQTT3_LOG_STDERR;
log_priorities = MOSQ_LOG_ERR;
@ -304,6 +306,10 @@ int log__vprintf(unsigned int priority, const char *fmt, va_list va)
}
if(log_destinations & MQTT3_LOG_FILE && log_fptr){
fprintf(log_fptr, "%s\n", log_line);
#ifdef WIN32
/* Windows doesn't support line buffering, so flush. */
fflush(log_fptr);
#endif
}
if(log_destinations & MQTT3_LOG_SYSLOG){
#ifndef WIN32