Hook into Tox logs if built without NDEBUG

This also requires libtoxcore to be built with logging enabled.
This commit is contained in:
Håvard Pettersson 2017-02-09 22:04:39 -08:00
parent 4c8c4f598d
commit bf095ecc5b
3 changed files with 51 additions and 0 deletions

View File

@ -208,6 +208,11 @@ twc_profile_set_options(struct Tox_Options *options,
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_UDP);
options->ipv6_enabled =
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_IPV6);
#ifndef NDEBUG
options->log_callback = twc_tox_log_callback;
options->log_user_data = profile;
#endif /* !NDEBUG */
}
void

View File

@ -18,6 +18,7 @@
*/
#include <string.h>
#include <inttypes.h>
#include <weechat/weechat-plugin.h>
#include <tox/tox.h>
@ -515,3 +516,40 @@ twc_group_title_callback(Tox *tox,
free(topic);
}
#ifndef NDEBUG
void
twc_tox_log_callback(Tox *tox,
TOX_LOG_LEVEL level,
const char *file, uint32_t line, const char *func,
const char *message, void *user_data)
{
struct t_twc_profile *const profile = user_data;
char const *color;
switch (level)
{
case TOX_LOG_LEVEL_TRACE:
color = weechat_color("gray");
break;
case TOX_LOG_LEVEL_DEBUG:
color = weechat_color("white");
break;
case TOX_LOG_LEVEL_INFO:
color = weechat_color("lightblue");
break;
case TOX_LOG_LEVEL_WARNING:
color = weechat_color("yellow");
break;
case TOX_LOG_LEVEL_ERROR:
color = weechat_color("red");
break;
default:
color = weechat_color("reset");
}
weechat_printf(profile->buffer, "%stox\t%s%s:%"PRIu32" [%s]%s %s",
color, weechat_color("reset"), file, line, func,
weechat_color("lightred"), message);
}
#endif /* !NDEBUG */

View File

@ -78,5 +78,13 @@ twc_group_title_callback(Tox *tox,
const uint8_t *title, size_t length,
void *data);
#ifndef NDEBUG
void
twc_tox_log_callback(Tox *tox,
TOX_LOG_LEVEL level,
const char *file, uint32_t line, const char *func,
const char *message, void *user_data);
#endif /* !NDEBUG */
#endif // TOX_WEECHAT_TOX_CALLBACKS_H