mirror of
https://github.com/open62541/open62541.git
synced 2026-10-29 05:11:36 +08:00
use color output for logging to stdout
This commit is contained in:
committed by
Julius Pfrommer
parent
15c65b5129
commit
fb499f9270
+17
-2
@@ -7,12 +7,27 @@
|
||||
#include "ua_types_generated.h"
|
||||
#include "ua_types_generated_handling.h"
|
||||
|
||||
/* ANSI escape sequences for color output taken from here:
|
||||
* https://stackoverflow.com/questions/3219393/stdlib-and-colored-output-in-c*/
|
||||
|
||||
#define ANSI_COLOR_RED "\x1b[31m"
|
||||
#define ANSI_COLOR_GREEN "\x1b[32m"
|
||||
#define ANSI_COLOR_YELLOW "\x1b[33m"
|
||||
#define ANSI_COLOR_BLUE "\x1b[34m"
|
||||
#define ANSI_COLOR_MAGENTA "\x1b[35m"
|
||||
#define ANSI_COLOR_CYAN "\x1b[36m"
|
||||
#define ANSI_COLOR_RESET "\x1b[0m"
|
||||
|
||||
#ifdef UA_ENABLE_MULTITHREADING
|
||||
#include <pthread.h>
|
||||
static pthread_mutex_t printf_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
const char *logLevelNames[6] = {"trace", "debug", "info", "warn", "error", "fatal"};
|
||||
const char *logLevelNames[6] = {"trace", "debug",
|
||||
ANSI_COLOR_GREEN "info",
|
||||
ANSI_COLOR_YELLOW "warn",
|
||||
ANSI_COLOR_RED "error",
|
||||
ANSI_COLOR_MAGENTA "fatal"};
|
||||
const char *logCategoryNames[7] = {"network", "channel", "session", "server",
|
||||
"client", "userland", "securitypolicy"};
|
||||
|
||||
@@ -26,7 +41,7 @@ UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category,
|
||||
#ifdef UA_ENABLE_MULTITHREADING
|
||||
pthread_mutex_lock(&printf_mutex);
|
||||
#endif
|
||||
printf("[%.23s] %s/%s\t", t.data, logLevelNames[level], logCategoryNames[category]);
|
||||
printf("[%.23s] %s/%s" ANSI_COLOR_RESET "\t", t.data, logLevelNames[level], logCategoryNames[category]);
|
||||
vprintf(msg, args);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
|
||||
Reference in New Issue
Block a user