Skip to content

Commit

Permalink
logging: move string to the beginning of msg
Browse files Browse the repository at this point in the history
this allow (to some extents) to print log messages directly to
stdout and/or stderr without extra parsing.

NOTE:
- messages are sent from differnet threads and there for they are less readable
  when they arrive all together
- there is no printing of message level and subsystem

for simple coding/debugging purposes this is useful, but otherwise
look at how ping_test.c or kronosnetd create a logpipe and read
sequencial messages from there.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Jan 8, 2013
1 parent 036b5aa commit 6abcf82
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ libknet:
- (issue) review locking handling policies (attempt locks vs deadlocks and so on)
almost done, needs knet_link_* bits done
- (issue) add .3 man pages
- (issue) fix logging packet format to allow direct output to a fd
(change packet structure to have string first basically)

libtap:
- (rfe) consider adding dhcp support for tap device
Expand Down
2 changes: 1 addition & 1 deletion libknet/libknet.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,9 @@ int knet_link_get_status(knet_handle_t knet_h,
#define KNET_MAX_LOG_MSG_SIZE 256

struct knet_log_msg {
char msg[KNET_MAX_LOG_MSG_SIZE - (sizeof(uint8_t)*2)];
uint8_t subsystem; /* KNET_SUB_* */
uint8_t msglevel; /* KNET_LOG_* */
char msg[KNET_MAX_LOG_MSG_SIZE - (sizeof(uint8_t)*2)];
};

void knet_set_log_level(knet_handle_t knet_h, uint8_t subsystem, uint8_t level);
Expand Down
2 changes: 2 additions & 0 deletions libknet/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "config.h"

#include <strings.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <stdarg.h>
Expand Down Expand Up @@ -117,6 +118,7 @@ void log_msg(knet_handle_t knet_h, uint8_t subsystem, uint8_t msglevel,
(msglevel > knet_h->log_levels[subsystem]))
return;

memset(&msg, 0, sizeof(struct knet_log_msg));
msg.subsystem = subsystem;
msg.msglevel = msglevel;

Expand Down

0 comments on commit 6abcf82

Please sign in to comment.