diff --git a/include/villas/log.h b/include/villas/log.h index c57d686bf..dbd7bda46 100644 --- a/include/villas/log.h +++ b/include/villas/log.h @@ -32,22 +32,25 @@ * * To be or-ed with the debug level */ -enum debug_facilities { - DBG_POOL = (1 << 8), - DBG_QUEUE = (1 << 9), - DBG_CONFIG = (1 << 10), - DBG_HOOK = (1 << 11), - DBG_PATH = (1 << 12), - DBG_MEM = (1 << 13), +enum log_facilities { + LOG_POOL = (1 << 8), + LOG_QUEUE = (1 << 9), + LOG_CONFIG = (1 << 10), + LOG_HOOK = (1 << 11), + LOG_PATH = (1 << 12), + LOG_MEM = (1 << 13), /* Node-types */ - DBG_SOCKET = (1 << 16), - DBG_FILE = (1 << 17), - DBG_FPGA = (1 << 18), - DBG_NGSI = (1 << 19), - DBG_WEBSOCKET = (1 << 20), - DBG_OPAL = (1 << 21), - DBG_NODE = (0xFF << 16) + LOG_SOCKET = (1 << 16), + LOG_FILE = (1 << 17), + LOG_FPGA = (1 << 18), + LOG_NGSI = (1 << 19), + LOG_WEBSOCKET = (1 << 20), + LOG_OPAL = (1 << 21), + + /* Classes */ + LOG_NODE = (0xFF << 16), + LOG_ALL = ~0xFF }; /** Change log indention for current thread. diff --git a/lib/hooks.c b/lib/hooks.c index ea4745e80..2e88e2813 100644 --- a/lib/hooks.c +++ b/lib/hooks.c @@ -42,7 +42,7 @@ int hook_run(struct path *p, struct sample *smps[], size_t cnt, int when) { list_foreach(struct hook *h, &p->hooks) { if (h->type & when) { - debug(DBG_HOOK | 22, "Running hook when=%u '%s' prio=%u, cnt=%zu", when, h->name, h->priority, cnt); + debug(LOG_HOOK | 22, "Running hook when=%u '%s' prio=%u, cnt=%zu", when, h->name, h->priority, cnt); cnt = h->cb(p, h, when, smps, cnt); if (cnt == 0) diff --git a/lib/kernel/if.c b/lib/kernel/if.c index 3a859304c..767831992 100644 --- a/lib/kernel/if.c +++ b/lib/kernel/if.c @@ -31,7 +31,7 @@ struct interface * if_create(struct rtnl_link *link) i->nl_link = link; - debug(DBG_SOCKET | 3, "Created interface '%s'", rtnl_link_get_name(i->nl_link)); + debug(LOG_SOCKET | 3, "Created interface '%s'", rtnl_link_get_name(i->nl_link)); int n = if_get_irqs(i); if (n > 0) @@ -94,7 +94,7 @@ int if_start(struct interface *i, int affinity) error("Failed to setup FW mark classifier: %s", nl_geterror(ret)); char *buf = tc_print(s->tc_qdisc); - debug(DBG_SOCKET | 5, "Starting network emulation on interface '%s' for FW mark %u: %s", + debug(LOG_SOCKET | 5, "Starting network emulation on interface '%s' for FW mark %u: %s", rtnl_link_get_name(i->nl_link), s->mark, buf); free(buf); @@ -195,7 +195,7 @@ int if_set_affinity(struct interface *i, int affinity) error("Failed to set affinity for IRQ %u", i->irqs[n]); fclose(file); - debug(DBG_SOCKET | 5, "Set affinity of IRQ %u for interface '%s' to %#x", i->irqs[n], rtnl_link_get_name(i->nl_link), affinity); + debug(LOG_SOCKET | 5, "Set affinity of IRQ %u for interface '%s' to %#x", i->irqs[n], rtnl_link_get_name(i->nl_link), affinity); } else error("Failed to set affinity for interface '%s'", rtnl_link_get_name(i->nl_link)); diff --git a/lib/memory.c b/lib/memory.c index 2f46161b3..da16d54d1 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -19,20 +19,20 @@ void * memory_alloc(const struct memtype *m, size_t len) { - debug(DBG_MEM | 2, "Allocating %#zx bytes of %s memory", len, m->name); + debug(LOG_MEM | 2, "Allocating %#zx bytes of %s memory", len, m->name); return m->alloc(len); } void * memory_alloc_aligned(const struct memtype *m, size_t len, size_t alignment) { - debug(DBG_MEM | 2, "Allocating %#zx bytes of %#zx-byte-aligned %s memory", len, alignment, m->name); + debug(LOG_MEM | 2, "Allocating %#zx bytes of %#zx-byte-aligned %s memory", len, alignment, m->name); warn("%s: not implemented yet!", __FUNCTION__); return memory_alloc(m, len); } int memory_free(const struct memtype *m, void *ptr, size_t len) { - debug(DBG_MEM | 2, "Releasing %#zx bytes of %s memory", len, m->name); + debug(LOG_MEM | 2, "Releasing %#zx bytes of %s memory", len, m->name); return m->free(ptr, len); } diff --git a/lib/nodes/ngsi.c b/lib/nodes/ngsi.c index 4eb0c9ddd..48f2abb2b 100644 --- a/lib/nodes/ngsi.c +++ b/lib/nodes/ngsi.c @@ -287,7 +287,7 @@ static int ngsi_request(CURL *handle, const char *endpoint, const char *operatio curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, strlen(post)); curl_easy_setopt(handle, CURLOPT_POSTFIELDS, post); - debug(DBG_NGSI | 18, "Request to context broker: %s\n%s", url, post); + debug(LOG_NGSI | 18, "Request to context broker: %s\n%s", url, post); /* We don't want to leave the handle in an invalid state */ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old); @@ -301,8 +301,8 @@ static int ngsi_request(CURL *handle, const char *endpoint, const char *operatio curl_easy_getinfo(handle, CURLINFO_TOTAL_TIME, &time); - debug(DBG_NGSI | 16, "Request to context broker completed in %.4f seconds", time); - debug(DBG_NGSI | 17, "Response from context broker:\n%s", chunk.data); + debug(LOG_NGSI | 16, "Request to context broker completed in %.4f seconds", time); + debug(LOG_NGSI | 17, "Response from context broker:\n%s", chunk.data); *response = json_loads(chunk.data, 0, &err); if (!*response) diff --git a/lib/nodes/opal.c b/lib/nodes/opal.c index 86b891faf..396224743 100644 --- a/lib/nodes/opal.c +++ b/lib/nodes/opal.c @@ -88,7 +88,7 @@ int opal_deinit() if (err != EOK) error("Failed to close shared memory area (%d)", err); - debug(DBG_OPAL | 4, "Closing OPAL shared memory mapping"); + debug(LOG_OPAL | 4, "Closing OPAL shared memory mapping"); err = OpalSystemCtrl_UnRegister(print_shmem_name); if (err != EOK) @@ -104,7 +104,7 @@ int opal_deinit() int opal_print_global() { - debug(DBG_OPAL | 2, "Controller ID: %u", params.controllerID); + debug(LOG_OPAL | 2, "Controller ID: %u", params.controllerID); char *sbuf = alloc(send_icons * 5); char *rbuf = alloc(recv_icons * 5); @@ -114,17 +114,17 @@ int opal_print_global() for (int i = 0; i < recv_icons; i++) strcatf(&rbuf, "%u ", recv_ids[i]); - debug(DBG_OPAL | 2, "Send Blocks: %s", sbuf); - debug(DBG_OPAL | 2, "Receive Blocks: %s", rbuf); + debug(LOG_OPAL | 2, "Send Blocks: %s", sbuf); + debug(LOG_OPAL | 2, "Receive Blocks: %s", rbuf); free(sbuf); free(rbuf); - debug(DBG_OPAL | 2, "Control Block Parameters:"); + debug(LOG_OPAL | 2, "Control Block Parameters:"); for (int i = 0; i < GENASYNC_NB_FLOAT_PARAM; i++) - debug(DBG_OPAL | 2, "FloatParam[]%u] = %f", i, params.FloatParam[i]); + debug(LOG_OPAL | 2, "FloatParam[]%u] = %f", i, params.FloatParam[i]); for (int i = 0; i < GENASYNC_NB_STRING_PARAM; i++) - debug(DBG_OPAL | 2, "StringParam[%u] = %s", i, params.StringParam[i]); + debug(LOG_OPAL | 2, "StringParam[%u] = %s", i, params.StringParam[i]); return 0; } diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 000fc123a..14771e6f8 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -165,7 +165,7 @@ int socket_open(struct node *n) if (ret) serror("Failed to set FW mark for outgoing packets"); else - debug(DBG_SOCKET | 4, "Set FW mark for socket (sd=%u) to %u", s->sd, s->mark); + debug(LOG_SOCKET | 4, "Set FW mark for socket (sd=%u) to %u", s->sd, s->mark); } /* Set socket priority, QoS or TOS IP options */ @@ -177,7 +177,7 @@ int socket_open(struct node *n) if (setsockopt(s->sd, IPPROTO_IP, IP_TOS, &prio, sizeof(prio))) serror("Failed to set type of service (QoS)"); else - debug(DBG_SOCKET | 4, "Set QoS/TOS IP option for node %s to %#x", node_name(n), prio); + debug(LOG_SOCKET | 4, "Set QoS/TOS IP option for node %s to %#x", node_name(n), prio); break; default: @@ -185,7 +185,7 @@ int socket_open(struct node *n) if (setsockopt(s->sd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio))) serror("Failed to set socket priority"); else - debug(DBG_SOCKET | 4, "Set socket priority for node %s to %d", node_name(n), prio); + debug(LOG_SOCKET | 4, "Set socket priority for node %s to %d", node_name(n), prio); break; } @@ -388,7 +388,7 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt) } } - debug(DBG_SOCKET | 17, "Received message of %zd bytes: %u samples", bytes, received); + debug(LOG_SOCKET | 17, "Received message of %zd bytes: %u samples", bytes, received); return received; } @@ -430,7 +430,7 @@ int socket_write(struct node *n, struct sample *smps[], unsigned cnt) sent++; - debug(DBG_SOCKET | 17, "Sent packet of %zd bytes with 1 sample", bytes); + debug(LOG_SOCKET | 17, "Sent packet of %zd bytes with 1 sample", bytes); } } else { @@ -464,7 +464,7 @@ int socket_write(struct node *n, struct sample *smps[], unsigned cnt) sent = cnt; /** @todo Find better way to determine how many values we actually sent */ - debug(DBG_SOCKET | 17, "Sent packet of %zd bytes with %u samples", bytes, cnt); + debug(LOG_SOCKET | 17, "Sent packet of %zd bytes with %u samples", bytes, cnt); } return sent; diff --git a/lib/path.c b/lib/path.c index 69667cbcc..a1693f2b1 100644 --- a/lib/path.c +++ b/lib/path.c @@ -43,7 +43,7 @@ static void path_write(struct path *p, bool resend) else if (sent < tosend) warn("Partial write to node %s", node_name(n)); - debug(DBG_PATH | 15, "Sent %u messages to node %s", sent, node_name(n)); + debug(LOG_PATH | 15, "Sent %u messages to node %s", sent, node_name(n)); released = pool_put_many(&p->pool, (void **) smps, sent); if (sent != released) @@ -99,7 +99,7 @@ static void * path_run(void *arg) else if (recv < ready) warn("Partial read for path %s: read=%u expected=%u", path_name(p), recv, ready); - debug(DBG_PATH | 15, "Received %u messages from node %s", recv, node_name(p->in)); + debug(LOG_PATH | 15, "Received %u messages from node %s", recv, node_name(p->in)); /* Run preprocessing hooks for vector of samples */ enqueue = hook_run(p, smps, recv, HOOK_READ); @@ -114,7 +114,7 @@ static void * path_run(void *arg) ready -= enqueued; - debug(DBG_PATH | 3, "Enqueuing %u samples to queue of path %s", enqueue, path_name(p)); + debug(LOG_PATH | 3, "Enqueuing %u samples to queue of path %s", enqueue, path_name(p)); /* At fixed rate mode, messages are send by another (asynchronous) thread */ if (p->rate == 0) diff --git a/lib/pool.c b/lib/pool.c index 955b8b77a..d84f24c81 100644 --- a/lib/pool.c +++ b/lib/pool.c @@ -26,7 +26,7 @@ int pool_init(struct pool *p, size_t cnt, size_t blocksz, const struct memtype * if (!p->buffer) serror("Failed to allocate memory for memory pool"); else - debug(DBG_POOL | 4, "Allocated %#zx bytes for memory pool", p->len); + debug(LOG_POOL | 4, "Allocated %#zx bytes for memory pool", p->len); ret = queue_init(&p->queue, cnt, m); if (ret)