summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c18
-rw-r--r--toxcore/logger.c9
-rw-r--r--toxcore/logger.h4
3 files changed, 18 insertions, 13 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 4a24ae5f..2408c844 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1977,26 +1977,24 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
1977 return nullptr; 1977 return nullptr;
1978 } 1978 }
1979 1979
1980 Logger *log = nullptr; 1980 m->log = logger_new();
1981 1981
1982 if (options->log_callback) { 1982 if (m->log == nullptr) {
1983 log = logger_new(); 1983 friendreq_kill(m->fr);
1984 1984 free(m);
1985 if (log != nullptr) { 1985 return nullptr;
1986 logger_callback_log(log, options->log_callback, m, options->log_user_data);
1987 }
1988 } 1986 }
1989 1987
1990 m->log = log; 1988 logger_callback_log(m->log, options->log_callback, m, options->log_user_data);
1991 1989
1992 unsigned int net_err = 0; 1990 unsigned int net_err = 0;
1993 1991
1994 if (options->udp_disabled) { 1992 if (options->udp_disabled) {
1995 m->net = new_networking_no_udp(log); 1993 m->net = new_networking_no_udp(m->log);
1996 } else { 1994 } else {
1997 IP ip; 1995 IP ip;
1998 ip_init(&ip, options->ipv6enabled); 1996 ip_init(&ip, options->ipv6enabled);
1999 m->net = new_networking_ex(log, ip, options->port_range[0], options->port_range[1], &net_err); 1997 m->net = new_networking_ex(m->log, ip, options->port_range[0], options->port_range[1], &net_err);
2000 } 1998 }
2001 1999
2002 if (m->net == nullptr) { 2000 if (m->net == nullptr) {
diff --git a/toxcore/logger.c b/toxcore/logger.c
index 80195e93..ff34f994 100644
--- a/toxcore/logger.c
+++ b/toxcore/logger.c
@@ -27,6 +27,7 @@
27 27
28#include "logger.h" 28#include "logger.h"
29 29
30#include <assert.h>
30#include <stdarg.h> 31#include <stdarg.h>
31#include <stdio.h> 32#include <stdio.h>
32#include <stdlib.h> 33#include <stdlib.h>
@@ -38,7 +39,7 @@ struct Logger {
38 void *userdata; 39 void *userdata;
39}; 40};
40 41
41 42#ifdef USE_STDERR_LOGGER
42static const char *logger_level_name(LOGGER_LEVEL level) 43static const char *logger_level_name(LOGGER_LEVEL level)
43{ 44{
44 switch (level) { 45 switch (level) {
@@ -73,7 +74,7 @@ static const Logger logger_stderr = {
73 nullptr, 74 nullptr,
74 nullptr, 75 nullptr,
75}; 76};
76 77#endif
77 78
78/** 79/**
79 * Public Functions 80 * Public Functions
@@ -99,7 +100,11 @@ void logger_write(const Logger *log, LOGGER_LEVEL level, const char *file, int l
99 const char *format, ...) 100 const char *format, ...)
100{ 101{
101 if (!log) { 102 if (!log) {
103#ifdef USE_STDERR_LOGGER
102 log = &logger_stderr; 104 log = &logger_stderr;
105#else
106 assert(!"NULL logger not permitted");
107#endif
103 } 108 }
104 109
105 if (!log->callback) { 110 if (!log->callback) {
diff --git a/toxcore/logger.h b/toxcore/logger.h
index 2a6ee2ed..acd21fb8 100644
--- a/toxcore/logger.h
+++ b/toxcore/logger.h
@@ -67,7 +67,9 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void *
67 * If the logger is NULL, this writes to stderr. This behaviour should not be 67 * If the logger is NULL, this writes to stderr. This behaviour should not be
68 * used in production code, but can be useful for temporarily debugging a 68 * used in production code, but can be useful for temporarily debugging a
69 * function that does not have a logger available. It's essentially 69 * function that does not have a logger available. It's essentially
70 * fprintf(stderr, ...), but with timestamps and source location. 70 * fprintf(stderr, ...), but with timestamps and source location. Toxcore must
71 * be built with -DUSE_STDERR_LOGGER for this to work. It will cause an
72 * assertion failure otherwise.
71 */ 73 */
72void logger_write( 74void logger_write(
73 const Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, 75 const Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func,