diff --git a/src/core/log.c b/src/core/log.c index e415e1591..9f6a10d60 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -11,6 +11,7 @@ #include "nng_impl.h" #include #include +#include #include #ifdef NNG_PLATFORM_WINDOWS #include @@ -167,9 +168,11 @@ stderr_logger(nng_log_level level, nng_log_facility facility, strftime(when, sizeof(when), "%H:%M:%S", tm); // we print with millisecond resolution - (void) fprintf(stderr, "%s[%-6s]: %s.%03d: %s%s%s%s\n", sgr, level_str, + bool trailing_nl = + ((strlen(msg) != 0) && msg[strlen(msg) - 1] == '\n'); + (void) fprintf(stderr, "%s[%-6s]: %s.%03d: %s%s%s%s%s", sgr, level_str, when, nsec / 1000000, msgid ? msgid : "", msgid ? ": " : "", msg, - sgr0); + sgr0, trailing_nl ? "" : "\n"); } void