From deb82006e5532693c07726e2eaedcc38c7bc050d Mon Sep 17 00:00:00 2001 From: cotox <39076296+cotox@users.noreply.github.com> Date: Mon, 21 May 2018 17:39:36 +0000 Subject: [PATCH] Feature bootstrap trace/debug log output Don't know why codes with macro dosen't work. As it's only a few expensive, just code it without macro for now. \#if (MIN_LOGGER_LEVEL == LOG_TRACE) || (MIN_LOGGER_LEVEL == LOG_DEBUG) fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message); \#endif --- other/DHT_bootstrap.c | 39 +++++++++++++++++++++ other/bootstrap_daemon/src/tox-bootstrapd.c | 39 +++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index ddec0d7b..637cb442 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -94,6 +94,40 @@ static void manage_keys(DHT *dht) fclose(keys_file); } +static void print_log(void *context, Logger_Level level, const char *file, int line, + const char *func, const char *message, void *userdata) +{ + char *strlevel; + + switch (level) { + case LOGGER_LEVEL_TRACE: + strlevel = "TRACE"; + break; + + case LOGGER_LEVEL_DEBUG: + strlevel = "DEBUG"; + break; + + case LOGGER_LEVEL_INFO: + strlevel = "INFO"; + break; + + case LOGGER_LEVEL_WARNING: + strlevel = "WARNING"; + break; + + case LOGGER_LEVEL_ERROR: + strlevel = "ERROR"; + break; + + default: + strlevel = ""; + break; + } + + fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message); +} + int main(int argc, char *argv[]) { if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) { @@ -116,6 +150,11 @@ int main(int argc, char *argv[]) ip_init(&ip, ipv6enabled); Logger *logger = logger_new(); + + if (MIN_LOGGER_LEVEL == LOGGER_LEVEL_TRACE || MIN_LOGGER_LEVEL == LOGGER_LEVEL_DEBUG) { + logger_callback_log(logger, print_log, nullptr, nullptr); + } + Mono_Time *mono_time = mono_time_new(); DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true); Onion *onion = new_onion(mono_time, dht); diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 0c18e05a..45c378f6 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -178,6 +178,44 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path) } } +void print_log(void *context, LOGGER_LEVEL level, const char *file, int line, + const char *func, const char *message, void *userdata) +{ + if (MIN_LOGGER_LEVEL != LOG_TRACE && MIN_LOGGER_LEVEL != LOG_DEBUG) { + return; + } + + char *strlevel; + + switch (level) { + case LOG_TRACE: + strlevel = "TRACE"; + break; + + case LOG_DEBUG: + strlevel = "DEBUG"; + break; + + case LOG_INFO: + strlevel = "INFO"; + break; + + case LOG_WARNING: + strlevel = "WARNING"; + break; + + case LOG_ERROR: + strlevel = "ERROR"; + break; + + default: + strlevel = ""; + break; + } + + fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message); +} + int main(int argc, char *argv[]) { umask(077); @@ -231,6 +269,7 @@ int main(int argc, char *argv[]) ip_init(&ip, enable_ipv6); Logger *logger = logger_new(); + logger_callback_log(logger, print_log, nullptr, nullptr); Networking_Core *net = new_networking(logger, ip, port);