From 6b4fd61817c5067d33c3703086d27d8ff6866412 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 31 Mar 2015 15:02:51 +0200 Subject: [PATCH] improved logging system by adding a line() function --- server/include/hist.h | 2 +- server/include/log.h | 16 +++++++++++----- server/include/utils.h | 8 +++++--- server/src/hist.c | 6 +++++- server/src/log.c | 14 ++++++++------ server/src/server.c | 4 ++-- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/server/include/hist.h b/server/include/hist.h index af26154e2..569f7dbdd 100644 --- a/server/include/hist.h +++ b/server/include/hist.h @@ -9,7 +9,7 @@ #include -#define HIST_HEIGHT 50 +#define HIST_HEIGHT 75 #define HIST_SEQ 17 typedef unsigned hist_cnt_t; diff --git a/server/include/log.h b/server/include/log.h index 6175f48a0..8aea009aa 100644 --- a/server/include/log.h +++ b/server/include/log.h @@ -16,12 +16,14 @@ #define INDENT ; #endif -/** The log level which is passed as first argument to print() */ +/** Width of log output in characters */ +#define LOG_WIDTH 100 -#define DEBUG GRY("Debug") -#define INFO "" -#define WARN YEL("Warn") -#define ERROR RED("Error") +/* The log level which is passed as first argument to print() */ +#define DEBUG GRY("Debug") +#define INFO "" +#define WARN YEL("Warn") +#define ERROR RED("Error") /** Change log indention for current thread. * @@ -65,6 +67,10 @@ void log_vprint(const char *lvl, const char *fmt, va_list va); void debug(int lvl, const char *fmt, ...) __attribute__ ((format(printf, 2, 3))); + +/** Print a horizontal line. */ +void line(); + /** Printf alike info message. */ void info(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); diff --git a/server/include/utils.h b/server/include/utils.h index ed7b0c3dd..bfe635099 100644 --- a/server/include/utils.h +++ b/server/include/utils.h @@ -36,9 +36,11 @@ /* Alternate character set */ #define ACS(chr) "\e(0" chr "\e(B" -#define ACS_VERTICAL ACS("\x78") -#define ACS_VERTRIGHT ACS("\x74s") -s +#define ACS_VERTICAL "|" +#define ACS_HORIZONTAL ACS("\x71") +//#define ACS_VERTICAL ACS("\x78") +#define ACS_VERTRIGHT ACS("\x74") + /* UTF-8 Line drawing characters */ #define UTF8_BOX "\xE2\x96\x88" #define UTF8_VERTICAL "\xE2\x94\x82" diff --git a/server/src/hist.c b/server/src/hist.c index b747ca58e..5c02c8764 100644 --- a/server/src/hist.c +++ b/server/src/hist.c @@ -111,7 +111,9 @@ void hist_print(struct hist *h) void hist_plot(struct hist *h) { - char buf[HIST_HEIGHT] = { '#' }; + char buf[HIST_HEIGHT]; + memset(buf, '#', sizeof(buf)); + unsigned int min = UINT_MAX, max = 0; /* Get max, first & last */ @@ -124,6 +126,8 @@ void hist_plot(struct hist *h) /* Print plot */ info("%9s | %5s | %s", "Value", "Occur", "Histogram Plot:"); + line(); + for (int i = 0; i < h->length; i++) { int bar = HIST_HEIGHT * ((double) h->data[i] / max); diff --git a/server/src/log.c b/server/src/log.c index 9a27f7a09..ea41e7e0b 100644 --- a/server/src/log.c +++ b/server/src/log.c @@ -85,7 +85,14 @@ void log_vprint(const char *lvl, const char *fmt, va_list ap) fprintf(stderr, "\r%s\n", buf); } -/** Printf alike debug message with level. */ +void line() +{ + char buf[LOG_WIDTH]; + memset(buf, 0x71, sizeof(buf)); + + log_print("", "\b" ACS("%.*s"), LOG_WIDTH, buf); +} + void debug(int lvl, const char *fmt, ...) { va_list ap; @@ -97,7 +104,6 @@ void debug(int lvl, const char *fmt, ...) } } -/** Printf alike info message. */ void info(const char *fmt, ...) { va_list ap; @@ -107,7 +113,6 @@ void info(const char *fmt, ...) va_end(ap); } -/** Printf alike warning message. */ void warn(const char *fmt, ...) { va_list ap; @@ -117,7 +122,6 @@ void warn(const char *fmt, ...) va_end(ap); } -/** Print error and exit. */ void error(const char *fmt, ...) { va_list ap; @@ -129,7 +133,6 @@ void error(const char *fmt, ...) die(); } -/** Print error and strerror(errno). */ void serror(const char *fmt, ...) { va_list ap; @@ -143,7 +146,6 @@ void serror(const char *fmt, ...) die(); } -/** Print configuration error and exit. */ void cerror(config_setting_t *cfg, const char *fmt, ...) { va_list ap; diff --git a/server/src/server.c b/server/src/server.c index a55a73eb7..e48be40f5 100644 --- a/server/src/server.c +++ b/server/src/server.c @@ -174,8 +174,8 @@ int main(int argc, char *argv[]) info("Runtime Statistics:"); info("%-32s : %-8s %-8s %-8s %-8s %-8s", "Source " MAG("=>") " Destination", "#Sent", "#Recv", "#Drop", "#Skip", "#Inval"); - info("---------------------------------------------------------------------------"); - + line(); + do { FOREACH(&paths, it) { usleep(settings.stats * 1e6); path_print_stats(it->path);