aboutsummaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-09 23:09:10 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-10 00:55:13 +0200
commit7a7192d327ea92285653f4de7b0b21046437498d (patch)
tree7564e72e72ef841edc40dbd0b712eeccb6d20906 /degesch.c
parent445837007d4d6000a322d7738f05035fcc9023a8 (diff)
downloadxK-7a7192d327ea92285653f4de7b0b21046437498d.tar.gz
xK-7a7192d327ea92285653f4de7b0b21046437498d.tar.xz
xK-7a7192d327ea92285653f4de7b0b21046437498d.zip
degesch: unfuck debug logging
We can store most of the messages in buffers, which gives us the nice possibility of using the formatter to fix encodings, as well as the ability to redisplay the debug prints. And we can also have some nice colors.
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c45
1 files changed, 18 insertions, 27 deletions
diff --git a/degesch.c b/degesch.c
index 3d0585d..f4fc87c 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2749,6 +2749,18 @@ log_full (struct app_context *ctx, struct server *s, struct buffer *buffer,
#define log_server_error(s, buffer, ...) \
log_server ((s), (buffer), BUFFER_LINE_ERROR, __VA_ARGS__)
+#define log_global_debug(ctx, ...) \
+ BLOCK_START \
+ if (g_debug_mode) \
+ log_global ((ctx), 0, "(*) " __VA_ARGS__); \
+ BLOCK_END
+
+#define log_server_debug(s, ...) \
+ BLOCK_START \
+ if (g_debug_mode) \
+ log_server ((s), (s)->buffer, 0, "(*) " __VA_ARGS__); \
+ BLOCK_END
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Lines that are used in more than one place
@@ -3377,7 +3389,7 @@ irc_send (struct server *s, const char *format, ...)
{
if (!soft_assert (irc_is_connected (s)))
{
- print_debug ("tried sending a message to a dead server connection");
+ log_server_debug (s, "sending a message to a dead server connection");
return;
}
@@ -3392,19 +3404,7 @@ irc_send (struct server *s, const char *format, ...)
str_append_vprintf (&str, format, ap);
va_end (ap);
- if (g_debug_mode)
- {
- input_hide (&s->ctx->input);
-
- char *server_name =
- iconv_xstrdup (s->ctx->term_from_utf8, s->name, -1, NULL);
- char *term = irc_to_term (s->ctx, str.str);
- fprintf (stderr, "[%s] <== \"%s\"\n", server_name, term);
- free (term);
- free (server_name);
-
- input_show (&s->ctx->input);
- }
+ log_server_debug (s, "#a<< \"#S\"#r", ATTR_PART, str.str);
str_append_str (&s->write_buffer, &str);
str_free (&str);
@@ -5939,19 +5939,7 @@ irc_process_message (const struct irc_message *msg,
{
struct server *s = user_data;
- if (g_debug_mode)
- {
- input_hide (&s->ctx->input);
-
- char *server_name =
- iconv_xstrdup (s->ctx->term_from_utf8, s->name, -1, NULL);
- char *term = irc_to_term (s->ctx, raw);
- fprintf (stderr, "[%s] ==> \"%s\"\n", server_name, term);
- free (term);
- free (server_name);
-
- input_show (&s->ctx->input);
- }
+ log_server_debug (s, "#a>> \"#S\"#r", ATTR_JOIN, raw);
struct irc_handler key = { .name = msg->command };
struct irc_handler *handler = bsearch (&key, g_irc_handlers,
@@ -7759,6 +7747,9 @@ process_input_utf8 (struct app_context *ctx, char *input, int alias_level)
return;
char *expanded = expand_alias (ctx, name, input);
+ if (expanded)
+ log_global_debug (ctx, "Alias expanded to \"#s\"", expanded);
+
if (!expanded)
log_global_error (ctx, "#s: /#s", "No such command or alias", name);
else if (alias_level != 0)