X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fverbose.c;h=2b0090737ea4ac6d6c56f3f6f19f2f37d7ba4940;hb=305d98f7b6db1a3207cc877bd2cda819e3b90656;hp=a91aeb1f02d2f3ca62fd463d1b8b8a6b0a639124;hpb=f2584b67445ca63d3ec8e4a11202a19250434fc8;p=src%2Fapp-framework-binder.git diff --git a/src/verbose.c b/src/verbose.c index a91aeb1f..2b009073 100644 --- a/src/verbose.c +++ b/src/verbose.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 "IoT.bzh" + Copyright (C) 2016, 2017 "IoT.bzh" author: José Bollo @@ -29,14 +29,14 @@ int verbosity = 1; #include -void vverbose(int level, const char *file, int line, const char *fmt, va_list args) +void vverbose(int level, const char *file, int line, const char *function, const char *fmt, va_list args) { char *p; if (file == NULL || vasprintf(&p, fmt, args) < 0) vsyslog(level, fmt, args); else { - syslog(LEVEL(level), "%s [%s:%d]", p, file, line); + syslog(LEVEL(level), "%s [%s:%d, function]", p, file, line, function); free(p); } } @@ -46,9 +46,38 @@ void verbose_set_name(const char *name, int authority) openlog(name, LOG_PERROR, authority ? LOG_AUTH : LOG_USER); } +#elif defined(VERBOSE_WITH_SYSTEMD) + +#define SD_JOURNAL_SUPPRESS_LOCATION + +#include + +static const char *appname; + +static int appauthority; + +void vverbose(int level, const char *file, int line, const char *function, const char *fmt, va_list args) +{ + char lino[20]; + + if (file == NULL) { + sd_journal_printv(level, fmt, args); + } else { + sprintf(lino, "%d", line); + sd_journal_printv_with_location(level, file, lino, function, fmt, args); + } +} + +void verbose_set_name(const char *name, int authority) +{ + appname = name; + appauthority = authority; +} + #else #include +#include static const char *appname; @@ -65,14 +94,16 @@ static const char *prefixes[] = { "<7> DEBUG" }; -void vverbose(int level, const char *file, int line, const char *fmt, va_list args) +void vverbose(int level, const char *file, int line, const char *function, const char *fmt, va_list args) { + int saverr = errno; int tty = isatty(fileno(stderr)); + errno = saverr; fprintf(stderr, "%s: ", prefixes[LEVEL(level)] + (tty ? 4 : 0)); vfprintf(stderr, fmt, args); - if (file != NULL && (!tty || verbosity >5)) - fprintf(stderr, " [%s:%d]\n", file, line); + if (file != NULL && (!tty || verbosity > 2)) + fprintf(stderr, " [%s:%d,%s]\n", file, line, function); else fprintf(stderr, "\n"); } @@ -85,12 +116,12 @@ void verbose_set_name(const char *name, int authority) #endif -void verbose(int level, const char *file, int line, const char *fmt, ...) +void verbose(int level, const char *file, int line, const char *function, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - vverbose(level, file, line, fmt, ap); + vverbose(level, file, line, function, fmt, ap); va_end(ap); }