From deb82006e5532693c07726e2eaedcc38c7bc050d Mon Sep 17 00:00:00 2001 From: cotox <39076296+cotox@users.noreply.github.com> Date: Mon, 21 May 2018 17:39:36 +0000 Subject: 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 --- other/bootstrap_daemon/src/tox-bootstrapd.c | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'other/bootstrap_daemon/src/tox-bootstrapd.c') diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 0c18e05a..45c378f6 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -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 = ""; + break; + } + + fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message); +} + int main(int argc, char *argv[]) { umask(077); @@ -231,6 +269,7 @@ int main(int argc, char *argv[]) ip_init(&ip, enable_ipv6); Logger *logger = logger_new(); + logger_callback_log(logger, print_log, nullptr, nullptr); Networking_Core *net = new_networking(logger, ip, port); -- cgit v1.2.3