Skip to content

Commit

Permalink
fix ua-cli logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Nov 28, 2024
1 parent 33c3eca commit e2beaae
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tools/ua-cli/ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,23 @@ logCategoryNames[UA_LOGCATEGORIES] =

static void
cliLog(void *context, UA_LogLevel level, UA_LogCategory category,
const char *msg, va_list args) {
if(logLevel > level)
return;
const char *msg, va_list args) {

/* Set to fatal if the level is outside the range */
int logLevelSlot = ((int)level / 100) - 1;
if(logLevelSlot < 0 || logLevelSlot > 5)
logLevelSlot = 5;
int l = ((int)level / 100) - 1;
if(l < 0 || l > 5)
l = 5;

if((int)logLevel - 1 > l)
return;

/* Log */
#define LOGBUFSIZE 512
UA_Byte logbuf[LOGBUFSIZE];
UA_String out = {LOGBUFSIZE, logbuf};
UA_String_vprintf(&out, msg, args);
fprintf(stderr, "%s/%s" ANSI_COLOR_RESET "\t",
logLevelNames[logLevelSlot], logCategoryNames[category]);
logLevelNames[l], logCategoryNames[category]);
fprintf(stderr, "%s\n", logbuf);
fflush(stderr);
}
Expand Down

0 comments on commit e2beaae

Please sign in to comment.