Skip to content

Commit

Permalink
log: keep log level logic in one place
Browse files Browse the repository at this point in the history
Do not distribute the filtering over several places.

While at it also make it the arguments a bit more readable.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
  • Loading branch information
igaw committed May 7, 2024
1 parent 72032c2 commit 2f1debc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/nvme/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
static nvme_root_t root;

void __attribute__((format(printf, 4, 5)))
__nvme_msg(nvme_root_t r, int lvl,
__nvme_msg(nvme_root_t r, int level,
const char *func, const char *format, ...)
{
FILE *fp = stderr;
Expand All @@ -56,9 +56,9 @@ __nvme_msg(nvme_root_t r, int lvl,
if (r)
fp = r->fp;

if (r && lvl > r->log_level)
if (r && level > r->log_level)
return;
if (!r && lvl > DEFAULT_LOGLEVEL)
if (!r && level > DEFAULT_LOGLEVEL)
return;

if (r && r->log_timestamp) {
Expand Down
12 changes: 4 additions & 8 deletions src/nvme/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,10 @@ void *__nvme_realloc(void *p, size_t len);
#endif

void __attribute__((format(printf, 4, 5)))
__nvme_msg(nvme_root_t r, int lvl, const char *func, const char *format, ...);

#define nvme_msg(r, lvl, format, ...) \
do { \
if ((lvl) <= MAX_LOGLEVEL) \
__nvme_msg(r, lvl, __nvme_log_func, \
format, ##__VA_ARGS__); \
} while (0)
__nvme_msg(nvme_root_t r, int level, const char *func, const char *format, ...);

#define nvme_msg(r, level, format, ...) \
__nvme_msg(r, level, __nvme_log_func, format, ##__VA_ARGS__)

#define root_from_ctrl(c) ((c)->s && (c)->s->h ? (c)->s->h->r : NULL)
#define root_from_ns(n) ((n)->s && (n)->s->h ? (n)->s->h->r : \
Expand Down

0 comments on commit 2f1debc

Please sign in to comment.