diff options
author | cotox <39076296+cotox@users.noreply.github.com> | 2018-05-21 17:39:36 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-30 22:44:18 +0000 |
commit | deb82006e5532693c07726e2eaedcc38c7bc050d (patch) | |
tree | 1337f000bfda1d101dfd91763c9b98d0600d4328 /other/DHT_bootstrap.c | |
parent | 36f0caaf072128623a4c70e6a614721249bb4c6b (diff) |
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
Diffstat (limited to 'other/DHT_bootstrap.c')
-rw-r--r-- | other/DHT_bootstrap.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index ddec0d7b..637cb442 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -94,6 +94,40 @@ static void manage_keys(DHT *dht) | |||
94 | fclose(keys_file); | 94 | fclose(keys_file); |
95 | } | 95 | } |
96 | 96 | ||
97 | static void print_log(void *context, Logger_Level level, const char *file, int line, | ||
98 | const char *func, const char *message, void *userdata) | ||
99 | { | ||
100 | char *strlevel; | ||
101 | |||
102 | switch (level) { | ||
103 | case LOGGER_LEVEL_TRACE: | ||
104 | strlevel = "TRACE"; | ||
105 | break; | ||
106 | |||
107 | case LOGGER_LEVEL_DEBUG: | ||
108 | strlevel = "DEBUG"; | ||
109 | break; | ||
110 | |||
111 | case LOGGER_LEVEL_INFO: | ||
112 | strlevel = "INFO"; | ||
113 | break; | ||
114 | |||
115 | case LOGGER_LEVEL_WARNING: | ||
116 | strlevel = "WARNING"; | ||
117 | break; | ||
118 | |||
119 | case LOGGER_LEVEL_ERROR: | ||
120 | strlevel = "ERROR"; | ||
121 | break; | ||
122 | |||
123 | default: | ||
124 | strlevel = "<unknown>"; | ||
125 | break; | ||
126 | } | ||
127 | |||
128 | fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message); | ||
129 | } | ||
130 | |||
97 | int main(int argc, char *argv[]) | 131 | int main(int argc, char *argv[]) |
98 | { | 132 | { |
99 | if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) { | 133 | if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) { |
@@ -116,6 +150,11 @@ int main(int argc, char *argv[]) | |||
116 | ip_init(&ip, ipv6enabled); | 150 | ip_init(&ip, ipv6enabled); |
117 | 151 | ||
118 | Logger *logger = logger_new(); | 152 | Logger *logger = logger_new(); |
153 | |||
154 | if (MIN_LOGGER_LEVEL == LOGGER_LEVEL_TRACE || MIN_LOGGER_LEVEL == LOGGER_LEVEL_DEBUG) { | ||
155 | logger_callback_log(logger, print_log, nullptr, nullptr); | ||
156 | } | ||
157 | |||
119 | Mono_Time *mono_time = mono_time_new(); | 158 | Mono_Time *mono_time = mono_time_new(); |
120 | DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true); | 159 | DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true); |
121 | Onion *onion = new_onion(mono_time, dht); | 160 | Onion *onion = new_onion(mono_time, dht); |