diff options
author | Max Kellermann <max@duempel.org> | 2008-12-29 17:28:34 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-02 17:47:08 +0100 |
commit | 8da4b82ca38480a88477ff92b595047dd676c515 (patch) | |
tree | c0beab94f0516350767f37d053b050259b6385d0 | |
parent | 0b6543da585ffbfb6dcc97b67041a5f63a33b76c (diff) | |
download | mpd-8da4b82ca38480a88477ff92b595047dd676c515.tar.gz mpd-8da4b82ca38480a88477ff92b595047dd676c515.tar.xz mpd-8da4b82ca38480a88477ff92b595047dd676c515.zip |
log: automatically append newline
If a log message does not include a newline character, append it.
-rw-r--r-- | src/log.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -66,6 +66,21 @@ static const char *log_date(void) return buf; } +/** + * Determines the length of the string excluding trailing whitespace + * characters. + */ +static int +chomp_length(const char *p) +{ + size_t length = strlen(p); + + while (length > 0 && g_ascii_isspace(p[length - 1])) + --length; + + return (int)length; +} + static void mpd_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level, @@ -90,10 +105,10 @@ mpd_log_func(const gchar *log_domain, if (log_domain == NULL) log_domain = ""; - fprintf(file, "%s%s%s%s", + fprintf(file, "%s%s%s%.*s\n", stdout_mode ? "" : log_date(), log_domain, *log_domain == 0 ? "" : ": ", - message); + chomp_length(message), message); g_free(converted); } |