From: Niklas Hofmann Date: Sat, 9 Aug 2014 12:49:53 +0000 (+0200) Subject: route avahi log to meshlink log X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=5ae4edd8e422fb1b184fb5cbd6c48de0c048c7b8;p=meshlink route avahi log to meshlink log --- diff --git a/src/discovery.c b/src/discovery.c index cf1dd5e2..b50aea8d 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -400,6 +401,33 @@ static void *discovery_loop(void *userdata) return NULL; } +static void discovery_log_cb(AvahiLogLevel level, const char *txt) +{ + meshlink_log_level_t mlevel = MESHLINK_CRITICAL; + + switch(level) + { + case AVAHI_LOG_ERROR: + mlevel = MESHLINK_ERROR; + break; + + case AVAHI_LOG_WARN: + mlevel = MESHLINK_WARNING; + break; + + case AVAHI_LOG_NOTICE: + case AVAHI_LOG_INFO: + mlevel = MESHLINK_INFO; + break; + + case AVAHI_LOG_DEBUG: + mlevel = MESHLINK_DEBUG; + break; + } + + logger(NULL, mlevel, "%s\n", txt); +} + bool discovery_start(meshlink_handle_t *mesh) { logger(mesh, MESHLINK_DEBUG, "discovery_start called\n"); @@ -412,6 +440,9 @@ bool discovery_start(meshlink_handle_t *mesh) assert(mesh->discovery_threadstarted == false); assert(mesh->avahi_servicetype == NULL); + // handle avahi logs + avahi_set_log_function(discovery_log_cb); + // create service type string size_t servicetype_strlen = sizeof(MESHLINK_MDNS_SERVICE_TYPE) + strlen(mesh->appname) + 1; mesh->avahi_servicetype = malloc(servicetype_strlen);