1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 09:33:25 +01:00

some logging code cleanup

This commit is contained in:
jfreegman 2022-03-06 14:51:49 -05:00
parent df77dbfeae
commit 7c799b0b60
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 35 additions and 10 deletions

View File

@ -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;
}

View File

@ -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 "<invalid>";
}
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. */