summaryrefslogtreecommitdiff
path: root/toxcore/tox.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-08-19 13:07:45 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-08-27 01:16:14 +0100
commit13ae9e9a93a1c02fad9475002c0391b86b7ad7bb (patch)
treea9575d3582c4f40e051c93ae18dded03fdddc432 /toxcore/tox.c
parent1f25fc0ae417bfc47dea4966cb5e43689aa88d5c (diff)
Move logging to a callback.
This removes the global logger (which by the way was deleted when the first tox was killed, so other toxes would then stop logging). Various bits of the code now carry a logger or pass it around. It's a bit less transparent now, but now there is no need to have a global logger, and clients can decide what to log and where.
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r--toxcore/tox.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index b1308d90..4b96afa8 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -126,13 +126,17 @@ void tox_options_free(struct Tox_Options *options)
126 126
127Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) 127Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
128{ 128{
129 if (!logger_get_global())
130 logger_set_global(logger_new(LOGGER_OUTPUT_FILE, LOGGER_LEVEL, "toxcore"));
131
132 Messenger_Options m_options = {0}; 129 Messenger_Options m_options = {0};
133 130
134 _Bool load_savedata_sk = 0, load_savedata_tox = 0; 131 _Bool load_savedata_sk = 0, load_savedata_tox = 0;
135 132
133 Logger *log = logger_new();
134
135 if (log == NULL) {
136 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
137 return NULL;
138 }
139
136 if (options == NULL) { 140 if (options == NULL) {
137 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; 141 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
138 } else { 142 } else {
@@ -210,7 +214,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
210 } 214 }
211 215
212 unsigned int m_error; 216 unsigned int m_error;
213 Messenger *m = new_messenger(&m_options, &m_error); 217 Messenger *m = new_messenger(log, &m_options, &m_error);
214 218
215 if (!new_groupchats(m)) { 219 if (!new_groupchats(m)) {
216 kill_messenger(m); 220 kill_messenger(m);
@@ -245,9 +249,16 @@ void tox_kill(Tox *tox)
245 } 249 }
246 250
247 Messenger *m = tox; 251 Messenger *m = tox;
252 Logger *log = m->log;
248 kill_groupchats(m->group_chat_object); 253 kill_groupchats(m->group_chat_object);
249 kill_messenger(m); 254 kill_messenger(m);
250 logger_kill_global(); 255 logger_kill(log);
256}
257
258void tox_callback_log(Tox *tox, tox_log_cb *function, void *userdata)
259{
260 Messenger *m = tox;
261 m_callback_log(m, (logger_cb *)function, userdata);
251} 262}
252 263
253size_t tox_get_savedata_size(const Tox *tox) 264size_t tox_get_savedata_size(const Tox *tox)