[gjs] log errors to stderr always, even if GJS_DEBUG_OUTPUT is set log them to stderr also
- From: Havoc Pennington <hp src gnome org>
- To: svn-commits-list gnome org
- Subject: [gjs] log errors to stderr always, even if GJS_DEBUG_OUTPUT is set log them to stderr also
- Date: Fri, 15 May 2009 12:42:12 -0400 (EDT)
commit 42d013d31ef65a9985aee7d67754bb071e0e2f3e
Author: Havoc Pennington <hp pobox com>
Date: Tue May 5 18:02:47 2009 -0400
log errors to stderr always, even if GJS_DEBUG_OUTPUT is set log them to stderr also
They should be on stderr for visibility, but can be useful to have them
in GJS_DEBUG_OUTPUT also for context.
---
util/log.c | 47 +++++++++++++++++++++++++++++++++++------------
1 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/util/log.c b/util/log.c
index 3b68d8e..2de116d 100644
--- a/util/log.c
+++ b/util/log.c
@@ -93,6 +93,21 @@ is_allowed_prefix (const char *prefix)
#define PREFIX_LENGTH 12
+static void
+write_to_stream(FILE *logfp,
+ gboolean error,
+ const char *prefix,
+ const char *s)
+{
+ /* seek to end to avoid truncating in case we're using shared logfile */
+ (void)fseek(logfp, 0, SEEK_END);
+
+ fprintf(logfp, "%*s: %s%s", PREFIX_LENGTH, prefix, error ? "!!! " : "", s);
+ if (!g_str_has_suffix(s, "\n"))
+ fputs("\n", logfp);
+ fflush(logfp);
+}
+
void
gjs_debug(GjsDebugTopic topic,
const char *format,
@@ -270,30 +285,38 @@ gjs_debug(GjsDebugTopic topic,
access(s2, F_OK);
g_free(s2);
} else {
- /* seek to end to avoid truncating in case we're using shared logfile */
- (void)fseek(logfp, 0, SEEK_END);
-
if (print_timestamp) {
static gdouble previous = 0.0;
gdouble total = g_timer_elapsed(timer, NULL) * 1000.0;
gdouble since = total - previous;
+ const char *ts_suffix;
+ char *s2;
- fprintf(logfp, "%g ", total);
if (since > 50.0) {
- fprintf(logfp, "!! ");
+ ts_suffix = "!! ";
} else if (since > 100.0) {
- fprintf(logfp, "!!! ");
+ ts_suffix = "!!! ";
} else if (since > 200.0) {
- fprintf(logfp, "!!!!");
+ ts_suffix = "!!!!";
} else {
- fprintf(logfp, " ");
+ ts_suffix = " ";
}
+
+ s2 = g_strdup_printf("%g %s%s",
+ total, ts_suffix, s);
+ g_free(s);
+ s = s2;
+
previous = total;
}
- fprintf(logfp, "%*s: %s%s", PREFIX_LENGTH, prefix, error ? "!!! " : "", s);
- if (!g_str_has_suffix(s, "\n"))
- fputs("\n", logfp);
- fflush(logfp);
+
+ /* write to both stderr and logfile
+ * if it's an error
+ */
+ if (error && logfp != stderr)
+ write_to_stream(stderr, error, prefix, s);
+
+ write_to_stream(logfp, error, prefix, s);
}
g_free(s);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]