Skip to content

Commit

Permalink
common: disable out_* functions in release build
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 27, 2024
1 parent bbe8082 commit 2129693
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 11 additions & 11 deletions src/core/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
#include "log_internal.h"
#include "last_error_msg.h"

#ifdef DEBUG

#define MAXPRINT 8192

static const char *Log_prefix;
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_LEVEL_HARK,
[1] = CORE_LOG_LEVEL_ERROR,
Expand Down Expand Up @@ -72,7 +73,8 @@ out_init(const char *log_prefix, const char *log_level_var,
int minor_version)
{
/* suppress unused-parameter errors */
SUPPRESS_UNUSED(log_level_var, log_file_var);
SUPPRESS_UNUSED(log_prefix, log_level_var, log_file_var, major_version,
minor_version);

static int once;

Expand All @@ -81,6 +83,7 @@ out_init(const char *log_prefix, const char *log_level_var,
return;
once++;

#ifdef DEBUG
Log_prefix = log_prefix;

char *log_alignment = os_getenv("PMDK_LOG_ALIGN");
Expand All @@ -90,7 +93,6 @@ out_init(const char *log_prefix, const char *log_level_var,
Log_alignment = (unsigned)align;
}

#ifdef DEBUG
char *log_file;
if ((log_file = os_getenv(log_file_var)) != NULL &&
log_file[0] != '\0') {
Expand All @@ -116,14 +118,12 @@ out_init(const char *log_prefix, const char *log_level_var,
abort();
}
}
#endif /* DEBUG */

if (Out_fp == NULL)
Out_fp = stderr;
else
setlinebuf(Out_fp);

#ifdef DEBUG
char *log_level;
int log_level_cropped = 0;
int ret;
Expand Down Expand Up @@ -154,16 +154,12 @@ out_init(const char *log_prefix, const char *log_level_var,
CORE_LOG_FATAL("Cannot set legacy log function");
}
}
#endif /* DEBUG */

/*
* Print library info
*/
#ifdef DEBUG
static char namepath[PATH_MAX];
CORE_LOG_HARK("pid %d: program: %s", getpid(),
util_getexecname(namepath, PATH_MAX));
#endif /* DEBUG */

CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version,
minor_version);
Expand Down Expand Up @@ -192,7 +188,7 @@ out_init(const char *log_prefix, const char *log_level_var,
"compiled with support for Valgrind drd";
CORE_LOG_HARK("%s", drd_msg);
#endif /* VG_DRD_ENABLED */

#endif /* DEBUG */
last_error_msg_init();
}

Expand All @@ -204,12 +200,15 @@ out_init(const char *log_prefix, const char *log_level_var,
void
out_fini(void)
{
#ifdef DEBUG
if (Out_fp != NULL && Out_fp != stderr) {
fclose(Out_fp);
Out_fp = stderr;
}
#endif
}

#ifdef DEBUG
/*
* out_print_func -- print function, goes to Out_fp (stderr by default)
*/
Expand Down Expand Up @@ -303,7 +302,7 @@ out_common(const char *file, int line, const char *func, int level,
/*
* out_log_va/out_log -- output a log line if Log_level >= level
*/
void
static void
out_log_va(const char *file, int line, const char *func, int level,
const char *fmt, va_list ap)
{
Expand All @@ -323,3 +322,4 @@ out_log(const char *file, int line, const char *func, int level,

va_end(ap);
}
#endif /* DEBUG */
2 changes: 0 additions & 2 deletions src/core/out.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ void out_init(const char *log_prefix, const char *log_level_var,
const char *log_file_var, int major_version,
int minor_version);
void out_fini(void);
void out_log_va(const char *file, int line, const char *func, int level,
const char *fmt, va_list ap);
void out_log(const char *file, int line, const char *func, int level,
const char *fmt, ...) FORMAT_PRINTF(5, 6);

Expand Down

0 comments on commit 2129693

Please sign in to comment.