From 1f71f8a459a03fbebf53186c25f555696c754fce Mon Sep 17 00:00:00 2001 From: sakeerthy Date: Thu, 3 Sep 2020 22:13:48 -0400 Subject: [PATCH 1/6] WIP zowe log formatting Signed-off-by: sakeerthy --- c/crossmemory.c | 8 ++++---- c/logging.c | 15 +++++++++++---- h/logging.h | 14 +++++++++++++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/c/crossmemory.c b/c/crossmemory.c index e6e419e1b..0ee9965bc 100644 --- a/c/crossmemory.c +++ b/c/crossmemory.c @@ -2986,13 +2986,13 @@ static void printDisplayConfigCommandResponse(CrossMemoryServer *server, CMSWTOR CART cart = routeInfo->cart; int consoleID = routeInfo->consoleID; CrossMemoryServerGlobalArea *globalArea = server->globalArea; - - zowelog(NULL, LOG_COMP_ID_CMS, ZOWE_LOG_INFO, #ifdef CROSS_MEMORY_SERVER_DEBUG - CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\' (debug mode)\n" +#define SERVER_INFO_PREFIX CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\' (debug mode)\n" #else - CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\'\n" +#define SERVER_INFO_PREFIX CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\'\n" #endif + zowelog(NULL, LOG_COMP_ID_CMS, ZOWE_LOG_INFO, + SERVER_INFO_PREFIX " Global area address = 0x%p\n" " Version = %d\n" " Key = %d\n" diff --git a/c/logging.c b/c/logging.c index 82561a5a9..3cced7ab5 100644 --- a/c/logging.c +++ b/c/logging.c @@ -647,8 +647,7 @@ int logGetLevel(LoggingContext *context, uint64 compID){ return component ? component->currentDetailLevel : ZOWE_LOG_NA; } -void zowelog(LoggingContext *context, uint64 compID, int level, char *formatString, ...){ - +void _zowelog(LoggingContext *context, uint64 compID, char* path, int line, int level, char *formatString, ...){ if (logShouldTrace(context, compID, level) == FALSE) { return; } @@ -687,8 +686,16 @@ void zowelog(LoggingContext *context, uint64 compID, int level, char *formatStri } /* here, pass to a var-args handler */ va_start(argPointer, formatString); - - destination->handler(context,component,destination->data,formatString,argPointer); + if (strncmp(context->eyecatcher, "ZOWECNTX", 7) == 0) { + LoggingInfo *info = (LoggingInfo *)safeMalloc(sizeof(LoggingInfo), "LoggingInfo"); + info->level = level; + info->line = line; + info->path = path; + info->compID = compID; + destination->handler(context,component,info,formatString,argPointer); + } else { + destination->handler(context,component,destination->data,formatString,argPointer); + } va_end(argPointer); } diff --git a/h/logging.h b/h/logging.h index 69816a9f5..d27cbafe5 100644 --- a/h/logging.h +++ b/h/logging.h @@ -76,6 +76,8 @@ ZOWE_PRAGMA_PACK_RESET #define LOG_PROD_ZIS 0x008F000200000000LLU #define LOG_PROD_ZSS 0x008F000300000000LLU #define LOG_PROD_PLUGINS 0x008F000400000000LLU +#define LOG_PROD_TEST 0x008F000500000000LLU + #define LOG_COMP_ALLOC 0x008F000100010000LLU #define LOG_COMP_UTILS 0x008F000100020000LLU @@ -121,6 +123,13 @@ typedef struct LoggingDestination_tag{ #define MAX_LOGGING_COMPONENTS 256 #define MAX_LOGGING_DESTINATIONS 32 +typedef struct LoggingInfo_tag { + int level; + int line; + char* path; + uint64 compID; +} LoggingInfo; + typedef struct LoggingVendor_tag { char eyecatcher[8]; /* RSLOGVNR */ unsigned short vendorID; @@ -298,7 +307,7 @@ bool logShouldTraceInternal(LoggingContext *context, uint64 componentID, int lev /* this log message will be sent to the destination associated to the component */ -void zowelog(LoggingContext *context, uint64 compID, int level, char *formatString, ...); +void _zowelog(LoggingContext *context, uint64 compID, char* path, int line, int level, char *formatString, ...); void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int dataSize); #define LOGCHECK(context,component,level) \ @@ -306,6 +315,9 @@ void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int (context->applicationComponents[component].level >= level) : \ (context->coreComponents[component].level >= level) ) +#define zowelog(context, compID, level, formatString, ...) \ + _zowelog(context, compID, __FILE__, __LINE__, level, formatString, ##__VA_ARGS__); + LoggingDestination *logConfigureDestination(LoggingContext *context, unsigned int id, char *name, From bd4b6288007a9506a8d1f297f29a3804a688f64f Mon Sep 17 00:00:00 2001 From: sakeerthy Date: Thu, 3 Sep 2020 22:42:55 -0400 Subject: [PATCH 2/6] free info Signed-off-by: sakeerthy --- c/logging.c | 1 + 1 file changed, 1 insertion(+) diff --git a/c/logging.c b/c/logging.c index 3cced7ab5..7873404ce 100644 --- a/c/logging.c +++ b/c/logging.c @@ -693,6 +693,7 @@ void _zowelog(LoggingContext *context, uint64 compID, char* path, int line, int info->path = path; info->compID = compID; destination->handler(context,component,info,formatString,argPointer); + free(info); } else { destination->handler(context,component,destination->data,formatString,argPointer); } From c5f456386a4c34438532f46fd97d4fb1ea9484c7 Mon Sep 17 00:00:00 2001 From: sakeerthy Date: Tue, 15 Sep 2020 13:36:48 -0400 Subject: [PATCH 3/6] zowelog2 added cleanup needed Signed-off-by: sakeerthy --- c/logging.c | 84 ++++++++++++++++++++++++++++++++++++++++++++--------- h/logging.h | 23 +++++++++++++-- 2 files changed, 91 insertions(+), 16 deletions(-) diff --git a/c/logging.c b/c/logging.c index 7873404ce..98c0a6681 100644 --- a/c/logging.c +++ b/c/logging.c @@ -439,6 +439,7 @@ LoggingDestination *logConfigureDestination(LoggingContext *context, destination->handler = handler; destination->dumper = standardDumperFunction; destination->state = LOG_DESTINATION_STATE_INIT; + destination->handler2 = NULL; return destination; } @@ -455,6 +456,25 @@ LoggingDestination *logConfigureDestination2(LoggingContext *context, return destination; } +LoggingDestination *logConfigureDestination3(LoggingContext *context, + unsigned int id, + char *name, + void *data, + LogHandler handler, + DataDumper dumper, + LogHandler2 handler2){ + if (context == NULL) { + context = getLoggingContext(); + } + + LoggingDestination *destination = logConfigureDestination(context, id, name, data, handler); + if (destination != NULL) { + // destination->dumper = dumper; + destination->handler2 = handler2; + } + return destination; +} + void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){ #ifdef METTLE printf("broken printf in logging.c\n"); @@ -647,7 +667,52 @@ int logGetLevel(LoggingContext *context, uint64 compID){ return component ? component->currentDetailLevel : ZOWE_LOG_NA; } -void _zowelog(LoggingContext *context, uint64 compID, char* path, int line, int level, char *formatString, ...){ +void zowelog(LoggingContext *context, uint64 compID, int level, char *formatString, ...){ + if (logShouldTrace(context, compID, level) == FALSE) { + return; + } + if (context == NULL) { + context = getLoggingContext(); + } + + int maxDetailLevel = 0; + LoggingComponent *component = getComponent(context, compID, &maxDetailLevel); + if (component == NULL) { + return; + } + + if (maxDetailLevel >= level){ + va_list argPointer; + LoggingDestination *destination = &getDestinationTable(context, compID)[component->destination]; +// printf("log.2 comp.dest=%d\n",component->destination);fflush(stdout); + + if (component->destination >= MAX_LOGGING_DESTINATIONS){ + char message[128]; + sprintf(message,"Destination %d is out of range (log)\n",component->destination); + lastResortLog(message); + return; + } else if (component->destination == 0 && destination->state != LOG_DESTINATION_STATE_UNINITIALIZED){ + /* silently do nothing, /dev/null is always destination 0 and always does nothing */ + printf("dev/null case\n"); + return; + } + + // printf("log.3\n");fflush(stdout); + if (destination->state == LOG_DESTINATION_STATE_UNINITIALIZED){ + char message[128]; + sprintf(message,"Destination %d is not initialized for logging\n",component->destination); + lastResortLog(message); + return; + } + /* here, pass to a var-args handler */ + va_start(argPointer, formatString); + destination->handler(context,component,destination->data,formatString,argPointer); + + va_end(argPointer); + } +} + +void zowelog2(LoggingContext *context, uint64 compID, int level, void *userData, char *formatString, ...){ if (logShouldTrace(context, compID, level) == FALSE) { return; } @@ -686,21 +751,14 @@ void _zowelog(LoggingContext *context, uint64 compID, char* path, int line, int } /* here, pass to a var-args handler */ va_start(argPointer, formatString); - if (strncmp(context->eyecatcher, "ZOWECNTX", 7) == 0) { - LoggingInfo *info = (LoggingInfo *)safeMalloc(sizeof(LoggingInfo), "LoggingInfo"); - info->level = level; - info->line = line; - info->path = path; - info->compID = compID; - destination->handler(context,component,info,formatString,argPointer); - free(info); - } else { - destination->handler(context,component,destination->data,formatString,argPointer); - } +if (destination->handler2 != NULL) { + destination->handler2(context, component, destination->data, level, compID, userData, formatString, argPointer); +} else { + destination->handler(context, component, destination->data, formatString, argPointer); +} va_end(argPointer); } - } static void printToDestination(LoggingDestination *destination, diff --git a/h/logging.h b/h/logging.h index d27cbafe5..9512e1abf 100644 --- a/h/logging.h +++ b/h/logging.h @@ -108,6 +108,15 @@ typedef void (*LogHandler)(struct LoggingContext_tag *context, va_list argList); typedef char *(*DataDumper)(char *workBuffer, int workBufferSize, void *data, int dataSize, int lineNumber); +typedef void (*LogHandler2)(struct LoggingContext_tag *context, + LoggingComponent *component, + void *componentData, // IF: set in existing logConfigureDestination or logConfigureDestination2 + int level, + uint64 compID, + void *userData, // IF: set in the new function logConfigureDestination3 char *formatString, + char *formatString, + va_list argList); + ZOWE_PRAGMA_PACK typedef struct LoggingDestination_tag{ @@ -118,6 +127,7 @@ typedef struct LoggingDestination_tag{ void *data; /* used by destination to hold internal state */ LogHandler handler; DataDumper dumper; + LogHandler2 handler2; } LoggingDestination; #define MAX_LOGGING_COMPONENTS 256 @@ -307,7 +317,8 @@ bool logShouldTraceInternal(LoggingContext *context, uint64 componentID, int lev /* this log message will be sent to the destination associated to the component */ -void _zowelog(LoggingContext *context, uint64 compID, char* path, int line, int level, char *formatString, ...); +void zowelog(LoggingContext *context, uint64 compID, int level, char *formatString, ...); +void zowelog2(LoggingContext *context, uint64 compID, int level, void *userData, char *formatString, ...); void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int dataSize); #define LOGCHECK(context,component,level) \ @@ -315,9 +326,15 @@ void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int (context->applicationComponents[component].level >= level) : \ (context->coreComponents[component].level >= level) ) -#define zowelog(context, compID, level, formatString, ...) \ - _zowelog(context, compID, __FILE__, __LINE__, level, formatString, ##__VA_ARGS__); +#define zowelogx(context, compID, level, formatString, ...) \ + do { \ + struct { \ + char *fileName; \ + int lineNnumber; \ + } fileAndLine = {__FILE__, __LINE__}; \ + zowelog2(context, compID, level, &fileAndLine, formatString, ##__VA_ARGS__); \ + } while (0) LoggingDestination *logConfigureDestination(LoggingContext *context, unsigned int id, char *name, From 6c6760e336d6c3f060114ef2546d26eea7490e14 Mon Sep 17 00:00:00 2001 From: sakeerthy Date: Tue, 15 Sep 2020 15:59:37 -0400 Subject: [PATCH 4/6] Some clean up Signed-off-by: sakeerthy --- c/crossmemory.c | 9 ++++----- c/logging.c | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/c/crossmemory.c b/c/crossmemory.c index 0ee9965bc..765a5137b 100644 --- a/c/crossmemory.c +++ b/c/crossmemory.c @@ -140,7 +140,7 @@ typedef struct MultilineWTOFirstLine_tag { void * __ptr32 cart; void * __ptr32 wsparm; unsigned short type; -#define MULTILINE_WTO_LINE_TYPE_E 0x1000 +#define MULTILINE_WTO_LINE_TYPE_E 0x1000 #define MULTILINE_WTO_LINE_TYPE_D 0x2000 #define MULTILINE_WTO_LINE_TYPE_DE 0x3000 unsigned char areaID; @@ -2986,13 +2986,12 @@ static void printDisplayConfigCommandResponse(CrossMemoryServer *server, CMSWTOR CART cart = routeInfo->cart; int consoleID = routeInfo->consoleID; CrossMemoryServerGlobalArea *globalArea = server->globalArea; + zowelog(NULL, LOG_COMP_ID_CMS, ZOWE_LOG_INFO, #ifdef CROSS_MEMORY_SERVER_DEBUG -#define SERVER_INFO_PREFIX CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\' (debug mode)\n" + CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\' (debug mode)\n" #else -#define SERVER_INFO_PREFIX CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\'\n" + CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\'\n" #endif - zowelog(NULL, LOG_COMP_ID_CMS, ZOWE_LOG_INFO, - SERVER_INFO_PREFIX " Global area address = 0x%p\n" " Version = %d\n" " Key = %d\n" diff --git a/c/logging.c b/c/logging.c index 98c0a6681..d9cec2485 100644 --- a/c/logging.c +++ b/c/logging.c @@ -463,14 +463,14 @@ LoggingDestination *logConfigureDestination3(LoggingContext *context, LogHandler handler, DataDumper dumper, LogHandler2 handler2){ - if (context == NULL) { - context = getLoggingContext(); - } - LoggingDestination *destination = logConfigureDestination(context, id, name, data, handler); if (destination != NULL) { - // destination->dumper = dumper; - destination->handler2 = handler2; + if (destination->handler2 != NULL) { + destination->handler2 = handler2; + } + if (destination->dumper != NULL) { + destination->dumper = dumper; + } } return destination; } From 2ba9c56656961ac5ef5cbf4bc26993fc835c8743 Mon Sep 17 00:00:00 2001 From: sakeerthy Date: Tue, 15 Sep 2020 16:01:13 -0400 Subject: [PATCH 5/6] clean up Signed-off-by: sakeerthy --- c/crossmemory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/c/crossmemory.c b/c/crossmemory.c index 765a5137b..e6e419e1b 100644 --- a/c/crossmemory.c +++ b/c/crossmemory.c @@ -140,7 +140,7 @@ typedef struct MultilineWTOFirstLine_tag { void * __ptr32 cart; void * __ptr32 wsparm; unsigned short type; -#define MULTILINE_WTO_LINE_TYPE_E 0x1000 +#define MULTILINE_WTO_LINE_TYPE_E 0x1000 #define MULTILINE_WTO_LINE_TYPE_D 0x2000 #define MULTILINE_WTO_LINE_TYPE_DE 0x3000 unsigned char areaID; @@ -2986,6 +2986,7 @@ static void printDisplayConfigCommandResponse(CrossMemoryServer *server, CMSWTOR CART cart = routeInfo->cart; int consoleID = routeInfo->consoleID; CrossMemoryServerGlobalArea *globalArea = server->globalArea; + zowelog(NULL, LOG_COMP_ID_CMS, ZOWE_LOG_INFO, #ifdef CROSS_MEMORY_SERVER_DEBUG CMS_LOG_DISP_CMD_RESULT_MSG"Server name - \'%16.16s\' (debug mode)\n" From 8df41b047e8d78a2f06179722639f04440cbe544 Mon Sep 17 00:00:00 2001 From: sakeerthy Date: Tue, 15 Sep 2020 16:07:35 -0400 Subject: [PATCH 6/6] clean up Signed-off-by: sakeerthy --- c/logging.c | 12 +++++------- h/logging.h | 10 ---------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/c/logging.c b/c/logging.c index d9cec2485..9ce246d74 100644 --- a/c/logging.c +++ b/c/logging.c @@ -439,7 +439,6 @@ LoggingDestination *logConfigureDestination(LoggingContext *context, destination->handler = handler; destination->dumper = standardDumperFunction; destination->state = LOG_DESTINATION_STATE_INIT; - destination->handler2 = NULL; return destination; } @@ -751,12 +750,11 @@ void zowelog2(LoggingContext *context, uint64 compID, int level, void *userData, } /* here, pass to a var-args handler */ va_start(argPointer, formatString); -if (destination->handler2 != NULL) { - destination->handler2(context, component, destination->data, level, compID, userData, formatString, argPointer); -} else { - destination->handler(context, component, destination->data, formatString, argPointer); -} - + if (destination->handler2 != NULL) { + destination->handler2(context, component, destination->data, level, compID, userData, formatString, argPointer); + } else { + destination->handler(context, component, destination->data, formatString, argPointer); + } va_end(argPointer); } } diff --git a/h/logging.h b/h/logging.h index 9512e1abf..3584a77b8 100644 --- a/h/logging.h +++ b/h/logging.h @@ -76,8 +76,6 @@ ZOWE_PRAGMA_PACK_RESET #define LOG_PROD_ZIS 0x008F000200000000LLU #define LOG_PROD_ZSS 0x008F000300000000LLU #define LOG_PROD_PLUGINS 0x008F000400000000LLU -#define LOG_PROD_TEST 0x008F000500000000LLU - #define LOG_COMP_ALLOC 0x008F000100010000LLU #define LOG_COMP_UTILS 0x008F000100020000LLU @@ -133,13 +131,6 @@ typedef struct LoggingDestination_tag{ #define MAX_LOGGING_COMPONENTS 256 #define MAX_LOGGING_DESTINATIONS 32 -typedef struct LoggingInfo_tag { - int level; - int line; - char* path; - uint64 compID; -} LoggingInfo; - typedef struct LoggingVendor_tag { char eyecatcher[8]; /* RSLOGVNR */ unsigned short vendorID; @@ -326,7 +317,6 @@ void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int (context->applicationComponents[component].level >= level) : \ (context->coreComponents[component].level >= level) ) - #define zowelogx(context, compID, level, formatString, ...) \ do { \ struct { \