diff --git a/include/villas/log.h b/include/villas/log.h index 4166c1500..22919e074 100644 --- a/include/villas/log.h +++ b/include/villas/log.h @@ -40,11 +40,11 @@ extern "C" { #endif /* The log level which is passed as first argument to print() */ -#define LOG_LVL_DEBUG GRY("Debug") -#define LOG_LVL_INFO WHT("Info ") -#define LOG_LVL_WARN YEL("Warn ") -#define LOG_LVL_ERROR RED("Error") -#define LOG_LVL_STATS MAG("Stats") +#define LOG_LVL_DEBUG CLR_GRY("Debug") +#define LOG_LVL_INFO CLR_WHT("Info ") +#define LOG_LVL_WARN CLR_YEL("Warn ") +#define LOG_LVL_ERROR CLR_RED("Error") +#define LOG_LVL_STATS CLR_MAG("Stats") /** Debug facilities. * diff --git a/include/villas/utils.h b/include/villas/utils.h index 138426e47..1d090ac63 100644 --- a/include/villas/utils.h +++ b/include/villas/utils.h @@ -41,21 +41,22 @@ #endif /* Some color escape codes for pretty log messages */ -#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 */ /* Alternate character set */ #define ACS(chr) "\e(0" chr "\e(B" #define ACS_HORIZONTAL ACS("\x71") #define ACS_VERTICAL ACS("\x78") #define ACS_VERTRIGHT ACS("\x74") +#define CLR(clr, str) "\e[" XSTR(clr) "m" str "\e[0m" +#define CLR_GRY(str) CLR(30, str) /**< Print str in gray */ +#define CLR_RED(str) CLR(31, str) /**< Print str in red */ +#define CLR_GRN(str) CLR(32, str) /**< Print str in green */ +#define CLR_YEL(str) CLR(33, str) /**< Print str in yellow */ +#define CLR_BLU(str) CLR(34, str) /**< Print str in blue */ +#define CLR_MAG(str) CLR(35, str) /**< Print str in magenta */ +#define CLR_CYN(str) CLR(36, str) /**< Print str in cyan */ +#define CLR_WHT(str) CLR(37, str) /**< Print str in white */ +#define CLR_BLD(str) CLR( 1, str) /**< Print str in bold */ /* CPP stringification */ #define XSTR(x) STR(x) diff --git a/lib/fpga/ips/rtds_axis.c b/lib/fpga/ips/rtds_axis.c index 76f11f6e6..c9f34cb93 100644 --- a/lib/fpga/ips/rtds_axis.c +++ b/lib/fpga/ips/rtds_axis.c @@ -24,11 +24,11 @@ void rtds_axis_dump(struct fpga_ip *c) { INDENT info("RTDS status: %#08x", sr); { INDENT - info("Card detected: %s", sr & RTDS_AXIS_SR_CARDDETECTED ? GRN("yes") : RED("no")); - info("Link up: %s", sr & RTDS_AXIS_SR_LINKUP ? GRN("yes") : RED("no")); - info("TX queue full: %s", sr & RTDS_AXIS_SR_TX_FULL ? RED("yes") : GRN("no")); - info("TX in progress: %s", sr & RTDS_AXIS_SR_TX_INPROGRESS ? YEL("yes") : "no"); - info("Case running: %s", sr & RTDS_AXIS_SR_CASE_RUNNING ? GRN("yes") : RED("no")); + info("Card detected: %s", sr & RTDS_AXIS_SR_CARDDETECTED ? CLR_GRN("yes") : CLR_RED("no")); + info("Link up: %s", sr & RTDS_AXIS_SR_LINKUP ? CLR_GRN("yes") : CLR_RED("no")); + info("TX queue full: %s", sr & RTDS_AXIS_SR_TX_FULL ? CLR_RED("yes") : CLR_GRN("no")); + info("TX in progress: %s", sr & RTDS_AXIS_SR_TX_INPROGRESS ? CLR_YEL("yes") : "no"); + info("Case running: %s", sr & RTDS_AXIS_SR_CASE_RUNNING ? CLR_GRN("yes") : CLR_RED("no")); } info("RTDS control: %#08x", regs[RTDS_AXIS_CR_OFFSET/4]); diff --git a/lib/node.c b/lib/node.c index 6ff8a666b..9770a49f0 100644 --- a/lib/node.c +++ b/lib/node.c @@ -207,7 +207,7 @@ int node_write(struct node *n, struct sample *smps[], unsigned cnt) char * node_name(struct node *n) { if (!n->_name) - strcatf(&n->_name, RED("%s") "(" YEL("%s") ")", n->name, plugin_name(n->_vt)); + strcatf(&n->_name, CLR_RED("%s") "(" CLR_YEL("%s") ")", n->name, plugin_name(n->_vt)); return n->_name; } diff --git a/lib/node_type.c b/lib/node_type.c index 92a26c851..c0a75f436 100644 --- a/lib/node_type.c +++ b/lib/node_type.c @@ -36,7 +36,7 @@ int node_type_start(struct node_type *vt, struct super_node *sn) if (vt->state != STATE_DESTROYED) return 0; - info("Initializing " YEL("%s") " node type which is used by %zu nodes", node_type_name(vt), list_length(&vt->instances)); + info("Initializing " CLR_YEL("%s") " node type which is used by %zu nodes", node_type_name(vt), list_length(&vt->instances)); { INDENT ret = vt->init ? vt->init(sn) : 0; } @@ -54,7 +54,7 @@ int node_type_stop(struct node_type *vt) if (vt->state != STATE_STARTED) return 0; - info("De-initializing " YEL("%s") " node type", node_type_name(vt)); + info("De-initializing " CLR_YEL("%s") " node type", node_type_name(vt)); { INDENT ret = vt->deinit ? vt->deinit() : 0; } diff --git a/lib/path.c b/lib/path.c index 948935ce6..375166366 100644 --- a/lib/path.c +++ b/lib/path.c @@ -404,12 +404,12 @@ const char * path_name(struct path *p) if (list_length(&p->destinations) == 1) { struct path_destination *pd = (struct path_destination *) list_first(&p->destinations); - strcatf(&p->_name, "%s " MAG("=>") " %s", + strcatf(&p->_name, "%s " CLR_MAG("=>") " %s", node_name_short(p->source->node), node_name_short(pd->node)); } else { - strcatf(&p->_name, "%s " MAG("=>") " [", node_name_short(p->source->node)); + strcatf(&p->_name, "%s " CLR_MAG("=>") " [", node_name_short(p->source->node)); for (size_t i = 0; i < list_length(&p->destinations); i++) { struct path_destination *pd = list_at(&p->destinations, i); diff --git a/lib/utils.c b/lib/utils.c index 111e979cc..416d92861 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -39,7 +39,7 @@ pthread_t main_thread; void print_copyright() { printf("VILLASnode %s (built on %s %s)\n", - BLU(BUILDID), MAG(__DATE__), MAG(__TIME__)); + CLR_BLU(BUILDID), CLR_MAG(__DATE__), CLR_MAG(__TIME__)); printf(" Copyright 2014-2017, Institute for Automation of Complex Power Systems, EONERC\n"); printf(" Steffen Vogel \n"); } diff --git a/src/node.c b/src/node.c index c09916d14..f6e8ed2cc 100644 --- a/src/node.c +++ b/src/node.c @@ -50,7 +50,7 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx) super_node_stop(&sn); super_node_destroy(&sn); - info(GRN("Goodbye!")); + info(CLR_GRN("Goodbye!")); exit(EXIT_SUCCESS); } @@ -101,8 +101,8 @@ int main(int argc, char *argv[]) usage(); #endif - info("This is VILLASnode %s (built on %s, %s)", BLD(YEL(BUILDID)), - BLD(MAG(__DATE__)), BLD(MAG(__TIME__))); + info("This is VILLASnode %s (built on %s, %s)", CLR_BLD(CLR_YEL(BUILDID)), + CLR_BLD(CLR_MAG(__DATE__)), CLR_BLD(CLR_MAG(__TIME__))); /* Checks system requirements*/ struct version kver, reqv = { KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN }; diff --git a/src/pipe.c b/src/pipe.c index 7ffc34619..8e9e26b9d 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -74,7 +74,7 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx) super_node_stop(&sn); super_node_destroy(&sn); - info(GRN("Goodbye!")); + info(CLR_GRN("Goodbye!")); exit(EXIT_SUCCESS); } diff --git a/src/signal.c b/src/signal.c index fe916b35d..14ebbdbf0 100644 --- a/src/signal.c +++ b/src/signal.c @@ -81,7 +81,7 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx) { signal_close(&n); - info(GRN("Goodbye!")); + info(CLR_GRN("Goodbye!")); exit(EXIT_SUCCESS); } diff --git a/tests/unit/fpga.c b/tests/unit/fpga.c index 5e30f8a0e..76471b74d 100644 --- a/tests/unit/fpga.c +++ b/tests/unit/fpga.c @@ -305,7 +305,7 @@ Test(fpga, dma, .description = "DMA") ret = memcmp(src.base_virt, dst.base_virt, src.len); - info("DMA %s (%s): %s", dm->name, dma->inst.HasSg ? "scatter-gather" : "simple", ret ? RED("failed") : GRN("passed")); + info("DMA %s (%s): %s", dm->name, dma->inst.HasSg ? "scatter-gather" : "simple", ret ? CLR_RED("failed") : CLR_GRN("passed")); ret = switch_disconnect(card->sw, dm, dm); cr_assert_eq(ret, 0, "Failed to configure switch");