summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-06-24 13:58:56 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-06-24 13:58:56 +0200
commitf2584b67445ca63d3ec8e4a11202a19250434fc8 (patch)
tree6908a83230120d46abcb88b742069ada03d857d3
parent9afa63b69d2061884c8fdf8227cccd1796c34879 (diff)
improves verbose messages
Change-Id: I176f5647512f50dce50d6db2de6204b5bc6e4d52 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/verbose.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/verbose.c b/src/verbose.c
index 53811c00..a91aeb1f 100644
--- a/src/verbose.c
+++ b/src/verbose.c
@@ -48,6 +48,12 @@ void verbose_set_name(const char *name, int authority)
#else
+#include <unistd.h>
+
+static const char *appname;
+
+static int appauthority;
+
static const char *prefixes[] = {
"<0> EMERGENCY",
"<1> ALERT",
@@ -61,9 +67,11 @@ static const char *prefixes[] = {
void vverbose(int level, const char *file, int line, const char *fmt, va_list args)
{
- fprintf(stderr, "%s: ", prefixes[LEVEL(level)]);
+ int tty = isatty(fileno(stderr));
+
+ fprintf(stderr, "%s: ", prefixes[LEVEL(level)] + (tty ? 4 : 0));
vfprintf(stderr, fmt, args);
- if (file != NULL)
+ if (file != NULL && (!tty || verbosity >5))
fprintf(stderr, " [%s:%d]\n", file, line);
else
fprintf(stderr, "\n");
@@ -71,7 +79,8 @@ void vverbose(int level, const char *file, int line, const char *fmt, va_list ar
void verbose_set_name(const char *name, int authority)
{
- fprintf(stderr, "%s: application name is '%s' for '%s'\n", prefixes[5], name, authority ? "AUTHORITY" : "USER");
+ appname = name;
+ appauthority = authority;
}
#endif