mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added some color to the console log
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@75 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
4f064d9d7a
commit
843c862542
3 changed files with 24 additions and 11 deletions
|
@ -15,6 +15,15 @@
|
|||
|
||||
#include <sched.h>
|
||||
|
||||
/* Some color escape codes for pretty log messages */
|
||||
#define RED(str) "\x1B[31m" str "\x1B[0m"
|
||||
#define GRN(str) "\x1B[32m" str "\x1B[0m"
|
||||
#define YEL(str) "\x1B[33m" str "\x1B[0m"
|
||||
#define BLU(str) "\x1B[34m" str "\x1B[0m"
|
||||
#define MAG(str) "\x1B[35m" str "\x1B[0m"
|
||||
#define CYN(str) "\x1B[36m" str "\x1B[0m"
|
||||
#define WHT(str) "\x1B[37m" str "\x1B[0m"
|
||||
|
||||
struct settings;
|
||||
struct sockaddr_in;
|
||||
struct sockaddr;
|
||||
|
|
|
@ -53,7 +53,8 @@ static void start()
|
|||
for (struct path *p = paths; p; p = p->next) {
|
||||
path_start(p);
|
||||
|
||||
info("Starting path: %12s => %s => %-12s", p->in->name, settings.name, p->out->name);
|
||||
info("Starting path: %12s " GRN("=>") " %s " GRN("=>") " %-12s",
|
||||
p->in->name, settings.name, p->out->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +64,8 @@ static void stop()
|
|||
for (struct path *p = paths; p; p = p->next) {
|
||||
path_stop(p);
|
||||
|
||||
info("Stopping path: %12s => %s => %-12s", p->in->name, settings.name, p->out->name);
|
||||
info("Stopping path: %12s " RED("=>") " %s " RED("=>") " %-12s",
|
||||
p->in->name, settings.name, p->out->name);
|
||||
info(" %u messages received", p->received);
|
||||
info(" %u messages duplicated", p->duplicated);
|
||||
info(" %u messages delayed", p->delayed);
|
||||
|
@ -109,7 +111,7 @@ int main(int argc, char *argv[])
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
info("This is s2ss %s", VERSION);
|
||||
info("This is " BLU("s2ss %s"), VERSION);
|
||||
|
||||
/* Parse configuration file */
|
||||
config_init(&config);
|
||||
|
|
18
src/utils.c
18
src/utils.c
|
@ -20,13 +20,6 @@
|
|||
#include "cfg.h"
|
||||
#include "utils.h"
|
||||
|
||||
static const char *log_prefix[] = {
|
||||
"Debug",
|
||||
"Info",
|
||||
"Warning",
|
||||
"Error"
|
||||
};
|
||||
|
||||
void print(enum log_level lvl, const char *fmt, ...)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
@ -36,7 +29,16 @@ void print(enum log_level lvl, const char *fmt, ...)
|
|||
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
|
||||
printf("%17.6f [%-7s] ", ts.tv_sec + ts.tv_nsec / 1e9, log_prefix[lvl]);
|
||||
/* Timestamp */
|
||||
printf("%15.4f", ts.tv_sec + ts.tv_nsec / 1e9);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
vprintf(fmt, ap);
|
||||
printf("\n");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue