From 2e4cae692e0895ce17e67fb2e1fd899c91fcb675 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Thu, 28 Jun 2018 21:01:13 -0400 Subject: [PATCH] Use our own logging facility to log toxcore's logs --- other/DHT_bootstrap.c | 2 +- other/bootstrap_daemon/src/tox-bootstrapd.c | 41 +++++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 637cb442..9cbcca62 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -97,7 +97,7 @@ static void manage_keys(DHT *dht) static void print_log(void *context, Logger_Level level, const char *file, int line, const char *func, const char *message, void *userdata) { - char *strlevel; + const char *strlevel; switch (level) { case LOGGER_LEVEL_TRACE: diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 45c378f6..c26ef54f 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -178,42 +178,40 @@ 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; - } +// Logs toxcore logger message using our logger facility - char *strlevel; +static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, int line, + const char *func, const char *message, void *userdata) +{ + LOG_LEVEL log_level; switch (level) { - case LOG_TRACE: - strlevel = "TRACE"; + case LOGGER_LEVEL_TRACE: + log_level = LOG_LEVEL_INFO; break; - case LOG_DEBUG: - strlevel = "DEBUG"; + case LOGGER_LEVEL_DEBUG: + log_level = LOG_LEVEL_INFO; break; - case LOG_INFO: - strlevel = "INFO"; + case LOGGER_LEVEL_INFO: + log_level = LOG_LEVEL_INFO; break; - case LOG_WARNING: - strlevel = "WARNING"; + case LOGGER_LEVEL_WARNING: + log_level = LOG_LEVEL_WARNING; break; - case LOG_ERROR: - strlevel = "ERROR"; + case LOGGER_LEVEL_ERROR: + log_level = LOG_LEVEL_ERROR; break; default: - strlevel = ""; + log_level = LOG_LEVEL_INFO; break; } - fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message); + log_write(log_level, "%s:%d(%s) %s\n", file, line, func, message); } int main(int argc, char *argv[]) @@ -269,7 +267,10 @@ int main(int argc, char *argv[]) ip_init(&ip, enable_ipv6); Logger *logger = logger_new(); - logger_callback_log(logger, print_log, nullptr, nullptr); + + if (MIN_LOGGER_LEVEL == LOGGER_LEVEL_TRACE || MIN_LOGGER_LEVEL == LOGGER_LEVEL_DEBUG) { + logger_callback_log(logger, toxcore_logger_callback, nullptr, nullptr); + } Networking_Core *net = new_networking(logger, ip, port);