mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 20:13:04 +01:00
some logging code cleanup
This commit is contained in:
parent
df77dbfeae
commit
7c799b0b60
@ -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;
|
||||
}
|
||||
|
41
src/toxic.c
41
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 "<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. */
|
||||
|
Loading…
Reference in New Issue
Block a user