Skip to content

Commit

Permalink
common: print basic lib info when new logging function is set
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromadzki <tomasz.gromadzki@intel.com>
  • Loading branch information
grom72 committed Feb 22, 2024
1 parent 38d414e commit 1affe63
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 19 deletions.
16 changes: 14 additions & 2 deletions src/core/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ core_log_fini()
core_log_default_fini();
}

static void
core_log_lib_info(void) {
CORE_LOG_HARK("src version: " SRCVERSION);
#if SDS_ENABLED
CORE_LOG_HARK("compiled with support for shutdown state");
#endif
#if NDCTL_ENABLED
CORE_LOG_HARK("compiled with libndctl 63+");
#endif
}
/*
* core_log_set_function -- set the log function pointer either to
* a user-provided function pointer or to the default logging function.
Expand All @@ -127,10 +137,12 @@ core_log_set_function(core_log_function *log_function, void *context)
core_log_function_old, (uintptr_t)log_function))
return EAGAIN;
if (__sync_bool_compare_and_swap(&Core_log_function_context,
context_old, context))
context_old, context)) {
core_log_lib_info();
return 0;
}

__sync_bool_compare_and_swap(&Core_log_function,
(void) __sync_bool_compare_and_swap(&Core_log_function,
(uintptr_t)log_function, core_log_function_old);
return EAGAIN;

Expand Down
17 changes: 9 additions & 8 deletions src/core/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ 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 All @@ -154,11 +147,19 @@ out_init(const char *log_prefix, const char *log_level_var,
else
setlinebuf(Out_fp);

#ifdef DEBUG
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 */
#ifdef DEBUG
static char namepath[PATH_MAX];
CORE_LOG_HARK("pid %d: program: %s", getpid(),
util_getexecname(namepath, PATH_MAX));
#endif
#endif /* DEBUG */
CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version,
minor_version);

Expand Down
21 changes: 12 additions & 9 deletions src/test/arch_flags/log0.log.match
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<arch_flags>: <1> [$(nW) out_init]$(W)pid $(nW): program: $(nW)
<arch_flags>: <1> [$(nW) out_init]$(W)arch_flags version 0.0
<arch_flags>: <1> [$(nW) out_init]$(W)src version: $(nW)
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for Valgrind pmemcheck
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for Valgrind helgrind
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for Valgrind memcheck
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for Valgrind drd
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with support for shutdown state
$(OPT)<arch_flags>: <1> [$(nW) out_init]$(W)compiled with libndctl 63+
<arch_flags>: <1> [$(*)]$(W)src version: $(nW)
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for shutdown state
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with libndctl 63+
<arch_flags>: <1> [$(*)]$(W)pid $(nW): program: $(nW)
<arch_flags>: <1> [$(*)]$(W)arch_flags version 0.0
<arch_flags>: <1> [$(*)]$(W)src version: $(nW)
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for Valgrind pmemcheck
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for Valgrind helgrind
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for Valgrind memcheck
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for Valgrind drd
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with support for shutdown state
$(OPT)<arch_flags>: <1> [$(*)]$(W)compiled with libndctl 63+
<arch_flags>: <3> [$(nW) util_mmap_init]
<arch_flags>: <1> [$(nW) util_check_arch_flags]$(W)invalid machine value
<arch_flags>: <1> [$(nW) util_check_arch_flags]$(W)invalid machine_class value
Expand Down
3 changes: 3 additions & 0 deletions src/test/out_err/traces0.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<trace>: <1> [$(*)]$(W)src version: $(nW)
$(OPT)<trace>: <1> [$(*)]$(W)compiled with support for shutdown state
$(OPT)<trace>: <1> [$(*)]$(W)compiled with libndctl 63+
<trace>: <1> [out.c:$(N) out_init]$(W)pid $(N): program: $(nW)
<trace>: <1> [out.c:$(N) out_init]$(W)trace version 1.0
<trace>: <1> [out.c:$(N) out_init]$(W)src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/traces/custom_file0.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/traces/redir_stderr2.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/traces/redir_stderr3.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/traces/redir_stderr4.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/traces/redir_stderr5.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$(nW) <1> $(nW) $(nW) src version: $(nW)
$(nW) <1> $(nW) $(nW) compiled with support for shutdown state
$(nW) <1> $(nW) $(nW) compiled with libndctl 63+
$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW)
$(nW) <1> $(nW) $(nW) ut version 1.0
$(nW) <1> $(nW) $(nW) src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/util_poolset/grep0.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)/util_poolset$(nW)
ut version 1.0
src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/util_poolset/grep1.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)/util_poolset$(nW)
ut version 1.0
src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/util_poolset/grep2.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)/util_poolset$(nW)
ut version 1.0
src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/util_poolset/grep3.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)util_poolset$(nW)
ut version 1.0
src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/util_poolset/grep4.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)util_poolset$(nW)
ut version 1.0
src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/util_poolset/grep5.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)util_poolset$(nW)
ut version 1.0
src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/util_poolset/grep6.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)util_poolset$(nW)
ut version 1.0
src version: $(nW)
Expand Down
3 changes: 3 additions & 0 deletions src/test/util_poolset/grep7.log.match
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src version: $(nW)
$(OPT)compiled with support for shutdown state
$(OPT)compiled with libndctl 63+
pid $(N): program: $(nW)util_poolset$(nW)
ut version 1.0
src version: $(nW)
Expand Down

0 comments on commit 1affe63

Please sign in to comment.