Skip to content

Commit

Permalink
Merge pull request #6020 from grom72/core-log-level-hark
Browse files Browse the repository at this point in the history
common: introduce logging level HARK
  • Loading branch information
janekmi authored Feb 22, 2024
2 parents 8ff6a12 + 2836433 commit 38d414e
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/core/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define CORE_LOG_THRESHOLD_AUX_DEFAULT CORE_LOG_LEVEL_WARNING
#else
#define CORE_LOG_THRESHOLD_DEFAULT CORE_LOG_LEVEL_WARNING
#define CORE_LOG_THRESHOLD_AUX_DEFAULT CORE_LOG_DISABLED
#define CORE_LOG_THRESHOLD_AUX_DEFAULT CORE_LOG_LEVEL_HARK
#endif

/*
Expand Down Expand Up @@ -148,7 +148,7 @@ core_log_set_threshold(enum core_log_threshold threshold,
threshold != CORE_LOG_THRESHOLD_AUX)
return EINVAL;

if (level < CORE_LOG_DISABLED || level > CORE_LOG_LEVEL_DEBUG)
if (level < CORE_LOG_LEVEL_HARK || level > CORE_LOG_LEVEL_DEBUG)
return EINVAL;

#ifdef ATOMIC_OPERATIONS_SUPPORTED
Expand Down
17 changes: 5 additions & 12 deletions src/core/log_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#include "os.h"
#include "util.h"

static const char log_level_names[6][9] = {
static const char log_level_names[CORE_LOG_LEVEL_MAX][9] = {
[CORE_LOG_LEVEL_HARK] = "*HARK* ",
[CORE_LOG_LEVEL_FATAL] = "*FATAL* ",
[CORE_LOG_LEVEL_ERROR] = "*ERROR* ",
[CORE_LOG_LEVEL_WARNING] = "*WARN* ",
Expand All @@ -32,6 +33,7 @@ static const char log_level_names[6][9] = {
};

static const int log_level_syslog_severity[] = {
[CORE_LOG_LEVEL_HARK] = LOG_NOTICE,
[CORE_LOG_LEVEL_FATAL] = LOG_CRIT,
[CORE_LOG_LEVEL_ERROR] = LOG_ERR,
[CORE_LOG_LEVEL_WARNING] = LOG_WARNING,
Expand Down Expand Up @@ -105,15 +107,6 @@ core_log_default_function(void *context, enum core_log_level level,
char file_info_buffer[256] = "";
const char *file_info = file_info_buffer;
const char file_info_error[] = "[file info error]: ";
bool is_always = false;

if (CORE_LOG_DISABLED == level)
return;

if (level == CORE_LOG_LEVEL_ALWAYS) {
is_always = true;
level = CORE_LOG_LEVEL_NOTICE;
}

if (file_name) {
/* extract base_file_name */
Expand All @@ -136,12 +129,12 @@ core_log_default_function(void *context, enum core_log_level level,
log_level_names[level], file_info, message);

/*
* Since the CORE_LOG_LEVEL_ALWAYS level messages convey pretty mundane
* Since the CORE_LOG_LEVEL_HARK level messages convey pretty mundane
* information regarding the libraries versions etc. it has been decided
* to print them out to the syslog and under no circumstances to stderr
* to keep it clean for potentially more critical information.
*/
if (is_always) {
if (level == CORE_LOG_LEVEL_HARK) {
return;
}

Expand Down
12 changes: 5 additions & 7 deletions src/core/log_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extern "C" {
#endif

enum core_log_level {
/* all messages will be suppressed */
CORE_LOG_DISABLED = -1,
/* only basic library info */
CORE_LOG_LEVEL_HARK,
/* an error that causes the library to stop working immediately */
CORE_LOG_LEVEL_FATAL,
/* an error that causes the library to stop working properly */
Expand All @@ -36,11 +36,9 @@ enum core_log_level {
CORE_LOG_LEVEL_INFO,
/* debug info e.g. write operation dump */
CORE_LOG_LEVEL_DEBUG,
CORE_LOG_LEVEL_MAX
};

/* Not meant to be used directly. */
#define CORE_LOG_LEVEL_ALWAYS (CORE_LOG_DISABLED - 1)

enum core_log_threshold {
/*
* the main threshold level - the logging messages above this level
Expand Down Expand Up @@ -184,8 +182,8 @@ void core_log_to_last(int errnum, const char *file_name, int line_no,
abort(); \
} while (0)

#define CORE_LOG_ALWAYS(format, ...) \
_CORE_LOG(CORE_LOG_LEVEL_ALWAYS, NO_ERRNO, format, ##__VA_ARGS__)
#define CORE_LOG_HARK(format, ...) \
_CORE_LOG(CORE_LOG_LEVEL_HARK, NO_ERRNO, format, ##__VA_ARGS__)

/*
* 'With errno' macros' flavours. Append string describing the current errno
Expand Down
31 changes: 13 additions & 18 deletions src/core/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ static unsigned Log_alignment;

#ifdef DEBUG
static const enum core_log_level level_to_core_log_level[5] = {
[0] = CORE_LOG_DISABLED,
[0] = CORE_LOG_LEVEL_HARK,
[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] = {
static const int core_log_level_to_level[CORE_LOG_LEVEL_MAX] = {
[CORE_LOG_LEVEL_HARK] = 1,
[CORE_LOG_LEVEL_FATAL] = 1,
[CORE_LOG_LEVEL_ERROR] = 1,
[CORE_LOG_LEVEL_WARNING] = 2,
Expand All @@ -55,13 +56,7 @@ out_legacy(void *context, enum core_log_level core_level, const char *file_name,
{
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];
}

int level = core_log_level_to_level[core_level];
out_log(file_name, line_no, function_name, level, "%s", message);
}
#endif /* DEBUG */
Expand Down Expand Up @@ -161,48 +156,48 @@ out_init(const char *log_prefix, const char *log_level_var,

#ifdef DEBUG
static char namepath[PATH_MAX];
CORE_LOG_ALWAYS("pid %d: program: %s", getpid(),
CORE_LOG_HARK("pid %d: program: %s", getpid(),
util_getexecname(namepath, PATH_MAX));
#endif
CORE_LOG_ALWAYS("%s version %d.%d", log_prefix, major_version,
CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version,
minor_version);

static __attribute__((used)) const char *version_msg =
"src version: " SRCVERSION;
CORE_LOG_ALWAYS("%s", version_msg);
CORE_LOG_HARK("%s", version_msg);
#if VG_PMEMCHECK_ENABLED
/*
* Attribute "used" to prevent compiler from optimizing out the variable
* when LOG expands to no code (!DEBUG)
*/
static __attribute__((used)) const char *pmemcheck_msg =
"compiled with support for Valgrind pmemcheck";
CORE_LOG_ALWAYS("%s", pmemcheck_msg);
CORE_LOG_HARK("%s", pmemcheck_msg);
#endif /* VG_PMEMCHECK_ENABLED */
#if VG_HELGRIND_ENABLED
static __attribute__((used)) const char *helgrind_msg =
"compiled with support for Valgrind helgrind";
CORE_LOG_ALWAYS("%s", helgrind_msg);
CORE_LOG_HARK("%s", helgrind_msg);
#endif /* VG_HELGRIND_ENABLED */
#if VG_MEMCHECK_ENABLED
static __attribute__((used)) const char *memcheck_msg =
"compiled with support for Valgrind memcheck";
CORE_LOG_ALWAYS("%s", memcheck_msg);
CORE_LOG_HARK("%s", memcheck_msg);
#endif /* VG_MEMCHECK_ENABLED */
#if VG_DRD_ENABLED
static __attribute__((used)) const char *drd_msg =
"compiled with support for Valgrind drd";
CORE_LOG_ALWAYS("%s", drd_msg);
CORE_LOG_HARK("%s", drd_msg);
#endif /* VG_DRD_ENABLED */
#if SDS_ENABLED
static __attribute__((used)) const char *shutdown_state_msg =
"compiled with support for shutdown state";
CORE_LOG_ALWAYS("%s", shutdown_state_msg);
CORE_LOG_HARK("%s", shutdown_state_msg);
#endif
#if NDCTL_ENABLED
static __attribute__((used)) const char *ndctl_ge_63_msg =
"compiled with libndctl 63+";
CORE_LOG_ALWAYS("%s", ndctl_ge_63_msg);
CORE_LOG_HARK("%s", ndctl_ge_63_msg);
#endif

last_error_msg_init();
Expand Down
19 changes: 10 additions & 9 deletions src/include/libpmemobj/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ extern "C" {
#endif

/*
* Available log levels. Log levels (except for PMEMOBJ_LOG_DISABLED) are used
* in the logging API calls to indicate logging message severity. Log levels are
* also used to define thresholds for the logging.
* Available log levels. Log levels are used in the logging API calls
* to indicate logging message severity. Log levels are also used
* to define thresholds for the logging.
*/
enum pmemobj_log_level {
/* all messages will be suppressed */
PMEMOBJ_LOG_DISABLED = -1,
/* only basic library info */
PMEMOBJ_LOG_LEVEL_HARK,
/* an error that causes the library to stop working immediately */
PMEMOBJ_LOG_LEVEL_FATAL,
/* an error that causes the library to stop working properly */
Expand Down Expand Up @@ -57,7 +57,7 @@ enum pmemobj_log_threshold {
* enum pmemobj_log_level level);
*
* enum log_level {
* PMEMOBJ_LOG_DISABLED,
* PMEMOBJ_LOG_LEVEL_HARK,
* PMEMOBJ_LOG_LEVEL_FATAL,
* PMEMOBJ_LOG_LEVEL_ERROR,
* PMEMOBJ_LOG_LEVEL_WARNING,
Expand All @@ -78,15 +78,16 @@ enum pmemobj_log_threshold {
* Available thresholds are:
* - PMEMOBJ_LOG_THRESHOLD - the main threshold used to filter out undesired
* logging messages. Messages on a higher level than the primary threshold
* level are ignored. PMEMOBJ_LOG_DISABLED shall be used to suppress logging.
* level are ignored. PMEMOBJ_LOG_LEVEL_HARK shall be used to suppress
* logging.
* The default value is PMEMOBJ_LOG_WARNING.
* - PMEMOBJ_LOG_THRESHOLD_AUX - the auxiliary threshold intended for use inside
* the logging function (please see log_get_threshold(3)). The logging
* function may or may not take this threshold into consideration. The default
* value is PMEMOBJ_LOG_DISABLED.
* value is PMEMOBJ_LOG_LEVEL_HARK.
*
* Available threshold levels are defined by enum log_level:
* - PMEMOBJ_LOG_DISABLED - all messages will be suppressed
* - PMEMOBJ_LOG_LEVEL_HARK - only basic library info
* - PMEMOBJ_LOG_LEVEL_FATAL - an error that causes the library to stop working
* immediately
* - PMEMOBJ_LOG_LEVEL_ERROR - an error that causes the library to stop working
Expand Down
10 changes: 5 additions & 5 deletions src/libpmempool/replica.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs)

os_fclose(recovery_file);

CORE_LOG_ALWAYS("bad blocks read from the recovery file -- '%s'", path);
CORE_LOG_HARK("bad blocks read from the recovery file -- '%s'", path);

return 0;

Expand Down Expand Up @@ -928,7 +928,7 @@ replica_badblocks_recovery_files_read(struct pool_set *set,
continue;
}

CORE_LOG_ALWAYS(
CORE_LOG_HARK(
"reading bad blocks from the recovery file -- '%s'",
part_hs->recovery_file_name);

Expand Down Expand Up @@ -1280,7 +1280,7 @@ replica_badblocks_check_or_clear(struct pool_set *set,
*/

if (!dry_run) {
CORE_LOG_ALWAYS(
CORE_LOG_HARK(
"removing all bad block recovery files...");
ret = replica_remove_all_recovery_files(set_hs);
if (ret < 0) {
Expand All @@ -1289,7 +1289,7 @@ replica_badblocks_check_or_clear(struct pool_set *set,
return -1;
}
} else {
CORE_LOG_ALWAYS(
CORE_LOG_HARK(
"all bad block recovery files would be removed");
}

Expand Down Expand Up @@ -1360,7 +1360,7 @@ replica_badblocks_check_or_clear(struct pool_set *set,

if (dry_run) {
/* dry-run - do nothing */
CORE_LOG_ALWAYS("bad blocks would be cleared");
CORE_LOG_HARK("bad blocks would be cleared");
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions src/libpmempool/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ sync_badblocks_data(struct pool_set *set, struct poolset_health_status *set_hs)
sync_mark_replica_no_badblocks(r, set_hs);
}

CORE_LOG_ALWAYS("all bad blocks have been fixed");
CORE_LOG_HARK("all bad blocks have been fixed");

if (replica_remove_all_recovery_files(set_hs)) {
CORE_LOG_ERROR("removing bad block recovery files failed");
Expand Down Expand Up @@ -1326,7 +1326,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs,

/* check if poolset is broken; if not, nothing to do */
if (replica_is_poolset_healthy(set_hs)) {
CORE_LOG_ALWAYS("poolset is healthy");
CORE_LOG_HARK("poolset is healthy");
goto out;
}
} else {
Expand All @@ -1348,7 +1348,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs,

/* in dry-run mode we can stop here */
if (is_dry_run(flags)) {
CORE_LOG_ALWAYS("Sync in dry-run mode finished successfully");
CORE_LOG_HARK("Sync in dry-run mode finished successfully");
goto out;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libpmempool/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out,
CORE_LOG_ERROR(
"falling back to the input poolset failed");
} else {
CORE_LOG_ALWAYS(
CORE_LOG_HARK(
"falling back to the input poolset succeeded");
}
ret = -1;
Expand All @@ -938,7 +938,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out,
CORE_LOG_ERROR(
"falling back to the input poolset failed");
} else {
CORE_LOG_ALWAYS(
CORE_LOG_HARK(
"falling back to the input poolset succeeded");
}
ret = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/test/traces/custom_file0.log.match
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $(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 HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
$(nW) <3> $(nW) $(nW) Log level INFO
Expand Down
2 changes: 1 addition & 1 deletion src/test/traces/redir_stderr2.log.match
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ $(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 HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
2 changes: 1 addition & 1 deletion src/test/traces/redir_stderr3.log.match
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ $(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 HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
2 changes: 1 addition & 1 deletion src/test/traces/redir_stderr4.log.match
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $(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 HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
$(nW) <3> $(nW) $(nW) Log level INFO
Expand Down
2 changes: 1 addition & 1 deletion src/test/traces/redir_stderr5.log.match
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $(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 HARK
$(nW) <1> $(nW) $(nW) Log level ERROR
$(nW) <2> $(nW) $(nW) Log level WARNING
$(nW) <3> $(nW) $(nW) Log level INFO
Expand Down
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);
CORE_LOG_ALWAYS("Log level ALWAYS");
CORE_LOG_HARK("Log level HARK");
CORE_LOG_ERROR("Log level ERROR");
CORE_LOG_WARNING("Log level WARNING");
LOG(3, "Log level INFO");
Expand Down
4 changes: 1 addition & 3 deletions src/test/unittest/ut_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "out.h"

static const int core_log_level_to_out_level[] = {
[CORE_LOG_LEVEL_HARK] = 1,
[CORE_LOG_LEVEL_FATAL] = 1,
[CORE_LOG_LEVEL_ERROR] = 1,
[CORE_LOG_LEVEL_WARNING] = 2,
Expand All @@ -22,9 +23,6 @@ void
ut_log_function(void *context, enum core_log_level level, const char *file_name,
const int line_no, const char *function_name, const char *message)
{
if (level == CORE_LOG_LEVEL_ALWAYS)
level = CORE_LOG_LEVEL_ERROR;

out_log(file_name, line_no, function_name,
core_log_level_to_out_level[(int)level], "%s", message);
}

0 comments on commit 38d414e

Please sign in to comment.