Skip to content

Commit 201a12c

Browse files
authored
fix: add missing fflush(stdout) to write log message immediately (#442)
Without fflush(stdout), log messages have incorrect timestamp (added by syslogd or journald), or even get printed out when exit() but not startup.
1 parent 653478c commit 201a12c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/utils.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int set_socket_rcvbuf(int fd, int size) {
8585
*
8686
* @param level Message log level
8787
* @param format printf style format string
88-
* @returns Whatever printf returns
88+
* @return Message length (newline included)
8989
*/
9090
int logger(loglevel_t level, const char *format, ...) {
9191
va_list ap;
@@ -120,7 +120,10 @@ int logger(loglevel_t level, const char *format, ...) {
120120
// Automatically add newline if format doesn't end with one
121121
if (format && strlen(format) > 0 && format[strlen(format) - 1] != '\n') {
122122
fputc('\n', stdout);
123+
r++;
123124
}
125+
126+
fflush(stdout);
124127
}
125128
return r;
126129
}

0 commit comments

Comments
 (0)