Skip to content

Commit

Permalink
common: pass all logs through legacy out if...
Browse files Browse the repository at this point in the history
...any of the debug logging environment variables are set.

Signed-off-by: Jan Michalski <jan.michalski@intel.com>
  • Loading branch information
janekmi committed Feb 13, 2024
1 parent 004e85d commit 6ac049b
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 111 deletions.
59 changes: 59 additions & 0 deletions src/core/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@ static int Log_level;
static FILE *Out_fp;
static unsigned Log_alignment;

#ifdef DEBUG
static const enum core_log_level level_to_core_log_level[5] = {
[0] = CORE_LOG_DISABLED,
[1] = CORE_LOG_LEVEL_ERROR,
[2] = CORE_LOG_LEVEL_NOTICE,
[3] = CORE_LOG_LEVEL_INFO,
[4] = CORE_LOG_LEVEL_DEBUG,
};

static const int core_log_level_to_level[6] = {
[CORE_LOG_LEVEL_FATAL] = 1,
[CORE_LOG_LEVEL_ERROR] = 1,
[CORE_LOG_LEVEL_WARNING] = 2,
[CORE_LOG_LEVEL_NOTICE] = 2,
[CORE_LOG_LEVEL_INFO] = 3,
[CORE_LOG_LEVEL_DEBUG] = 4,
};

#define OUT_MAX_LEVEL 4

static void
out_legacy(void *context, enum core_log_level core_level, const char *file_name,
const int line_no, const char *function_name, const char *message)
{
SUPPRESS_UNUSED(context);

int level;
if (core_level == CORE_LOG_LEVEL_ALWAYS) {
level = 1; /* traditionally used for this kind of messages */
} else {
level = core_log_level_to_level[core_level];
}

out_log(file_name, line_no, function_name, level, "%s", message);
}
#endif /* DEBUG */

/*
* out_init -- initialize the log
*
Expand All @@ -54,12 +91,27 @@ out_init(const char *log_prefix, const char *log_level_var,
#ifdef DEBUG
char *log_level;
char *log_file;
int log_level_cropped = 0;
int ret;

if ((log_level = os_getenv(log_level_var)) != NULL) {
Log_level = atoi(log_level);
if (Log_level < 0) {
Log_level = 0;
}
if (Log_level <= OUT_MAX_LEVEL) {
log_level_cropped = Log_level;
} else {
log_level_cropped = OUT_MAX_LEVEL;
}
}

if (log_level != NULL) {
ret = core_log_set_threshold(CORE_LOG_THRESHOLD,
level_to_core_log_level[log_level_cropped]);
if (ret) {
CORE_LOG_FATAL("Cannot set log threshold");
}
}

if ((log_file = os_getenv(log_file_var)) != NULL &&
Expand All @@ -86,6 +138,13 @@ out_init(const char *log_prefix, const char *log_level_var,
abort();
}
}

if (log_level != NULL || log_file != NULL) {
ret = core_log_set_function(out_legacy, NULL);
if (ret) {
CORE_LOG_FATAL("Cannot set legacy log function");
}
}
#endif /* DEBUG */

char *log_alignment = os_getenv("PMDK_LOG_ALIGN");
Expand Down
23 changes: 0 additions & 23 deletions src/test/traces/TEST6

This file was deleted.

32 changes: 16 additions & 16 deletions src/test/traces/custom_file0.log.match
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$(*)
$(*)
$(*)
$(OPT)$(*) compiled with support for Valgrind pmemcheck
$(OPT)$(*) compiled with support for Valgrind helgrind
$(OPT)$(*) compiled with support for Valgrind memcheck
$(OPT)$(*) compiled with support for Valgrind drd
$(OPT)$(*) compiled with support for shutdown state
$(OPT)$(*) compiled with libndctl 63+
$(*)
$(*)Log level NONE
$(*)Log level ERROR
$(*)Log level WARNING
$(*)Log level INFO
$(*)Log level DEBUG
$(*)
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <3> $(nW) $(nW)
$(nW) <1> $(nW) $(nW) Log level ALWAYS
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
$(nW) <3> $(nW) $(nW) Log level INFO
$(nW) <4> $(nW) $(nW) Log level DEBUG
$(nW) <3> $(nW) $(nW)
1 change: 0 additions & 1 deletion src/test/traces/redir_stderr1.log.match
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
$(*)Log level NONE
22 changes: 11 additions & 11 deletions src/test/traces/redir_stderr2.log.match
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
$(*)
$(*)
$(*)
$(OPT)$(*) compiled with support for Valgrind pmemcheck
$(OPT)$(*) compiled with support for Valgrind helgrind
$(OPT)$(*) compiled with support for Valgrind memcheck
$(OPT)$(*) compiled with support for Valgrind drd
$(OPT)$(*) compiled with support for shutdown state
$(OPT)$(*) compiled with libndctl 63+
$(*)Log level NONE
$(*)Log level ERROR
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) Log level ALWAYS
$(nW) <1> $(nW) $(nW) Log level ERROR
24 changes: 12 additions & 12 deletions src/test/traces/redir_stderr3.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$(*)
$(*)
$(*)
$(OPT)$(*) compiled with support for Valgrind pmemcheck
$(OPT)$(*) compiled with support for Valgrind helgrind
$(OPT)$(*) compiled with support for Valgrind memcheck
$(OPT)$(*) compiled with support for Valgrind drd
$(OPT)$(*) compiled with support for shutdown state
$(OPT)$(*) compiled with libndctl 63+
$(*)Log level NONE
$(*)Log level ERROR
$(*)Log level WARNING
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) Log level ALWAYS
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
30 changes: 15 additions & 15 deletions src/test/traces/redir_stderr4.log.match
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
$(*)
$(*)
$(*)
$(OPT)$(*) compiled with support for Valgrind pmemcheck
$(OPT)$(*) compiled with support for Valgrind helgrind
$(OPT)$(*) compiled with support for Valgrind memcheck
$(OPT)$(*) compiled with support for Valgrind drd
$(OPT)$(*) compiled with support for shutdown state
$(OPT)$(*) compiled with libndctl 63+
$(*)
$(*)Log level NONE
$(*)Log level ERROR
$(*)Log level WARNING
$(*)Log level INFO
$(*)
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <3> $(nW) $(nW)
$(nW) <1> $(nW) $(nW) Log level ALWAYS
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
$(nW) <3> $(nW) $(nW) Log level INFO
$(nW) <3> $(nW) $(nW)
32 changes: 16 additions & 16 deletions src/test/traces/redir_stderr5.log.match
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$(*)
$(*)
$(*)
$(OPT)$(*) compiled with support for Valgrind pmemcheck
$(OPT)$(*) compiled with support for Valgrind helgrind
$(OPT)$(*) compiled with support for Valgrind memcheck
$(OPT)$(*) compiled with support for Valgrind drd
$(OPT)$(*) compiled with support for shutdown state
$(OPT)$(*) compiled with libndctl 63+
$(*)
$(*)Log level NONE
$(*)Log level ERROR
$(*)Log level WARNING
$(*)Log level INFO
$(*)Log level DEBUG
$(*)
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck
$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <3> $(nW) $(nW)
$(nW) <1> $(nW) $(nW) Log level ALWAYS
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
$(nW) <3> $(nW) $(nW) Log level INFO
$(nW) <4> $(nW) $(nW) Log level DEBUG
$(nW) <3> $(nW) $(nW)
16 changes: 0 additions & 16 deletions src/test/traces/redir_stderr6.log.match

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/traces/traces.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ main(int argc, char *argv[])
/* Execute test */
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
LOG(0, "Log level NONE");
CORE_LOG_ALWAYS("Log level ALWAYS");
CORE_LOG_ERROR("Log level ERROR");
CORE_LOG_WARNING("Log level WARNING");
LOG(3, "Log level INFO");
Expand Down

0 comments on commit 6ac049b

Please sign in to comment.