By default, mutt_log will prepend a date to the log if it has changed
between two debug statements. In some situation, it might cause the logs
to be very hard to read.
This adds a function mutt_log_append that simply appends the string to
the logs, without printing the date.
---
lib.c | 34 +++++++++++++++++++++++++++-------
lib.h | 1 +
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/lib.c b/lib.c
index 38fffb2..a90bc20 100644
--- a/lib.c
+++ b/lib.c
@@ -1053,9 +1053,8 @@ int mutt_log_get_level (void)
return debuglevel;
}
-void mutt_log (int level, const char *fmt, ...)
+static void mutt_vlog (int level, int print_time, const char *fmt, va_list vl)
{
- va_list ap;
time_t now = time (NULL);
static char buf[23] = "";
static time_t last = 0;
@@ -1063,14 +1062,35 @@ void mutt_log (int level, const char *fmt, ...)
if (debuglevel < level || !debugfile)
return;
- if (now > last)
+ if (print_time)
{
- strftime (buf, sizeof (buf), "%Y-%m-%d %H:%M:%S", localtime (&now));
- last = now;
+ if (now > last)
+ {
+ strftime (buf, sizeof (buf), "%Y-%m-%d %H:%M:%S", localtime (&now));
+ last = now;
+ }
+
+ fprintf (debugfile, "[%s] ", buf);
}
- fprintf (debugfile, "[%s] ", buf);
+
+ vfprintf (debugfile, fmt, vl);
+}
+
+void mutt_log (int level, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+ mutt_vlog (level, 1, fmt, ap);
+ va_end (ap);
+}
+
+void mutt_log_append (int level, const char *fmt, ...)
+{
+ va_list ap;
+
va_start (ap, fmt);
- vfprintf (debugfile, fmt, ap);
+ mutt_vlog (level, 0, fmt, ap);
va_end (ap);
}
#endif
diff --git a/lib.h b/lib.h
index 2328fca..f8f4d88 100644
--- a/lib.h
+++ b/lib.h
@@ -139,6 +139,7 @@ int mutt_log_init (const char *reldate, const char
*homedir);
int mutt_log_set_level (int level);
int mutt_log_get_level (void);
void mutt_log (int level, const char *, ...);
+void mutt_log_append (int level, const char *, ...);
# else
--
2.9.0