From da3da934b32d766c047e42fe0e47dc762def2da8 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Sat, 27 Apr 2024 11:13:19 -0500 Subject: [PATCH 01/13] first iteration at logging improvements for zss data services due to customer complaints. Signed-off-by: Jordan Filteau --- c/logging.c | 67 +++++++++++++++++++++++++++++++++++++++++------------ h/logging.h | 5 +++- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/c/logging.c b/c/logging.c index b43f50367..9ad2a6019 100644 --- a/c/logging.c +++ b/c/logging.c @@ -26,7 +26,7 @@ #include #include #include - +#include #endif #include "zowetypes.h" @@ -457,20 +457,57 @@ LoggingDestination *logConfigureDestination2(LoggingContext *context, return destination; } -void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){ +static char *logLevelToString(int level) { + switch (level) { + case ZOWE_LOG_SEVERE: return "severe"; + case ZOWE_LOG_WARNING: return "warning"; + case ZOWE_LOG_INFO: return "info"; + case ZOWE_LOG_DEBUG: return "debug"; + case ZOWE_LOG_DEBUG2: return "debug"; + case ZOWE_LOG_DEBUG3: return "debug"; + default: return ""; + } +} + +static void getCurrentTime(char *timeStamp, unsigned int timeStampSize) { + ISOTime isoTime = {0}; + time_t unixTime = time(NULL); + convertUnixToISO((int) unixTime, &isoTime); + strncpy(timeStamp, isoTime.data, timeStampSize); +} + +static void prependMetadata(int logLevel, char *fullMessage, unsigned int fullMessageSize, char *formatString, va_list argList) { + char time[64] = {0}; + getCurrentTime((char *) &time, sizeof(time)); + char message[256] = {0}; + vsnprintf(message, sizeof(message), formatString, argList); + snprintf(fullMessage, fullMessageSize, "[%s:%p:%s:%s:%d:%s]: %s", time, getTCB(), __FILE__, __FUNCTION__, __LINE__, logLevelToString(logLevel), message); +} + +void printToLog(FILE *destination, char *formatString, va_list argList, int logLevel) { #ifdef METTLE printf("broken printf in logging.c\n"); -#else - vfprintf(stdout,formatString,argList); +#else + char fullMessage[1024] = {0}; + prependMetadata(logLevel, (char *) &fullMessage, sizeof(fullMessage), formatString, argList); + fprintf(destination, "%s\n", fullMessage); #endif } +void printStdout2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel) { + printToLog(stdout, formatString, argList, logLevel); +} + +void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){ + printStdout2(context, component, data, formatString, argList, ZOWE_LOG_NA); +} + +void printStderr2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel) { + printToLog(stderr, formatString, argList, logLevel); +} + void printStderr(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){ -#ifdef METTLE - printf("broken printf in logging.c\n"); -#else - vfprintf(stderr,formatString,argList); -#endif + printStderr2(context, component, data, formatString, argList, ZOWE_LOG_NA); } void logConfigureStandardDestinations(LoggingContext *context){ @@ -478,8 +515,8 @@ void logConfigureStandardDestinations(LoggingContext *context){ context = getLoggingContext(); } logConfigureDestination(context,LOG_DEST_DEV_NULL,"/dev/null",NULL,NULL); - logConfigureDestination(context,LOG_DEST_PRINTF_STDOUT,"printf(stdout)",NULL,printStdout); - logConfigureDestination(context,LOG_DEST_PRINTF_STDERR,"printf(stderr)",NULL,printStderr); + logConfigureDestination(context,LOG_DEST_PRINTF_STDOUT,"printf(stdout)",NULL,printStdout2); + logConfigureDestination(context,LOG_DEST_PRINTF_STDERR,"printf(stderr)",NULL,printStderr2); } void logConfigureComponent(LoggingContext *context, uint64 compID, char *compName, int destination, int level){ @@ -690,7 +727,7 @@ 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); + destination->handler(context,component,destination->data,formatString,argPointer,level); va_end(argPointer); } @@ -700,10 +737,10 @@ void zowelog(LoggingContext *context, uint64 compID, int level, char *formatStri static void printToDestination(LoggingDestination *destination, struct LoggingContext_tag *context, LoggingComponent *component, - void *data, char *formatString, ...){ + int level, void *data, char *formatString, ...){ va_list argPointer; va_start(argPointer, formatString); - destination->handler(context,component,destination->data,formatString,argPointer); + destination->handler(context,component,destination->data,formatString,argPointer,level); va_end(argPointer); } @@ -748,7 +785,7 @@ void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int for (int i = 0; ; i++){ char *result = destination->dumper(workBuffer, sizeof(workBuffer), data, dataSize, i); if (result != NULL){ - printToDestination(destination, context, component, destination->data, "%s\n", result); + printToDestination(destination, context, component, level, destination->data, "%s\n", result); } else { break; diff --git a/h/logging.h b/h/logging.h index 1d7654f71..f9f5ea685 100644 --- a/h/logging.h +++ b/h/logging.h @@ -135,7 +135,8 @@ typedef void (*LogHandler)(struct LoggingContext_tag *context, LoggingComponent *component, void *data, char *formatString, - va_list argList); + va_list argList, + int logLevel); typedef char *(*DataDumper)(char *workBuffer, int workBufferSize, void *data, int dataSize, int lineNumber); ZOWE_PRAGMA_PACK @@ -369,7 +370,9 @@ extern int logSetExternalContext(LoggingContext *context); extern LoggingContext *logGetExternalContext(); void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList); +void printStdout2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel); void printStderr(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList); +void printStderr2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel); #endif From 8c6b3916e5a48acfb66c8330ff5960dcd5bc5215 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Sat, 27 Apr 2024 20:27:31 -0500 Subject: [PATCH 02/13] more metadata added; changed format. Signed-off-by: Jordan Filteau --- c/logging.c | 132 ++++++++++++++++++++++++++++++++++++++++++---------- h/logging.h | 33 +++++++++++-- 2 files changed, 137 insertions(+), 28 deletions(-) diff --git a/c/logging.c b/c/logging.c index 9ad2a6019..d5ffebdd1 100644 --- a/c/logging.c +++ b/c/logging.c @@ -476,38 +476,91 @@ static void getCurrentTime(char *timeStamp, unsigned int timeStampSize) { strncpy(timeStamp, isoTime.data, timeStampSize); } -static void prependMetadata(int logLevel, char *fullMessage, unsigned int fullMessageSize, char *formatString, va_list argList) { +static void prependMetadata(int logLevel, + char *fullMessage, + unsigned int fullMessageSize, + char *formatString, + va_list argList, + char *fileName, + char *functionName, + unsigned int lineNumber) { char time[64] = {0}; getCurrentTime((char *) &time, sizeof(time)); char message[256] = {0}; vsnprintf(message, sizeof(message), formatString, argList); - snprintf(fullMessage, fullMessageSize, "[%s:%p:%s:%s:%d:%s]: %s", time, getTCB(), __FILE__, __FUNCTION__, __LINE__, logLevelToString(logLevel), message); -} - -void printToLog(FILE *destination, char *formatString, va_list argList, int logLevel) { + pthread_t pThread = pthread_self(); + if (!fileName || !functionName || lineNumber == 0) { + snprintf(fullMessage, + fullMessageSize, + "<%s|tcb=%p|thread=%d|pid=%d|%s>: %s", + time, + getTCB(), + &pThread, + getpid(), + logLevelToString(logLevel), + message); + } else { + snprintf(fullMessage, + fullMessageSize, + "<%s|tcb=%p|thread=%d|pid=%d|%s:%s():%d|%s>: %s", + time, + getTCB(), + &pThread, + getpid(), + basename(fileName), + functionName, + lineNumber, + logLevelToString(logLevel), + message); + } +} + +void printToLog(FILE *destination, + char *formatString, + va_list argList, + int logLevel, + char *fileName, + char *functionName, + unsigned int lineNumber) { #ifdef METTLE printf("broken printf in logging.c\n"); #else char fullMessage[1024] = {0}; - prependMetadata(logLevel, (char *) &fullMessage, sizeof(fullMessage), formatString, argList); + prependMetadata(logLevel, (char *) &fullMessage, sizeof(fullMessage), formatString, argList, fileName, functionName, lineNumber); fprintf(destination, "%s\n", fullMessage); #endif } -void printStdout2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel) { - printToLog(stdout, formatString, argList, logLevel); +void printStdout2(LoggingContext *context, + LoggingComponent *component, + void *data, + char *formatString, + va_list argList, + int logLevel, + char *fileName, + char *functionName, + unsigned int lineNumber) { + printToLog(stdout, formatString, argList, logLevel, fileName, functionName, lineNumber); } void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){ - printStdout2(context, component, data, formatString, argList, ZOWE_LOG_NA); + printStdout2(context, component, data, formatString, argList, ZOWE_LOG_NA, "", "", 0); } -void printStderr2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel) { - printToLog(stderr, formatString, argList, logLevel); +void printStderr2(LoggingContext *context, + LoggingComponent *component, + void *data, + char *formatString, + va_list argList, + int logLevel, + char *fileName, + char *functionName, + unsigned int lineNumber) { + printToLog(stderr, formatString, argList, logLevel, fileName, functionName, lineNumber); } void printStderr(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){ - printStderr2(context, component, data, formatString, argList, ZOWE_LOG_NA); + printStderr2(context, component, data, formatString, argList, ZOWE_LOG_NA, "", "", 0); } void logConfigureStandardDestinations(LoggingContext *context){ @@ -686,7 +739,14 @@ int logGetLevel(LoggingContext *context, uint64 compID){ return component ? component->currentDetailLevel : ZOWE_LOG_NA; } -void zowelog(LoggingContext *context, uint64 compID, int level, char *formatString, ...){ +void zowelogInner(LoggingContext *context, + uint64 compID, + int level, + char *fileName, + char *functionName, + unsigned int lineNumber, + char *formatString, + va_list argPointer) { if (logShouldTrace(context, compID, level) == FALSE) { return; @@ -703,8 +763,6 @@ void zowelog(LoggingContext *context, uint64 compID, int level, char *formatStri } 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){ @@ -724,27 +782,44 @@ void zowelog(LoggingContext *context, uint64 compID, int level, char *formatStri lastResortLog(message); return; } - /* here, pass to a var-args handler */ - va_start(argPointer, formatString); - - destination->handler(context,component,destination->data,formatString,argPointer,level); - - va_end(argPointer); + destination->handler(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber); } +} +void zowelog2(LoggingContext *context, uint64 compID, int level, char *fileName, char *functionName, unsigned int lineNumber, char *formatString, ...) { + va_list argPointer; + va_start(argPointer, formatString); + zowelogInner(context, compID, level, fileName, functionName, lineNumber, formatString, argPointer); + va_end(argPointer); +} + +void zowelog(LoggingContext *context, uint64 compID, int level, char *formatString, ...){ + va_list argPointer; + va_start(argPointer, formatString); + zowelogInner(context, compID, level, "", "", 0, formatString, argPointer); + va_end(argPointer); } static void printToDestination(LoggingDestination *destination, struct LoggingContext_tag *context, LoggingComponent *component, - int level, void *data, char *formatString, ...){ + int level, char *fileName, + char *functionName, unsigned int lineNumber, + void *data, char *formatString, ...){ va_list argPointer; va_start(argPointer, formatString); - destination->handler(context,component,destination->data,formatString,argPointer,level); + destination->handler(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber); va_end(argPointer); } -void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int dataSize){ +void zowedumpInner(LoggingContext *context, + uint64 compID, + int level, + void *data, + int dataSize, + char *fileName, + char *functionName, + unsigned int lineNumber) { if (logShouldTrace(context, compID, level) == FALSE) { return; @@ -785,7 +860,7 @@ void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int for (int i = 0; ; i++){ char *result = destination->dumper(workBuffer, sizeof(workBuffer), data, dataSize, i); if (result != NULL){ - printToDestination(destination, context, component, level, destination->data, "%s\n", result); + printToDestination(destination, context, component, level, fileName, functionName, lineNumber, destination->data, "%s\n", result); } else { break; @@ -793,7 +868,14 @@ void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int } } +} +void zowedump2(LoggingContext *context, uint64 compID, int level, void *data, int dataSize, char *fileName, char *functionName, unsigned int lineNumber) { + zowedumpInner(context, compID, level, data, dataSize, fileName, functionName, lineNumber); +} + +void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int dataSize){ + zowedumpInner(context, compID, level, data, dataSize, "", "", 0); } bool logShouldTraceInternal(LoggingContext *context, uint64 componentID, int level) { diff --git a/h/logging.h b/h/logging.h index f9f5ea685..ec03184a6 100644 --- a/h/logging.h +++ b/h/logging.h @@ -22,6 +22,30 @@ #include "collections.h" #include "le.h" +#define ZOWELOG_SEVERE($id, $fmt, ...) \ + zowelog2(NULL, $id, ZOWE_LOG_SEVERE, \ + ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + +#define ZOWELOG_WARNING($id, $fmt, ...) \ + zowelog2(NULL, $id, ZOWE_LOG_WARNING, \ + ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + +#define ZOWELOG_INFO($id, $fmt, ...) \ + zowelog2(NULL, $id, ZOWE_LOG_INFO, \ + ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + +#define ZOWELOG_DEBUG($id, $fmt, ...) \ + zowelog2(NULL, $id, ZOWE_LOG_DEBUG, \ + ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + +#define ZOWELOG_DEBUG2($id, $fmt, ...) \ + zowelog2(NULL, $id, ZOWE_LOG_DEBUG2, \ + ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + +#define ZOWELOG_DEBUG3($id, $fmt, ...) \ + zowelog2(NULL, $id, ZOWE_LOG_DEBUG3, \ + ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + /** \file * \brief logging.h defines a platform-independent logging facility that echoes some of Java logging. * @@ -136,7 +160,10 @@ typedef void (*LogHandler)(struct LoggingContext_tag *context, void *data, char *formatString, va_list argList, - int logLevel); + int logLevel, + char *fileName, + char *functionName, + unsigned int lineNumber); typedef char *(*DataDumper)(char *workBuffer, int workBufferSize, void *data, int dataSize, int lineNumber); ZOWE_PRAGMA_PACK @@ -370,9 +397,9 @@ extern int logSetExternalContext(LoggingContext *context); extern LoggingContext *logGetExternalContext(); void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList); -void printStdout2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel); +void printStdout2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel, char *fileName, char *functionName, unsigned int lineNumber); void printStderr(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList); -void printStderr2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel); +void printStderr2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel, char *fileName, char *functionName, unsigned int lineNumber); #endif From ea41ceeea8c24de0c7a156bd90d54249c17f0983 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Mon, 29 Apr 2024 10:25:36 -0500 Subject: [PATCH 03/13] making changes requested by Sean to conform to Zowe common logging format. Signed-off-by: Jordan Filteau --- c/logging.c | 102 +++++++++++++++++++++++++++++++++++++++------------- h/logging.h | 1 + 2 files changed, 78 insertions(+), 25 deletions(-) diff --git a/c/logging.c b/c/logging.c index d5ffebdd1..72a356050 100644 --- a/c/logging.c +++ b/c/logging.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #endif #include "zowetypes.h" @@ -36,6 +38,7 @@ #include "utils.h" #include "logging.h" #include "printables_for_dump.h" +#include "zos.h" #ifdef __ZOWE_OS_ZOS #include "le.h" @@ -459,21 +462,65 @@ LoggingDestination *logConfigureDestination2(LoggingContext *context, static char *logLevelToString(int level) { switch (level) { - case ZOWE_LOG_SEVERE: return "severe"; - case ZOWE_LOG_WARNING: return "warning"; - case ZOWE_LOG_INFO: return "info"; - case ZOWE_LOG_DEBUG: return "debug"; - case ZOWE_LOG_DEBUG2: return "debug"; - case ZOWE_LOG_DEBUG3: return "debug"; + case ZOWE_LOG_SEVERE: return "CRITICAL"; + case ZOWE_LOG_WARNING: return "WARN"; + case ZOWE_LOG_INFO: return "INFO"; + case ZOWE_LOG_DEBUG: return "DEBUG"; + case ZOWE_LOG_DEBUG2: return "FINER"; + case ZOWE_LOG_DEBUG3: return "TRACE"; default: return ""; } } -static void getCurrentTime(char *timeStamp, unsigned int timeStampSize) { - ISOTime isoTime = {0}; - time_t unixTime = time(NULL); - convertUnixToISO((int) unixTime, &isoTime); - strncpy(timeStamp, isoTime.data, timeStampSize); +typedef struct zl_time_t { + char value[32]; +} zl_time_t; + +static zl_time_t gettime(void) { + + time_t t = time(NULL); + const char *format = "%Y-%m-%d %H:%M:%S"; + + struct tm lt; + zl_time_t result; + + gmtime_r(&t, <); + + strftime(result.value, sizeof(result.value), format, <); + + struct timeval now; + gettimeofday(&now, NULL); + int milli = now.tv_usec / 1000; + snprintf(result.value+strlen(result.value), 5, ".%03d", milli); + + return result; +} + +static char *getServiceName() { + return "ZWESZ1"; +} + +static void getTaskInformation(char *taskInformation, unsigned int taskInformationSize) { + pthread_t pThread = pthread_self(); + snprintf(taskInformation, taskInformationSize, "tcb=0x%p,threadid=0x%p,pid=0x%p", getTCB(), &pThread, getpid()); +} + +static void getMessage(char *message, unsigned int messageSize, const char *formatString, va_list argList) { + vsnprintf(message, messageSize, formatString, argList); +} + +/* + * 1. Try to get the name from the TCB. + * 2. Try to get the name from the login data base. + */ +static void getUserID(char *user, unsigned int userSize) { + TCB *tcb = getTCB(); + ACEE *acee = (ACEE *) tcb->tcbsenv; + if (acee) { + snprintf(user, userSize, "%.*s", acee->aceeuser[0], acee->aceeuser[1]); + } else { + getlogin_r(user, userSize); + } } static void prependMetadata(int logLevel, @@ -484,33 +531,38 @@ static void prependMetadata(int logLevel, char *fileName, char *functionName, unsigned int lineNumber) { - char time[64] = {0}; - getCurrentTime((char *) &time, sizeof(time)); + char user[8+1] = {0}; + getUserID((char *) &user, sizeof(user) - 1); + //char time[64] = {0}; + zl_time_t time = {0}; + time = gettime(); + //getCurrentTime((char *) &time, sizeof(time)); char message[256] = {0}; - vsnprintf(message, sizeof(message), formatString, argList); - pthread_t pThread = pthread_self(); + getMessage((char *) &message, sizeof(message), formatString, argList); + char taskInformation[128] = {0}; + getTaskInformation((char *) &taskInformation, sizeof(taskInformation)); if (!fileName || !functionName || lineNumber == 0) { snprintf(fullMessage, fullMessageSize, - "<%s|tcb=%p|thread=%d|pid=%d|%s>: %s", + "%s <%s:%s> %s %s %s", time, - getTCB(), - &pThread, - getpid(), + getServiceName(), + taskInformation, + user, logLevelToString(logLevel), message); } else { snprintf(fullMessage, fullMessageSize, - "<%s|tcb=%p|thread=%d|pid=%d|%s:%s():%d|%s>: %s", - time, - getTCB(), - &pThread, - getpid(), + "%s <%s:%s> %s %s (%s:%s:%d) %s", + time.value, + getServiceName(), + taskInformation, + user, + logLevelToString(logLevel), basename(fileName), functionName, lineNumber, - logLevelToString(logLevel), message); } } diff --git a/h/logging.h b/h/logging.h index ec03184a6..acc6c0bf2 100644 --- a/h/logging.h +++ b/h/logging.h @@ -70,6 +70,7 @@ ZOWE_PRAGMA_PACK_RESET #define RC_LOG_ERROR 8 #define ZOWE_LOG_NA -1 + #define ZOWE_LOG_SEVERE 0 #define ZOWE_LOG_ALWAYS 0 #define ZOWE_LOG_WARNING 1 From 7702b00437b6603295afffadbe4ef459e23f1e4f Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Mon, 29 Apr 2024 14:34:53 -0500 Subject: [PATCH 04/13] adding a second loghandler; more backwards compatibility. Signed-off-by: Jordan Filteau --- c/logging.c | 55 +++++++++++++++++++++++++++++++++-------------------- h/logging.h | 10 +++++++++- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/c/logging.c b/c/logging.c index 72a356050..c1b4d69a9 100644 --- a/c/logging.c +++ b/c/logging.c @@ -405,11 +405,13 @@ int setLoggingContext(LoggingContext *context) { #endif /* not LOGGING_CUSTOM_CONTEXT_GETTER */ } -LoggingDestination *logConfigureDestination(LoggingContext *context, - unsigned int id, - char *name, - void *data, - LogHandler handler){ +LoggingDestination *logConfigureDestination3(LoggingContext *context, + unsigned int id, + char *name, + void *data, + LogHandler handler, + DataDumper dumper, + LogHandler2 handler2) { if (context == NULL) { context = getLoggingContext(); @@ -442,22 +444,29 @@ LoggingDestination *logConfigureDestination(LoggingContext *context, destination->name = name; destination->data = data; destination->handler = handler; - destination->dumper = standardDumperFunction; + destination->handler2 = handler2; + destination->dumper = dumper != NULL ? dumper : standardDumperFunction; destination->state = LOG_DESTINATION_STATE_INIT; return destination; } +LoggingDestination *logConfigureDestination(LoggingContext *context, + unsigned int id, + char *name, + void *data, + LogHandler handler){ + + return logConfigureDestination3(context, id, name, data, handler, NULL, NULL); +} + LoggingDestination *logConfigureDestination2(LoggingContext *context, unsigned int id, char *name, void *data, LogHandler handler, DataDumper dumper){ - LoggingDestination *destination = logConfigureDestination(context, id, name, data, handler); - if (destination != NULL) { - destination->dumper = dumper; - } - return destination; + + return logConfigureDestination3(context, id, name, data, handler, dumper, NULL); } static char *logLevelToString(int level) { @@ -533,15 +542,13 @@ static void prependMetadata(int logLevel, unsigned int lineNumber) { char user[8+1] = {0}; getUserID((char *) &user, sizeof(user) - 1); - //char time[64] = {0}; zl_time_t time = {0}; time = gettime(); - //getCurrentTime((char *) &time, sizeof(time)); char message[256] = {0}; getMessage((char *) &message, sizeof(message), formatString, argList); char taskInformation[128] = {0}; getTaskInformation((char *) &taskInformation, sizeof(taskInformation)); - if (!fileName || !functionName || lineNumber == 0) { + if (!fileName || strlen(fileName) == 0 || !functionName || strlen(functionName) == 0 || lineNumber == 0) { snprintf(fullMessage, fullMessageSize, "%s <%s:%s> %s %s %s", @@ -619,9 +626,9 @@ void logConfigureStandardDestinations(LoggingContext *context){ if (context == NULL) { context = getLoggingContext(); } - logConfigureDestination(context,LOG_DEST_DEV_NULL,"/dev/null",NULL,NULL); - logConfigureDestination(context,LOG_DEST_PRINTF_STDOUT,"printf(stdout)",NULL,printStdout2); - logConfigureDestination(context,LOG_DEST_PRINTF_STDERR,"printf(stderr)",NULL,printStderr2); + logConfigureDestination3(context,LOG_DEST_DEV_NULL,"/dev/null",NULL,NULL,NULL,NULL); + logConfigureDestination3(context,LOG_DEST_PRINTF_STDOUT,"printf(stdout)",NULL,printStdout,NULL,printStdout2); + logConfigureDestination3(context,LOG_DEST_PRINTF_STDERR,"printf(stderr)",NULL,printStderr,NULL,printStderr2); } void logConfigureComponent(LoggingContext *context, uint64 compID, char *compName, int destination, int level){ @@ -816,7 +823,6 @@ void zowelogInner(LoggingContext *context, if (maxDetailLevel >= level){ 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); @@ -827,14 +833,17 @@ void zowelogInner(LoggingContext *context, 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; } - destination->handler(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber); + if (destination->handler2) { + destination->handler2(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber); + } else { + destination->handler(context,component,destination->data,formatString,argPointer); + } } } @@ -860,7 +869,11 @@ static void printToDestination(LoggingDestination *destination, void *data, char *formatString, ...){ va_list argPointer; va_start(argPointer, formatString); - destination->handler(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber); + if (destination->handler2) { + destination->handler2(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber); + } else { + destination->handler(context,component,destination->data,formatString,argPointer); + } va_end(argPointer); } diff --git a/h/logging.h b/h/logging.h index acc6c0bf2..4fec14777 100644 --- a/h/logging.h +++ b/h/logging.h @@ -156,7 +156,7 @@ typedef struct LogComponentsMap_tag { struct LoggingContext_tag; -typedef void (*LogHandler)(struct LoggingContext_tag *context, +typedef void (*LogHandler2)(struct LoggingContext_tag *context, LoggingComponent *component, void *data, char *formatString, @@ -165,6 +165,13 @@ typedef void (*LogHandler)(struct LoggingContext_tag *context, char *fileName, char *functionName, unsigned int lineNumber); + +typedef void (*LogHandler)(struct LoggingContext_tag *context, + LoggingComponent *component, + void *data, + char *formatString, + va_list argList); + typedef char *(*DataDumper)(char *workBuffer, int workBufferSize, void *data, int dataSize, int lineNumber); ZOWE_PRAGMA_PACK @@ -176,6 +183,7 @@ typedef struct LoggingDestination_tag{ char *name; void *data; /* used by destination to hold internal state */ LogHandler handler; + LogHandler2 handler2; DataDumper dumper; } LoggingDestination; From c0fbdb589b8673f606570ee78637e02358377b29 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Mon, 29 Apr 2024 15:14:44 -0500 Subject: [PATCH 05/13] removing magic numbers; adding comments. Signed-off-by: Jordan Filteau --- c/logging.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/c/logging.c b/c/logging.c index c1b4d69a9..d3b618605 100644 --- a/c/logging.c +++ b/c/logging.c @@ -532,6 +532,15 @@ static void getUserID(char *user, unsigned int userSize) { } } +/* + * These seem very generous. + * + * + */ +#define LOG_USER_ID_MAX_LENGTH 8 +#define LOG_MESSAGE_MAX_LENGTH 512 +#define LOG_TASK_INFO_MAX_LENGTH 128 + static void prependMetadata(int logLevel, char *fullMessage, unsigned int fullMessageSize, @@ -540,23 +549,40 @@ static void prependMetadata(int logLevel, char *fileName, char *functionName, unsigned int lineNumber) { - char user[8+1] = {0}; + char user[LOG_USER_ID_MAX_LENGTH + 1] = {0}; getUserID((char *) &user, sizeof(user) - 1); zl_time_t time = {0}; time = gettime(); - char message[256] = {0}; + char message[LOG_MESSAGE_MAX_LENGTH + 1] = {0}; getMessage((char *) &message, sizeof(message), formatString, argList); - char taskInformation[128] = {0}; + char taskInformation[LOG_TASK_INFO_MAX_LENGTH + 1] = {0}; getTaskInformation((char *) &taskInformation, sizeof(taskInformation)); - if (!fileName || strlen(fileName) == 0 || !functionName || strlen(functionName) == 0 || lineNumber == 0) { + char *logLevelAsString = logLevelToString(logLevel); + /* + * The following fields were added in the second iteration of LogHandler. + * + * 1. fileName + * 2. functionName + * 3. lineNumber + * 4. logLevel + * + * (1,2,3) were never asked for, but (4) wasn't propogated down to the LogHandler and was just used to determine + * if the message should be printed. (4) is now passed to here so that it can be used to construct the common + * logging format. + * + * If one of these (1,2,3,4) isn't present, then they all aren't based on this implementation; therefore, we'll just format with what's + * available to us without relying on new arguments. The previous LogHandler will return null or empty values for (1,2), a 0 for (3), and + * ZOWE_LOG_NA for (4), which when going thorugh logLevelToString() will be an empty value. + * + */ + if (!fileName || strlen(fileName) == 0 || !functionName || strlen(functionName) == 0 || lineNumber == 0 || strlen(logLevelAsString) == 0) { snprintf(fullMessage, fullMessageSize, - "%s <%s:%s> %s %s %s", + "%s <%s:%s> %s %s", time, getServiceName(), taskInformation, user, - logLevelToString(logLevel), message); } else { snprintf(fullMessage, @@ -584,7 +610,7 @@ void printToLog(FILE *destination, #ifdef METTLE printf("broken printf in logging.c\n"); #else - char fullMessage[1024] = {0}; + char fullMessage[LOG_USER_ID_MAX_LENGTH + LOG_MESSAGE_MAX_LENGTH + LOG_TASK_INFO_MAX_LENGTH + 1] = {0}; prependMetadata(logLevel, (char *) &fullMessage, sizeof(fullMessage), formatString, argList, fileName, functionName, lineNumber); fprintf(destination, "%s\n", fullMessage); #endif From 701ce005ec60ea250708f8f03877b47102a1849e Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Mon, 29 Apr 2024 15:16:57 -0500 Subject: [PATCH 06/13] simplify code Signed-off-by: Jordan Filteau --- c/logging.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/c/logging.c b/c/logging.c index d3b618605..b7e7b8a13 100644 --- a/c/logging.c +++ b/c/logging.c @@ -535,10 +535,9 @@ static void getUserID(char *user, unsigned int userSize) { /* * These seem very generous. * - * */ -#define LOG_USER_ID_MAX_LENGTH 8 -#define LOG_MESSAGE_MAX_LENGTH 512 +#define LOG_USER_ID_MAX_LENGTH 8 +#define LOG_MESSAGE_MAX_LENGTH 512 #define LOG_TASK_INFO_MAX_LENGTH 128 static void prependMetadata(int logLevel, @@ -592,7 +591,7 @@ static void prependMetadata(int logLevel, getServiceName(), taskInformation, user, - logLevelToString(logLevel), + logLevelAsString, basename(fileName), functionName, lineNumber, From 18f74b4a2ed6ff97cae3e87144d5ee303c80e5ca Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Tue, 30 Apr 2024 13:50:59 -0500 Subject: [PATCH 07/13] updating based on Sean feedback, adding small test case. Signed-off-by: Jordan Filteau --- c/logging.c | 15 +++++++++------ h/logging.h | 12 ++++++------ tests/loggingtest.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 tests/loggingtest.c diff --git a/c/logging.c b/c/logging.c index b7e7b8a13..4ea954dc2 100644 --- a/c/logging.c +++ b/c/logging.c @@ -477,7 +477,7 @@ static char *logLevelToString(int level) { case ZOWE_LOG_DEBUG: return "DEBUG"; case ZOWE_LOG_DEBUG2: return "FINER"; case ZOWE_LOG_DEBUG3: return "TRACE"; - default: return ""; + default: return "NA"; } } @@ -511,7 +511,7 @@ static char *getServiceName() { static void getTaskInformation(char *taskInformation, unsigned int taskInformationSize) { pthread_t pThread = pthread_self(); - snprintf(taskInformation, taskInformationSize, "tcb=0x%p,threadid=0x%p,pid=0x%p", getTCB(), &pThread, getpid()); + snprintf(taskInformation, taskInformationSize, "0x%p:0x%p:%d", getTCB(), &pThread, getpid()); } static void getMessage(char *message, unsigned int messageSize, const char *formatString, va_list argList) { @@ -571,17 +571,20 @@ static void prependMetadata(int logLevel, * * If one of these (1,2,3,4) isn't present, then they all aren't based on this implementation; therefore, we'll just format with what's * available to us without relying on new arguments. The previous LogHandler will return null or empty values for (1,2), a 0 for (3), and - * ZOWE_LOG_NA for (4), which when going thorugh logLevelToString() will be an empty value. + * ZOWE_LOG_NA for (4), which when going thorugh logLevelToString() will be NA. + * + * The existing logs in the server should contain the level, as long as logConfigureDestination3() is used. If not, it will have the placeholder. * */ - if (!fileName || strlen(fileName) == 0 || !functionName || strlen(functionName) == 0 || lineNumber == 0 || strlen(logLevelAsString) == 0) { + if (!fileName || strlen(fileName) == 0 || !functionName || strlen(functionName) == 0 || lineNumber == 0) { snprintf(fullMessage, fullMessageSize, - "%s <%s:%s> %s %s", - time, + "%s <%s:%s> %s %s %s", + time.value, getServiceName(), taskInformation, user, + logLevelAsString, message); } else { snprintf(fullMessage, diff --git a/h/logging.h b/h/logging.h index 4fec14777..6347ac00b 100644 --- a/h/logging.h +++ b/h/logging.h @@ -24,27 +24,27 @@ #define ZOWELOG_SEVERE($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_SEVERE, \ - ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) #define ZOWELOG_WARNING($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_WARNING, \ - ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) #define ZOWELOG_INFO($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_INFO, \ - ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) #define ZOWELOG_DEBUG($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_DEBUG, \ - ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) #define ZOWELOG_DEBUG2($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_DEBUG2, \ - ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) #define ZOWELOG_DEBUG3($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_DEBUG3, \ - ___FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) /** \file * \brief logging.h defines a platform-independent logging facility that echoes some of Java logging. diff --git a/tests/loggingtest.c b/tests/loggingtest.c new file mode 100644 index 000000000..c5405ab68 --- /dev/null +++ b/tests/loggingtest.c @@ -0,0 +1,29 @@ +#include "logging.h" + +#include +#include +#include +#include +#include +#include +#include + +/* + * Test that logging is functional with and without new helper macros. + */ +void main() { + LoggingContext *context = makeLoggingContext(); + logConfigureStandardDestinations(context); + logConfigureComponent(context, LOG_COMP_DATASERVICE, "DATASERVICE", LOG_DEST_PRINTF_STDOUT, ZOWE_LOG_INFO); + + ZOWELOG_SEVERE(LOG_COMP_DATASERVICE, "Hello from zowelog2(). This log should have every field."); + zowelog(context, LOG_COMP_DATASERVICE, ZOWE_LOG_INFO, "Hello from zowelog(). This log should lack fileLocation information."); + + LoggingContext *context2 = makeLoggingContext(); + /* Using outdated logConfigureDestination. */ + logConfigureDestination(context2, LOG_DEST_PRINTF_STDOUT,"printf(stdout)", NULL, printStdout); + logConfigureComponent(context2, LOG_COMP_DATASERVICE, "DATASERVICE", LOG_DEST_PRINTF_STDOUT, ZOWE_LOG_INFO); + zowelog(context2, LOG_COMP_DATASERVICE, ZOWE_LOG_INFO, "Hello from zowelog(). This log should lack level and fileLocation information."); +} + + From 8ccaac5e9a79f203d4783ee0767e94c4c8f700f8 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Tue, 30 Apr 2024 13:53:30 -0500 Subject: [PATCH 08/13] adding build script Signed-off-by: Jordan Filteau --- tests/loggingtest.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/loggingtest.c b/tests/loggingtest.c index c5405ab68..38e27ada3 100644 --- a/tests/loggingtest.c +++ b/tests/loggingtest.c @@ -9,7 +9,27 @@ #include /* - * Test that logging is functional with and without new helper macros. + BUILD + c89 -D_OPEN_THREADS -D_XOPEN_SOURCE=600 -DAPF_AUTHORIZED=0 -DNOIBMHTTP \ + "-Wa,goff" "-Wc,langlvl(EXTC99),float(HEX),agg,list(),so(),search(),\ + goff,xref,gonum,roconst,gonum,asm,asmlib('SYS1.MACLIB'),asmlib('CEE.SCEEMAC')" \ + -I ../h \ + -o loggingtest \ + ./loggingtest.c \ + ../c/utils.c \ + ../c/logging.c \ + ../c/alloc.c \ + ../c/collections.c \ + ../c/zos.c \ + ../c/timeutls.c \ + ../c/le.c \ + ../c/scheduling.c \ + ../c/recovery.c + + */ + +/* + * Test that logging is functional with and without new helper macros. Prove backwards compatibility. */ void main() { LoggingContext *context = makeLoggingContext(); From 8f926e34e091708370ee9aba0082ea01ce23d271 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Wed, 1 May 2024 12:27:08 -0500 Subject: [PATCH 09/13] moving new handler2 to end of LoggingDestination; using const char *; updating nolongname Signed-off-by: Jordan Filteau --- c/logging.c | 2 +- h/logging.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/c/logging.c b/c/logging.c index 4ea954dc2..f3d4aba37 100644 --- a/c/logging.c +++ b/c/logging.c @@ -505,7 +505,7 @@ static zl_time_t gettime(void) { return result; } -static char *getServiceName() { +static const char *getServiceName() { return "ZWESZ1"; } diff --git a/h/logging.h b/h/logging.h index 6347ac00b..4c38b4c59 100644 --- a/h/logging.h +++ b/h/logging.h @@ -183,8 +183,8 @@ typedef struct LoggingDestination_tag{ char *name; void *data; /* used by destination to hold internal state */ LogHandler handler; - LogHandler2 handler2; DataDumper dumper; + LogHandler2 handler2; } LoggingDestination; #define MAX_LOGGING_COMPONENTS 256 @@ -292,9 +292,11 @@ extern LoggingContext *theLoggingContext; #define getLoggingContext GTLOGCTX #define setLoggingContext STLOGCTX #define zowelog ZOWELOG +#define zowelog2 ZOWELOG2 #define zowedump ZOWEDUMP #define logConfigureDestination LGCFGDST #define logConfigureDestination2 LGCFGDS2 +#define logConfigureDestination3 LGCFGDS3 #define logConfigureStandardDestinations LGCFGSTD #define logConfigureComponent LGCFGCMP #define logSetLevel LGSETLVL @@ -304,6 +306,8 @@ extern LoggingContext *theLoggingContext; #define logSetExternalContext LGSLOGCX #define printStdout LGPRSOUT #define printStderr LGPRSERR +#define printStdout2 LGPROUT2 +#define printStderr2 LGPRERR2 #endif From 890be90e82e6c96247bd6f295a8e858ba33de5f6 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Tue, 28 May 2024 19:22:14 -0500 Subject: [PATCH 10/13] addressing some of Irek's comments. Signed-off-by: Jordan Filteau --- c/logging.c | 127 +++++++++++++++++++++++++++++----------------------- h/logging.h | 27 +++++++---- 2 files changed, 89 insertions(+), 65 deletions(-) diff --git a/c/logging.c b/c/logging.c index f3d4aba37..701214bbe 100644 --- a/c/logging.c +++ b/c/logging.c @@ -481,31 +481,34 @@ static char *logLevelToString(int level) { } } -typedef struct zl_time_t { +typedef struct ZLTime_t { char value[32]; -} zl_time_t; +} ZLTime; -static zl_time_t gettime(void) { +static int getTime(ZLTime *result) { time_t t = time(NULL); const char *format = "%Y-%m-%d %H:%M:%S"; struct tm lt; - zl_time_t result; - gmtime_r(&t, <); - strftime(result.value, sizeof(result.value), format, <); + if (strftime(result->value, sizeof(result->value), format, <) == 0) { + return 1; + } struct timeval now; - gettimeofday(&now, NULL); + if (gettimeofday(&now, NULL) != 0) { + return 1; + } + int milli = now.tv_usec / 1000; - snprintf(result.value+strlen(result.value), 5, ".%03d", milli); + snprintf(result->value+strlen(result->value), 5, ".%03d", milli); - return result; + return 0; } -static const char *getServiceName() { +static const char *getDefaultServiceName() { return "ZWESZ1"; } @@ -547,11 +550,14 @@ static void prependMetadata(int logLevel, va_list argList, char *fileName, char *functionName, - unsigned int lineNumber) { + unsigned int lineNumber, + const char *serviceName) { char user[LOG_USER_ID_MAX_LENGTH + 1] = {0}; getUserID((char *) &user, sizeof(user) - 1); - zl_time_t time = {0}; - time = gettime(); + ZLTime time = {0}; + if (getTime(&time) != 0) { + strcpy(time.value, "0000-00-00 00:00:00.000"); + } char message[LOG_MESSAGE_MAX_LENGTH + 1] = {0}; getMessage((char *) &message, sizeof(message), formatString, argList); char taskInformation[LOG_TASK_INFO_MAX_LENGTH + 1] = {0}; @@ -575,13 +581,16 @@ static void prependMetadata(int logLevel, * * The existing logs in the server should contain the level, as long as logConfigureDestination3() is used. If not, it will have the placeholder. * + * Service name is configurable. + * */ - if (!fileName || strlen(fileName) == 0 || !functionName || strlen(functionName) == 0 || lineNumber == 0) { + bool useFileMetadata = fileName && strlen(fileName) != 0 && functionName && strlen(functionName) != 0 && lineNumber != 0; + if (!useFileMetadata) { snprintf(fullMessage, fullMessageSize, "%s <%s:%s> %s %s %s", time.value, - getServiceName(), + serviceName != NULL && strlen(serviceName) != 0 ? serviceName : getDefaultServiceName(), taskInformation, user, logLevelAsString, @@ -591,7 +600,7 @@ static void prependMetadata(int logLevel, fullMessageSize, "%s <%s:%s> %s %s (%s:%s:%d) %s", time.value, - getServiceName(), + serviceName != NULL && strlen(serviceName) != 0 ? serviceName : getDefaultServiceName(), taskInformation, user, logLevelAsString, @@ -602,18 +611,19 @@ static void prependMetadata(int logLevel, } } -void printToLog(FILE *destination, - char *formatString, - va_list argList, - int logLevel, - char *fileName, - char *functionName, - unsigned int lineNumber) { -#ifdef METTLE +static void printToLog(FILE *destination, + char *formatString, + va_list argList, + int logLevel, + char *fileName, + char *functionName, + unsigned int lineNumber, + const char *serviceName) { +#ifdef METTLE printf("broken printf in logging.c\n"); #else char fullMessage[LOG_USER_ID_MAX_LENGTH + LOG_MESSAGE_MAX_LENGTH + LOG_TASK_INFO_MAX_LENGTH + 1] = {0}; - prependMetadata(logLevel, (char *) &fullMessage, sizeof(fullMessage), formatString, argList, fileName, functionName, lineNumber); + prependMetadata(logLevel, (char *) &fullMessage, sizeof(fullMessage), formatString, argList, fileName, functionName, lineNumber, serviceName); fprintf(destination, "%s\n", fullMessage); #endif } @@ -626,12 +636,13 @@ void printStdout2(LoggingContext *context, int logLevel, char *fileName, char *functionName, - unsigned int lineNumber) { - printToLog(stdout, formatString, argList, logLevel, fileName, functionName, lineNumber); + unsigned int lineNumber, + const char *serviceName) { + printToLog(stdout, formatString, argList, logLevel, fileName, functionName, lineNumber, serviceName); } void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){ - printStdout2(context, component, data, formatString, argList, ZOWE_LOG_NA, "", "", 0); + printStdout2(context, component, data, formatString, argList, ZOWE_LOG_NA, "", "", 0, ""); } void printStderr2(LoggingContext *context, @@ -642,12 +653,13 @@ void printStderr2(LoggingContext *context, int logLevel, char *fileName, char *functionName, - unsigned int lineNumber) { - printToLog(stderr, formatString, argList, logLevel, fileName, functionName, lineNumber); + unsigned int lineNumber, + const char *serviceName) { + printToLog(stderr, formatString, argList, logLevel, fileName, functionName, lineNumber, serviceName); } void printStderr(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){ - printStderr2(context, component, data, formatString, argList, ZOWE_LOG_NA, "", "", 0); + printStderr2(context, component, data, formatString, argList, ZOWE_LOG_NA, "", "", 0, ""); } void logConfigureStandardDestinations(LoggingContext *context){ @@ -826,14 +838,15 @@ int logGetLevel(LoggingContext *context, uint64 compID){ return component ? component->currentDetailLevel : ZOWE_LOG_NA; } -void zowelogInner(LoggingContext *context, - uint64 compID, - int level, - char *fileName, - char *functionName, - unsigned int lineNumber, - char *formatString, - va_list argPointer) { +static void zowelogInner(LoggingContext *context, + uint64 compID, + int level, + char *fileName, + char *functionName, + unsigned int lineNumber, + const char *serviceName, + char *formatString, + va_list argPointer) { if (logShouldTrace(context, compID, level) == FALSE) { return; @@ -868,24 +881,24 @@ void zowelogInner(LoggingContext *context, return; } if (destination->handler2) { - destination->handler2(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber); + destination->handler2(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber,serviceName); } else { destination->handler(context,component,destination->data,formatString,argPointer); } } } -void zowelog2(LoggingContext *context, uint64 compID, int level, char *fileName, char *functionName, unsigned int lineNumber, char *formatString, ...) { +void zowelog2(LoggingContext *context, uint64 compID, int level, char *fileName, char *functionName, unsigned int lineNumber, const char *serviceName, char *formatString, ...) { va_list argPointer; va_start(argPointer, formatString); - zowelogInner(context, compID, level, fileName, functionName, lineNumber, formatString, argPointer); + zowelogInner(context, compID, level, fileName, functionName, lineNumber, serviceName, formatString, argPointer); va_end(argPointer); } void zowelog(LoggingContext *context, uint64 compID, int level, char *formatString, ...){ va_list argPointer; va_start(argPointer, formatString); - zowelogInner(context, compID, level, "", "", 0, formatString, argPointer); + zowelogInner(context, compID, level, "", "", 0, "", formatString, argPointer); va_end(argPointer); } @@ -894,25 +907,27 @@ static void printToDestination(LoggingDestination *destination, LoggingComponent *component, int level, char *fileName, char *functionName, unsigned int lineNumber, + const char *serviceName, void *data, char *formatString, ...){ va_list argPointer; va_start(argPointer, formatString); if (destination->handler2) { - destination->handler2(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber); + destination->handler2(context,component,destination->data,formatString,argPointer,level,fileName,functionName,lineNumber,serviceName); } else { destination->handler(context,component,destination->data,formatString,argPointer); } va_end(argPointer); } -void zowedumpInner(LoggingContext *context, - uint64 compID, - int level, - void *data, - int dataSize, - char *fileName, - char *functionName, - unsigned int lineNumber) { +static void zowedumpInner(LoggingContext *context, + uint64 compID, + int level, + void *data, + int dataSize, + char *fileName, + char *functionName, + unsigned int lineNumber, + const char *serviceName) { if (logShouldTrace(context, compID, level) == FALSE) { return; @@ -953,7 +968,7 @@ void zowedumpInner(LoggingContext *context, for (int i = 0; ; i++){ char *result = destination->dumper(workBuffer, sizeof(workBuffer), data, dataSize, i); if (result != NULL){ - printToDestination(destination, context, component, level, fileName, functionName, lineNumber, destination->data, "%s\n", result); + printToDestination(destination, context, component, level, fileName, functionName, lineNumber, serviceName, destination->data, "%s\n", result); } else { break; @@ -963,12 +978,12 @@ void zowedumpInner(LoggingContext *context, } } -void zowedump2(LoggingContext *context, uint64 compID, int level, void *data, int dataSize, char *fileName, char *functionName, unsigned int lineNumber) { - zowedumpInner(context, compID, level, data, dataSize, fileName, functionName, lineNumber); +void zowedump2(LoggingContext *context, uint64 compID, int level, void *data, int dataSize, char *fileName, char *functionName, unsigned int lineNumber, const char *serviceName) { + zowedumpInner(context, compID, level, data, dataSize, fileName, functionName, lineNumber, serviceName); } void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int dataSize){ - zowedumpInner(context, compID, level, data, dataSize, "", "", 0); + zowedumpInner(context, compID, level, data, dataSize, "", "", 0, ""); } bool logShouldTraceInternal(LoggingContext *context, uint64 componentID, int level) { diff --git a/h/logging.h b/h/logging.h index 4c38b4c59..94097619f 100644 --- a/h/logging.h +++ b/h/logging.h @@ -24,27 +24,27 @@ #define ZOWELOG_SEVERE($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_SEVERE, \ - __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, NULL, $fmt, ##__VA_ARGS__) #define ZOWELOG_WARNING($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_WARNING, \ - __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, NULL, $fmt, ##__VA_ARGS__) #define ZOWELOG_INFO($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_INFO, \ - __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, NULL, $fmt, ##__VA_ARGS__) #define ZOWELOG_DEBUG($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_DEBUG, \ - __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, NULL, $fmt, ##__VA_ARGS__) #define ZOWELOG_DEBUG2($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_DEBUG2, \ - __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, NULL, $fmt, ##__VA_ARGS__) #define ZOWELOG_DEBUG3($id, $fmt, ...) \ zowelog2(NULL, $id, ZOWE_LOG_DEBUG3, \ - __FILE__, __FUNCTION__, __LINE__, $fmt, ##__VA_ARGS__) + __FILE__, __FUNCTION__, __LINE__, NULL, $fmt, ##__VA_ARGS__) /** \file * \brief logging.h defines a platform-independent logging facility that echoes some of Java logging. @@ -164,7 +164,8 @@ typedef void (*LogHandler2)(struct LoggingContext_tag *context, int logLevel, char *fileName, char *functionName, - unsigned int lineNumber); + unsigned int lineNumber, + const char *serviceName); typedef void (*LogHandler)(struct LoggingContext_tag *context, LoggingComponent *component, @@ -396,6 +397,14 @@ LoggingDestination *logConfigureDestination2(LoggingContext *context, LogHandler handler, DataDumper dumper); +LoggingDestination *logConfigureDestination3(LoggingContext *context, + unsigned int id, + char *name, + void *data, + LogHandler handler, + DataDumper dumper, + LogHandler2 handler2); + void logConfigureStandardDestinations(LoggingContext *context); void logConfigureComponent(LoggingContext *context, uint64 compID, @@ -410,9 +419,9 @@ extern int logSetExternalContext(LoggingContext *context); extern LoggingContext *logGetExternalContext(); void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList); -void printStdout2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel, char *fileName, char *functionName, unsigned int lineNumber); +void printStdout2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel, char *fileName, char *functionName, unsigned int lineNumber, const char *serviceName); void printStderr(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList); -void printStderr2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel, char *fileName, char *functionName, unsigned int lineNumber); +void printStderr2(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList, int logLevel, char *fileName, char *functionName, unsigned int lineNumber, const char *serviceName); #endif From e0373eaee4c56c884be96aee3d43f355ff094375 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Fri, 19 Jul 2024 16:49:37 -0500 Subject: [PATCH 11/13] committing tests Signed-off-by: Jordan Filteau --- tests/buildloggingtest.sh | 16 ++++++++++++++++ tests/loggingtest.c | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/buildloggingtest.sh diff --git a/tests/buildloggingtest.sh b/tests/buildloggingtest.sh new file mode 100644 index 000000000..d5b02b1f7 --- /dev/null +++ b/tests/buildloggingtest.sh @@ -0,0 +1,16 @@ +c89 -D_OPEN_THREADS -D_XOPEN_SOURCE=600 -DAPF_AUTHORIZED=0 -DNOIBMHTTP \ +"-Wa,goff" "-Wc,langlvl(EXTC99),float(HEX),agg,list(),so(),search(),\ +goff,xref,gonum,roconst,gonum,asm,asmlib('SYS1.MACLIB'),asmlib('CEE.SCEEMAC'),LP64" "-Wl,lp64,xplink" \ +-I ../h \ +-o loggingtest \ +./loggingtest.c \ +../c/utils.c \ +../c/logging.c \ +../c/alloc.c \ +../c/collections.c \ +../c/zos.c \ +../c/timeutls.c \ +../c/le.c \ +../c/scheduling.c \ +../c/recovery.c + diff --git a/tests/loggingtest.c b/tests/loggingtest.c index 38e27ada3..2e77b338a 100644 --- a/tests/loggingtest.c +++ b/tests/loggingtest.c @@ -32,7 +32,8 @@ * Test that logging is functional with and without new helper macros. Prove backwards compatibility. */ void main() { - LoggingContext *context = makeLoggingContext(); + LoggingContext *context = NULL; + //LoggingContext *context = makeLoggingContext(); logConfigureStandardDestinations(context); logConfigureComponent(context, LOG_COMP_DATASERVICE, "DATASERVICE", LOG_DEST_PRINTF_STDOUT, ZOWE_LOG_INFO); From ccbf89b1a3b77dad236c78231cd22cf34fe3b466 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Mon, 5 Aug 2024 16:18:02 -0500 Subject: [PATCH 12/13] updating test and build Signed-off-by: Jordan Filteau --- tests/buildloggingtest.sh | 0 tests/loggingtest.c | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 tests/buildloggingtest.sh diff --git a/tests/buildloggingtest.sh b/tests/buildloggingtest.sh old mode 100644 new mode 100755 diff --git a/tests/loggingtest.c b/tests/loggingtest.c index 2e77b338a..00beeb008 100644 --- a/tests/loggingtest.c +++ b/tests/loggingtest.c @@ -32,8 +32,8 @@ * Test that logging is functional with and without new helper macros. Prove backwards compatibility. */ void main() { - LoggingContext *context = NULL; - //LoggingContext *context = makeLoggingContext(); + LoggingContext *context = makeLoggingContext(); + logConfigureStandardDestinations(context); logConfigureComponent(context, LOG_COMP_DATASERVICE, "DATASERVICE", LOG_DEST_PRINTF_STDOUT, ZOWE_LOG_INFO); From af3de61c6e775b667df5be8ab20ded27c1b54b4c Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Mon, 5 Aug 2024 16:24:59 -0500 Subject: [PATCH 13/13] adding declarations Signed-off-by: Jordan Filteau --- h/logging.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/h/logging.h b/h/logging.h index 94097619f..cbad510ca 100644 --- a/h/logging.h +++ b/h/logging.h @@ -295,6 +295,7 @@ extern LoggingContext *theLoggingContext; #define zowelog ZOWELOG #define zowelog2 ZOWELOG2 #define zowedump ZOWEDUMP +#define zowedump2 ZOWEDUM2 #define logConfigureDestination LGCFGDST #define logConfigureDestination2 LGCFGDS2 #define logConfigureDestination3 LGCFGDS3 @@ -377,7 +378,9 @@ bool logShouldTraceInternal(LoggingContext *context, uint64 componentID, int lev */ void zowelog(LoggingContext *context, uint64 compID, int level, char *formatString, ...); +void zowelog2(LoggingContext *context, uint64 compID, int level, char *fileName, char *functionName, unsigned int lineNumber, const char *serviceName, char *formatString, ...); void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int dataSize); +void zowedump2(LoggingContext *context, uint64 compID, int level, void *data, int dataSize, char *fileName, char *functionName, unsigned int lineNumber, const char *serviceName); #define LOGCHECK(context,component,level) \ ((component > MAX_LOGGING_COMPONENTS) ? \