Permalink
Browse files

logging: start documenting API and other bits

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information...
1 parent 95db93a commit f4e6edd4c3fcd1ce38b5e15070508fdd2924ff8e @fabbione committed Jan 29, 2013
Showing with 70 additions and 15 deletions.
  1. +4 −4 kronosnetd/vty.c
  2. +60 −5 libknet/libknet.h
  3. +4 −4 libknet/logging.c
  4. +2 −2 libknet/ping_test.c
View
8 kronosnetd/vty.c
@@ -114,17 +114,17 @@ static void *_handle_logging_thread(void *data)
switch(msg.msglevel) {
case KNET_LOG_WARN:
- log_warn("(%s) %s", knet_get_subsystem_name(msg.subsystem), msg.msg);
+ log_warn("(%s) %s", knet_log_get_subsystem_name(msg.subsystem), msg.msg);
break;
case KNET_LOG_INFO:
- log_info("(%s) %s", knet_get_subsystem_name(msg.subsystem), msg.msg);
+ log_info("(%s) %s", knet_log_get_subsystem_name(msg.subsystem), msg.msg);
break;
case KNET_LOG_DEBUG:
- log_kdebug("(%s) %s", knet_get_subsystem_name(msg.subsystem), msg.msg);
+ log_kdebug("(%s) %s", knet_log_get_subsystem_name(msg.subsystem), msg.msg);
break;
case KNET_LOG_ERR:
default:
- log_error("(%s) %s", knet_get_subsystem_name(msg.subsystem), msg.msg);
+ log_error("(%s) %s", knet_log_get_subsystem_name(msg.subsystem), msg.msg);
}
}
}
View
65 libknet/libknet.h
@@ -681,7 +681,15 @@ struct knet_link_status {
int knet_link_get_status(knet_handle_t knet_h, uint16_t host_id, uint8_t link_id,
struct knet_link_status *status);
-/* logging */
+/*
+ * logging structs/API calls
+ */
+
+/*
+ * libknet is composed of several subsystems. In order
+ * to easily distinguish log messages coming from different
+ * places, each subsystem has its own ID.
+ */
#define KNET_SUB_COMMON 0 /* common.c */
#define KNET_SUB_HANDLE 1 /* handle.c alloc/dealloc config changes */
@@ -698,11 +706,62 @@ int knet_link_get_status(knet_handle_t knet_h, uint16_t host_id, uint8_t link_id
#define KNET_SUB_LAST KNET_SUB_NSSCRYPTO
#define KNET_MAX_SUBSYSTEMS KNET_SUB_LAST + 1
+/*
+ * Convert between subsystem IDs and names
+ */
+
+/*
+ * knet_log_get_subsystem_name
+ *
+ * return internal name of the subsystem or "unknown"
+ */
+
+const char *knet_log_get_subsystem_name(uint8_t subsystem);
+
+/*
+ * knet_log_get_subsystem_id
+ *
+ * return internal ID of the subsystem or KNET_SUB_COMMON
+ */
+
+uint8_t knet_log_get_subsystem_id(const char *name);
+
+/*
+ * 4 log levels are enough for everybody
+ */
+
#define KNET_LOG_ERR 0 /* unrecoverable errors/conditions */
#define KNET_LOG_WARN 1 /* recoverable errors/conditions */
#define KNET_LOG_INFO 2 /* info, link up/down, config changes.. */
#define KNET_LOG_DEBUG 3
+/*
+ * Convert between log level values and names
+ */
+
+/*
+ * knet_log_get_loglevel_name
+ *
+ * return internal name of the log level or "unknown"
+ */
+
+const char *knet_log_get_loglevel_name(uint8_t level);
+
+/*
+ * knet_log_get_loglevel_id
+ *
+ * return internal ID of the subsystem or KNET_SUB_COMMON
+ */
+
+uint8_t knet_log_get_loglevel_id(const char *name);
+
+/*
+ * every log message is composed by a text message (including a trailing \n)
+ * and message level/subsystem IDs.
+ * In order to make debugging easier it is possible to send those packets
+ * straight to stdout/stderr (see ping_test.c stdout option).
+ */
+
#define KNET_MAX_LOG_MSG_SIZE 256
struct knet_log_msg {
@@ -712,9 +771,5 @@ struct knet_log_msg {
};
void knet_set_log_level(knet_handle_t knet_h, uint8_t subsystem, uint8_t level);
-const char *knet_get_subsystem_name(uint8_t subsystem);
-const char *knet_get_loglevel_name(uint8_t level);
-uint8_t knet_get_subsystem_id(const char *name);
-uint8_t knet_get_loglevel_id(const char *name);
#endif
View
8 libknet/logging.c
@@ -40,7 +40,7 @@ static struct pretty_names subsystem_names[] =
{ "nsscrypto", KNET_SUB_NSSCRYPTO }
};
-const char *knet_get_subsystem_name(uint8_t subsystem)
+const char *knet_log_get_subsystem_name(uint8_t subsystem)
{
unsigned int i;
@@ -52,7 +52,7 @@ const char *knet_get_subsystem_name(uint8_t subsystem)
return "unknown";
}
-uint8_t knet_get_subsystem_id(const char *name)
+uint8_t knet_log_get_subsystem_id(const char *name)
{
unsigned int i;
@@ -72,7 +72,7 @@ static struct pretty_names loglevel_names[] =
{ "debug", KNET_LOG_DEBUG }
};
-const char *knet_get_loglevel_name(uint8_t level)
+const char *knet_log_get_loglevel_name(uint8_t level)
{
unsigned int i;
@@ -84,7 +84,7 @@ const char *knet_get_loglevel_name(uint8_t level)
return "unknown";
}
-uint8_t knet_get_loglevel_id(const char *name)
+uint8_t knet_log_get_loglevel_id(const char *name)
{
unsigned int i;
View
4 libknet/ping_test.c
@@ -372,8 +372,8 @@ int main(int argc, char *argv[])
}
printf("[%s] %s: %s\n",
- knet_get_loglevel_name(msg.msglevel),
- knet_get_subsystem_name(msg.subsystem),
+ knet_log_get_loglevel_name(msg.msglevel),
+ knet_log_get_subsystem_name(msg.subsystem),
msg.msg);
}

0 comments on commit f4e6edd

Please sign in to comment.