1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

improved debugging output system

This commit is contained in:
Steffen Vogel 2014-12-05 12:17:27 +01:00
parent 473739b4e5
commit dc8ed60b85
2 changed files with 58 additions and 24 deletions

View file

@ -22,14 +22,21 @@
#endif
/* Some color escape codes for pretty log messages */
#define RED(str) "\x1B[31m" str "\x1B[0m" /**< Print str in red */
#define GRN(str) "\x1B[32m" str "\x1B[0m" /**< Print str in green */
#define YEL(str) "\x1B[33m" str "\x1B[0m" /**< Print str in yellow */
#define BLU(str) "\x1B[34m" str "\x1B[0m" /**< Print str in blue */
#define MAG(str) "\x1B[35m" str "\x1B[0m" /**< Print str in magenta */
#define CYN(str) "\x1B[36m" str "\x1B[0m" /**< Print str in cyan */
#define WHT(str) "\x1B[37m" str "\x1B[0m" /**< Print str in white */
#define BLD(str) "\x1B[1m" str "\x1B[0m" /**< Print str in bold */
#define GRY(str) "\e[30m" str "\e[0m" /**< Print str in gray */
#define RED(str) "\e[31m" str "\e[0m" /**< Print str in red */
#define GRN(str) "\e[32m" str "\e[0m" /**< Print str in green */
#define YEL(str) "\e[33m" str "\e[0m" /**< Print str in yellow */
#define BLU(str) "\e[34m" str "\e[0m" /**< Print str in blue */
#define MAG(str) "\e[35m" str "\e[0m" /**< Print str in magenta */
#define CYN(str) "\e[36m" str "\e[0m" /**< Print str in cyan */
#define WHT(str) "\e[37m" str "\e[0m" /**< Print str in white */
#define BLD(str) "\e[1m" str "\e[0m" /**< Print str in bold */
#define GFX(chr) "\e(0" chr "\e(B"
#define UP(n) "\e[" ## n ## "A"
#define DOWN(n) "\e[" ## n ## "B"
#define RIGHT(n) "\e[" ## n ## "C"
#define LEFT(n) "\e[" ## n ## "D"
/** The log level which is passed as first argument to print() */
enum log_level { DEBUG, INFO, WARN, ERROR };
@ -38,8 +45,22 @@ enum log_level { DEBUG, INFO, WARN, ERROR };
struct settings;
struct sockaddr_in;
struct sockaddr;
struct timespec;
extern int debug;
/* These global variables allow changing the output style and verbosity */
extern int _debug;
extern int _indent;
void outdent(int *old);
#ifdef __GNUC__
#define INDENT int __attribute__ ((__cleanup__(outdent), unused)) _old_indent = _indent++;
#else
#define INDENT ;
#endif
/** Reset the wallclock of debugging outputs */
void epoch_reset();
/** Logs variadic messages to stdout.
*
@ -93,7 +114,7 @@ void hist_dump(unsigned *hist, int length);
/** Printf alike debug message with level. */
#define debug(lvl, msg, ...) do { \
if (lvl <= debug) \
if (lvl <= _debug) \
print(DEBUG, msg, ##__VA_ARGS__); \
} while (0)

View file

@ -22,7 +22,20 @@
#include "utils.h"
/* This global variable contains the debug level for debug() and assert() macros */
int debug = V;
int _debug = V;
int _indent = 0;
struct timespec epoch;
void outdent(int *old)
{
_indent = *old;
}
void epoch_reset()
{
clock_gettime(CLOCK_REALTIME, &epoch);
}
void print(enum log_level lvl, const char *fmt, ...)
{
@ -31,23 +44,20 @@ void print(enum log_level lvl, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
clock_gettime(CLOCK_REALTIME, &ts);
/* Timestamp */
printf("%15.4f", ts.tv_sec + ts.tv_nsec / 1e9);
clock_gettime(CLOCK_REALTIME, &ts);
fprintf(stderr, "%8.3f ", timespec_delta(&epoch, &ts));
switch (lvl) {
case DEBUG: printf(" [" BLU("Debug") "] "); break;
case INFO: printf(" [" WHT("Info ") "] "); break;
case WARN: printf(" [" YEL("Warn ") "] "); break;
case ERROR: printf(" [" RED("Error") "] "); break;
case DEBUG: fprintf(stderr, BLD("%-5s "), GRY("Debug")); break;
case INFO: fprintf(stderr, BLD("%-5s "), " " ); break;
case WARN: fprintf(stderr, BLD("%-5s "), YEL(" Warn")); break;
case ERROR: fprintf(stderr, BLD("%-5s "), RED("Error")); break;
}
vprintf(fmt, ap);
printf("\n");
va_end(ap);
}
if (_indent) {
for (int i = 0; i < _indent-1; i++)
fprintf(stderr, GFX("\x78") " ");
int print_addr(struct sockaddr *sa, char *buf, size_t len)
{
@ -75,6 +85,7 @@ int print_addr(struct sockaddr *sa, char *buf, size_t len)
default:
error("Unsupported address family");
fprintf(stderr, GFX("\x74") " ");
}
}
@ -107,8 +118,11 @@ int parse_addr(const char *addr, struct sockaddr_in *sa, int flags)
}
free(tmp);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
return ret;
va_end(ap);
}
cpu_set_t to_cpu_set(int set)
@ -160,7 +174,6 @@ void hist_plot(unsigned *hist, int length)
max = i;
}
/* Print header */
info("%2s | %5s | %s", "Id", "Value", "Histogram Plot:");