diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-03-16 16:06:54 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-11-03 12:24:55 +0100 |
commit | 4bcf5073022c2cefffb0bb51f95f1564e7e447be (patch) | |
tree | 8a9cecd3f291a5467a038580537cf5f31dc30eca /src | |
parent | 7e095d9db3674af91496838c0f3739dbf8ebc60a (diff) |
shl: log: check for trailing newlines
If the format string contains a trailing newline, we now skip writing our
own. We also skip the fn+file information as it would be written on the
next line.
Trailing newlines occur only when forwarding messages from other
libraries. In this case we don't need the fn+file information, anyway.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/shl_log.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/shl_log.c b/src/shl_log.c index 5318710..9acae87 100644 --- a/src/shl_log.c +++ b/src/shl_log.c @@ -386,6 +386,8 @@ static void log__submit(const char *file, const char *prefix = NULL; FILE *out; long long sec, usec; + bool nl; + size_t len; if (log__omit(file, line, func, config, subs, sev)) return; @@ -414,19 +416,20 @@ static void log__submit(const char *file, fprintf(out, "[%.4lld.%.6lld] ", sec, usec); } + len = strlen(format); + nl = format[len - 1] == '\n'; + + if (!func) + func = "<unknown>"; + if (!file) + file = "<unknown>"; + if (line < 0) + line = 0; + vfprintf(out, format, args); - if (sev == LOG_DEBUG) { - if (!func) - func = "<unknown>"; - if (!file) - file = "<unknown>"; - if (line < 0) - line = 0; + if (!nl) fprintf(out, " (%s() in %s:%d)\n", func, file, line); - } else { - fprintf(out, "\n"); - } } static void log__format(const char *file, |