Skip to content

Commit

Permalink
[libknet] logging: add handle information in log structure
Browse files Browse the repository at this point in the history
Use case: an app is using the same fd to gather logs from
multiple knet_h, the app might still require to know which
knet_h has generated the log for better logging purposes.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Dec 20, 2018
1 parent 9e94898 commit a4a709c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions libknet/libknet.h
Expand Up @@ -1921,6 +1921,7 @@ struct knet_log_msg {
char msg[KNET_MAX_LOG_MSG_SIZE];
uint8_t subsystem; /* KNET_SUB_* */
uint8_t msglevel; /* KNET_LOG_* */
knet_handle_t knet_h; /* pointer to the handle generating the log */
};

/**
Expand Down
1 change: 1 addition & 0 deletions libknet/logging.c
Expand Up @@ -221,6 +221,7 @@ void log_msg(knet_handle_t knet_h, uint8_t subsystem, uint8_t msglevel,
memset(&msg, 0, sizeof(struct knet_log_msg));
msg.subsystem = subsystem;
msg.msglevel = msglevel;
msg.knet_h = knet_h;

va_start(ap, fmt);
#ifdef __clang__
Expand Down
9 changes: 9 additions & 0 deletions libknet/tests/test-common.c
Expand Up @@ -233,6 +233,15 @@ void flush_logs(int logfd, FILE *std)
bytes_read += len;
}

if (!msg.knet_h) {
/*
* this is harsh but this function is void
* and it is used also inside log_thread.
* this is the easiest to get out with an error
*/
fprintf(std, "NO HANDLE INFO IN LOG MSG!!\n");
abort();
}
fprintf(std, "[knet]: [%s] %s: %.*s\n",
knet_log_get_loglevel_name(msg.msglevel),
knet_log_get_subsystem_name(msg.subsystem),
Expand Down

0 comments on commit a4a709c

Please sign in to comment.