Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP zowe log formatting #166

Draft
wants to merge 6 commits into
base: v1.x/staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions c/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,25 @@ LoggingDestination *logConfigureDestination2(LoggingContext *context,
return destination;
}

LoggingDestination *logConfigureDestination3(LoggingContext *context,
unsigned int id,
char *name,
void *data,
LogHandler handler,
DataDumper dumper,
LogHandler2 handler2){
LoggingDestination *destination = logConfigureDestination(context, id, name, data, handler);
if (destination != NULL) {
if (destination->handler2 != NULL) {
destination->handler2 = handler2;
}
if (destination->dumper != NULL) {
destination->dumper = dumper;
}
}
return destination;
}

void printStdout(LoggingContext *context, LoggingComponent *component, void *data, char *formatString, va_list argList){
#ifdef METTLE
printf("broken printf in logging.c\n");
Expand Down Expand Up @@ -648,7 +667,51 @@ int logGetLevel(LoggingContext *context, uint64 compID){
}

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;
}
Expand Down Expand Up @@ -687,12 +750,13 @@ 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 (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,
Expand Down
19 changes: 19 additions & 0 deletions h/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,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{
Expand All @@ -116,6 +125,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
Expand Down Expand Up @@ -299,13 +309,22 @@ 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, void *userData, char *formatString, ...);
void zowedump(LoggingContext *context, uint64 compID, int level, void *data, int dataSize);

#define LOGCHECK(context,component,level) \
((component > MAX_LOGGING_COMPONENTS) ? \
(context->applicationComponents[component].level >= level) : \
(context->coreComponents[component].level >= level) )

#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,
Expand Down