log: automatically append newline
If a log message does not include a newline character, append it.
This commit is contained in:
23
src/log.c
23
src/log.c
@@ -68,6 +68,21 @@ static const char *log_date(void)
|
|||||||
return buf;
|
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
|
static void
|
||||||
file_log_func(const gchar *log_domain,
|
file_log_func(const gchar *log_domain,
|
||||||
G_GNUC_UNUSED GLogLevelFlags log_level,
|
G_GNUC_UNUSED GLogLevelFlags log_level,
|
||||||
@@ -90,10 +105,10 @@ file_log_func(const gchar *log_domain,
|
|||||||
if (log_domain == NULL)
|
if (log_domain == NULL)
|
||||||
log_domain = "";
|
log_domain = "";
|
||||||
|
|
||||||
fprintf(stderr, "%s%s%s%s",
|
fprintf(stderr, "%s%s%s%.*s\n",
|
||||||
stdout_mode ? "" : log_date(),
|
stdout_mode ? "" : log_date(),
|
||||||
log_domain, *log_domain == 0 ? "" : ": ",
|
log_domain, *log_domain == 0 ? "" : ": ",
|
||||||
message);
|
chomp_length(message), message);
|
||||||
|
|
||||||
g_free(converted);
|
g_free(converted);
|
||||||
}
|
}
|
||||||
@@ -170,9 +185,9 @@ syslog_log_func(const gchar *log_domain,
|
|||||||
if (log_domain == NULL)
|
if (log_domain == NULL)
|
||||||
log_domain = "";
|
log_domain = "";
|
||||||
|
|
||||||
syslog(glib_to_syslog_level(log_level), "%s%s%s",
|
syslog(glib_to_syslog_level(log_level), "%s%s%.*s",
|
||||||
log_domain, *log_domain == 0 ? "" : ": ",
|
log_domain, *log_domain == 0 ? "" : ": ",
|
||||||
message);
|
chomp_length(message), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Reference in New Issue
Block a user