Improve debugging
* libmailutils/diag/debug.c (mu_debug_log): Account for eventual newlines in the generated message string. * imap4d/io.c (imap4d_init_tls_server): Use mu_stream_strerror.
Showing
2 changed files
with
22 additions
and
4 deletions
... | @@ -139,7 +139,7 @@ imap4d_init_tls_server () | ... | @@ -139,7 +139,7 @@ imap4d_init_tls_server () |
139 | if (rc) | 139 | if (rc) |
140 | { | 140 | { |
141 | mu_diag_output (MU_DIAG_ERROR, _("cannot open TLS stream: %s"), | 141 | mu_diag_output (MU_DIAG_ERROR, _("cannot open TLS stream: %s"), |
142 | mu_stream_strerror (tlsstream, rc)); | 142 | mu_strerror (rc)); |
143 | return 1; | 143 | return 1; |
144 | } | 144 | } |
145 | 145 | ... | ... |
... | @@ -34,6 +34,7 @@ | ... | @@ -34,6 +34,7 @@ |
34 | #include <mailutils/stdstream.h> | 34 | #include <mailutils/stdstream.h> |
35 | #include <mailutils/iterator.h> | 35 | #include <mailutils/iterator.h> |
36 | #include <mailutils/cstr.h> | 36 | #include <mailutils/cstr.h> |
37 | #include <mailutils/io.h> | ||
37 | 38 | ||
38 | int mu_debug_line_info; /* Debug messages include source locations */ | 39 | int mu_debug_line_info; /* Debug messages include source locations */ |
39 | 40 | ||
... | @@ -675,13 +676,30 @@ void | ... | @@ -675,13 +676,30 @@ void |
675 | mu_debug_log (const char *fmt, ...) | 676 | mu_debug_log (const char *fmt, ...) |
676 | { | 677 | { |
677 | va_list ap; | 678 | va_list ap; |
679 | char *buf = NULL; | ||
680 | size_t buflen = 0; | ||
681 | size_t n; | ||
682 | int rc; | ||
678 | 683 | ||
679 | mu_diag_init (); | 684 | mu_diag_init (); |
680 | va_start (ap, fmt); | 685 | va_start (ap, fmt); |
681 | mu_stream_printf (mu_strerr, "\033s<%d>", MU_LOG_DEBUG); | 686 | rc = mu_vasnprintf (&buf, &buflen, fmt, ap); |
682 | mu_stream_vprintf (mu_strerr, fmt, ap); | ||
683 | mu_stream_write (mu_strerr, "\n", 1, NULL); | ||
684 | va_end (ap); | 687 | va_end (ap); |
688 | if (rc == 0) | ||
689 | { | ||
690 | size_t i; | ||
691 | int nl = 0; | ||
692 | for (i = 0; buf[i]; i += n) | ||
693 | { | ||
694 | n = strcspn (buf + i, "\n"); | ||
695 | if ((nl = buf[i + n])) | ||
696 | ++n; | ||
697 | mu_stream_printf (mu_strerr, "\033s<%d>", MU_LOG_DEBUG); | ||
698 | mu_stream_write (mu_strerr, buf + i, n, NULL); | ||
699 | } | ||
700 | if (!nl) | ||
701 | mu_stream_write (mu_strerr, "\n", 1, NULL); | ||
702 | } | ||
685 | } | 703 | } |
686 | 704 | ||
687 | void | 705 | void | ... | ... |
-
Please register or sign in to post a comment