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
This commit is contained in:
cotox 2018-05-21 17:39:36 +00:00 committed by iphydf
parent 36f0caaf07
commit deb82006e5
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
2 changed files with 78 additions and 0 deletions

View File

@ -94,6 +94,40 @@ static void manage_keys(DHT *dht)
fclose(keys_file); 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 = "<unknown>";
break;
}
fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) { if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
@ -116,6 +150,11 @@ int main(int argc, char *argv[])
ip_init(&ip, ipv6enabled); ip_init(&ip, ipv6enabled);
Logger *logger = logger_new(); 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(); Mono_Time *mono_time = mono_time_new();
DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true); DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true);
Onion *onion = new_onion(mono_time, dht); Onion *onion = new_onion(mono_time, dht);

View File

@ -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 = "<unknown>";
break;
}
fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
umask(077); umask(077);
@ -231,6 +269,7 @@ int main(int argc, char *argv[])
ip_init(&ip, enable_ipv6); ip_init(&ip, enable_ipv6);
Logger *logger = logger_new(); Logger *logger = logger_new();
logger_callback_log(logger, print_log, nullptr, nullptr);
Networking_Core *net = new_networking(logger, ip, port); Networking_Core *net = new_networking(logger, ip, port);