diff --git a/src/core/out.c b/src/core/out.c index b55142e6906..3c0790f790f 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -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 * @@ -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 && @@ -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"); diff --git a/src/test/traces/TEST6 b/src/test/traces/TEST6 deleted file mode 100755 index 05da8876e43..00000000000 --- a/src/test/traces/TEST6 +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2019, Intel Corporation - -# -# src/test/traces/TEST6 -- unit test for traces -# - -. ../unittest/unittest.sh - -require_test_type medium - -require_fs_type none -require_build_type debug - -setup - -export UT_LOG_LEVEL=4 -expect_normal_exit ./traces$EXESUFFIX 2>redir_stderr$UNITTEST_NUM.log - -check - -pass diff --git a/src/test/traces/custom_file0.log.match b/src/test/traces/custom_file0.log.match index 9209b0590f2..a3733783de9 100644 --- a/src/test/traces/custom_file0.log.match +++ b/src/test/traces/custom_file0.log.match @@ -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) diff --git a/src/test/traces/redir_stderr1.log.match b/src/test/traces/redir_stderr1.log.match index 3d739c871d8..e69de29bb2d 100644 --- a/src/test/traces/redir_stderr1.log.match +++ b/src/test/traces/redir_stderr1.log.match @@ -1 +0,0 @@ -$(*)Log level NONE diff --git a/src/test/traces/redir_stderr2.log.match b/src/test/traces/redir_stderr2.log.match index 0ff6e699564..79271cadab2 100644 --- a/src/test/traces/redir_stderr2.log.match +++ b/src/test/traces/redir_stderr2.log.match @@ -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 diff --git a/src/test/traces/redir_stderr3.log.match b/src/test/traces/redir_stderr3.log.match index 1f4b14419a3..dfee35a04d7 100644 --- a/src/test/traces/redir_stderr3.log.match +++ b/src/test/traces/redir_stderr3.log.match @@ -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 diff --git a/src/test/traces/redir_stderr4.log.match b/src/test/traces/redir_stderr4.log.match index 97f9f09bf48..15cb460f06a 100644 --- a/src/test/traces/redir_stderr4.log.match +++ b/src/test/traces/redir_stderr4.log.match @@ -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) diff --git a/src/test/traces/redir_stderr5.log.match b/src/test/traces/redir_stderr5.log.match index 9209b0590f2..a3733783de9 100644 --- a/src/test/traces/redir_stderr5.log.match +++ b/src/test/traces/redir_stderr5.log.match @@ -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) diff --git a/src/test/traces/redir_stderr6.log.match b/src/test/traces/redir_stderr6.log.match deleted file mode 100644 index c96567c6243..00000000000 --- a/src/test/traces/redir_stderr6.log.match +++ /dev/null @@ -1,16 +0,0 @@ -$(*) -$(*) -$(*) -$(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+ -$(*) -: <0> [traces.c:$(*) main]$(W)Log level NONE -: <1> [traces.c:$(*) main]$(W)Log level ERROR -: <2> [traces.c:$(*) main]$(W)Log level WARNING -: <3> [traces.c:$(*) main]$(W)Log level INFO -: <4> [traces.c:$(*) main]$(W)Log level DEBUG -$(*) diff --git a/src/test/traces/traces.c b/src/test/traces/traces.c index e61046bcebf..05e08499026 100644 --- a/src/test/traces/traces.c +++ b/src/test/traces/traces.c @@ -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");