From 7c799b0b6047a97ee10385c1bc612b28fdff2874 Mon Sep 17 00:00:00 2001 From: jfreegman Date: Sun, 6 Mar 2022 14:51:49 -0500 Subject: [PATCH] some logging code cleanup --- src/bootstrap.c | 4 ++-- src/toxic.c | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/bootstrap.c b/src/bootstrap.c index ec98419..164d8ce 100644 --- a/src/bootstrap.c +++ b/src/bootstrap.c @@ -583,8 +583,7 @@ int load_DHT_nodeslist(void) memcpy(node->ip4, TESTNET_IP, sizeof(TESTNET_IP)); Nodes.count = 1; - return 0; - +#if 0 if (thread_data.active) { return -1; } @@ -607,6 +606,7 @@ int load_DHT_nodeslist(void) thread_data.active = false; return -5; } +#endif return 0; } diff --git a/src/toxic.c b/src/toxic.c index 09d65c0..33a6e8f 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -230,20 +230,45 @@ void exit_toxic_err(const char *errmsg, int errcode) exit(EXIT_FAILURE); } +static const char *tox_log_level_show(Tox_Log_Level level) +{ + switch (level) { + case TOX_LOG_LEVEL_TRACE: + return "TRACE"; + + case TOX_LOG_LEVEL_DEBUG: + return "DEBUG"; + + case TOX_LOG_LEVEL_INFO: + return "INFO"; + + case TOX_LOG_LEVEL_WARNING: + return "WARNING"; + + case TOX_LOG_LEVEL_ERROR: + return "ERROR"; + } + + return ""; +} + void cb_toxcore_logger(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func, const char *message, void *user_data) { - UNUSED_VAR(user_data); - UNUSED_VAR(file); UNUSED_VAR(m); - if (user_data) { - FILE *fp = (FILE *)user_data; - fprintf(fp, "[%d] %u:%s() - %s\n", level, line, func, message); - fflush(fp); - } else { - fprintf(stderr, "[%d] %u:%s() - %s\n", level, line, func, message); + if (level == TOX_LOG_LEVEL_TRACE) { + return; } + + FILE *fp = (FILE *)user_data; + + if (!fp) { + fp = stderr; + } + + fprintf(fp, "[%c] %s:%u(%s) - %s\n", tox_log_level_show(level)[0], file, line, func, message); + fflush(fp); } /* Sets ncurses refresh rate. Lower values make it refresh more often. */