From ea05dba9b6dade513ceeac009da0d4e3a8eae59e Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 9 May 2001 16:36:17 +0000 Subject: [PATCH] Get rid of --enable-msg-prefix 2001-04-26 Havoc Pennington * configure.in: Get rid of --enable-msg-prefix * gmessages.c: make whether to prefix the messages with appname/pid a runtime setting, not a compile-time setting. Change default to include prefix for debug/warning/error type messages. --- ChangeLog | 8 ++++ ChangeLog.pre-2-0 | 8 ++++ ChangeLog.pre-2-10 | 8 ++++ ChangeLog.pre-2-12 | 8 ++++ ChangeLog.pre-2-2 | 8 ++++ ChangeLog.pre-2-4 | 8 ++++ ChangeLog.pre-2-6 | 8 ++++ ChangeLog.pre-2-8 | 8 ++++ configure.in | 6 --- glib/gmessages.c | 103 +++++++++++++++++++++++++++++++-------------- gmessages.c | 103 +++++++++++++++++++++++++++++++-------------- 11 files changed, 208 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index 97606adc8..ebcd9d189 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-04-26 Havoc Pennington + + * configure.in: Get rid of --enable-msg-prefix + + * gmessages.c: make whether to prefix the messages with + appname/pid a runtime setting, not a compile-time setting. Change + default to include prefix for debug/warning/error type messages. + 2001-05-09 Sebastian Wilhelmi * gthread.c, gthread.h: Renamed 'value' and 'arg' to 'data' and diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 97606adc8..ebcd9d189 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,11 @@ +2001-04-26 Havoc Pennington + + * configure.in: Get rid of --enable-msg-prefix + + * gmessages.c: make whether to prefix the messages with + appname/pid a runtime setting, not a compile-time setting. Change + default to include prefix for debug/warning/error type messages. + 2001-05-09 Sebastian Wilhelmi * gthread.c, gthread.h: Renamed 'value' and 'arg' to 'data' and diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 97606adc8..ebcd9d189 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2001-04-26 Havoc Pennington + + * configure.in: Get rid of --enable-msg-prefix + + * gmessages.c: make whether to prefix the messages with + appname/pid a runtime setting, not a compile-time setting. Change + default to include prefix for debug/warning/error type messages. + 2001-05-09 Sebastian Wilhelmi * gthread.c, gthread.h: Renamed 'value' and 'arg' to 'data' and diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 97606adc8..ebcd9d189 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2001-04-26 Havoc Pennington + + * configure.in: Get rid of --enable-msg-prefix + + * gmessages.c: make whether to prefix the messages with + appname/pid a runtime setting, not a compile-time setting. Change + default to include prefix for debug/warning/error type messages. + 2001-05-09 Sebastian Wilhelmi * gthread.c, gthread.h: Renamed 'value' and 'arg' to 'data' and diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 97606adc8..ebcd9d189 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +2001-04-26 Havoc Pennington + + * configure.in: Get rid of --enable-msg-prefix + + * gmessages.c: make whether to prefix the messages with + appname/pid a runtime setting, not a compile-time setting. Change + default to include prefix for debug/warning/error type messages. + 2001-05-09 Sebastian Wilhelmi * gthread.c, gthread.h: Renamed 'value' and 'arg' to 'data' and diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 97606adc8..ebcd9d189 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +2001-04-26 Havoc Pennington + + * configure.in: Get rid of --enable-msg-prefix + + * gmessages.c: make whether to prefix the messages with + appname/pid a runtime setting, not a compile-time setting. Change + default to include prefix for debug/warning/error type messages. + 2001-05-09 Sebastian Wilhelmi * gthread.c, gthread.h: Renamed 'value' and 'arg' to 'data' and diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 97606adc8..ebcd9d189 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +2001-04-26 Havoc Pennington + + * configure.in: Get rid of --enable-msg-prefix + + * gmessages.c: make whether to prefix the messages with + appname/pid a runtime setting, not a compile-time setting. Change + default to include prefix for debug/warning/error type messages. + 2001-05-09 Sebastian Wilhelmi * gthread.c, gthread.h: Renamed 'value' and 'arg' to 'data' and diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 97606adc8..ebcd9d189 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2001-04-26 Havoc Pennington + + * configure.in: Get rid of --enable-msg-prefix + + * gmessages.c: make whether to prefix the messages with + appname/pid a runtime setting, not a compile-time setting. Change + default to include prefix for debug/warning/error type messages. + 2001-05-09 Sebastian Wilhelmi * gthread.c, gthread.h: Renamed 'value' and 'arg' to 'data' and diff --git a/configure.in b/configure.in index bb29288c5..6eba44dd2 100644 --- a/configure.in +++ b/configure.in @@ -101,7 +101,6 @@ esac[]dnl dnl declare --enable-* args and collect ac_help strings AC_ARG_ENABLE(debug, [ --enable-debug=[no/minimum/yes] turn on debugging [default=$debug_default]],,enable_debug=$debug_default) -AC_ARG_ENABLE(msg-prefix, [ --enable-msg-prefix turn on program name and PID prefixing of messages and warnings],,enable_msg_prefix=no) AC_ARG_ENABLE(gc_friendly, [ --enable-gc-friendly turn on garbage collector friendliness [default=no]],,enable_gc_friendly=no) AC_ARG_ENABLE(mem_pools, [ --disable-mem-pools disable all glib memory pools],,disable_mem_pools=no) AC_ARG_ENABLE(ansi, [ --enable-ansi turn on strict ansi [default=no]], @@ -135,11 +134,6 @@ else AC_MSG_RESULT(yes) fi -if test "x$enable_msg_prefix" = "xyes"; then - AC_DEFINE_UNQUOTED(G_ENABLE_MSG_PREFIX, 1, - [Enable prefixing of error messages with program names]) -fi - dnl Checks for programs. AC_PROG_CC diff --git a/glib/gmessages.c b/glib/gmessages.c index c8ec37bd5..3cfaa52a0 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -86,7 +86,6 @@ static GPrintFunc glib_message_func = NULL; static GPrivate* g_log_depth = NULL; - /* --- functions --- */ #ifdef G_OS_WIN32 # define STRICT @@ -150,7 +149,59 @@ ensure_stdout_valid (void) #else #define ensure_stdout_valid() /* Define as empty */ #endif - + +static void +g_log_write_prefix (gint fd, + GLogLevelFlags mask) +{ + static GLogLevelFlags g_log_msg_prefix = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG; + static gboolean initted = FALSE; + + g_mutex_lock (g_messages_lock); + + if (!initted) + { + const gchar *val; + initted = TRUE; + + val = g_getenv ("G_PREFIX_MESSAGES"); + + if (val) + { + static const GDebugKey keys[] = { + { "error", G_LOG_LEVEL_ERROR }, + { "critical", G_LOG_LEVEL_CRITICAL }, + { "warning", G_LOG_LEVEL_WARNING }, + { "message", G_LOG_LEVEL_MESSAGE }, + { "info", G_LOG_LEVEL_INFO }, + { "debug", G_LOG_LEVEL_DEBUG } + }; + + g_log_msg_prefix = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys)); + } + } + + g_mutex_unlock (g_messages_lock); + + if ((g_log_msg_prefix & mask) == mask) + { + gchar prg_pid[64], *prg_name; + + prg_name = g_get_prgname (); + + if (!prg_name) + { + prg_name = "(process"; + sprintf (prg_pid, ":%u): ", getpid ()); + } + else + sprintf (prg_pid, " (pid:%u): ", getpid ()); + + write (fd, prg_name, strlen (prg_name)); + write (fd, prg_pid, strlen (prg_pid)); + } +} + static inline GLogDomain* g_log_find_domain (const gchar *log_domain) { @@ -480,7 +531,7 @@ g_log_default_handler (const gchar *log_domain, GWarningFunc local_glib_warning_func; GPrintFunc local_glib_message_func; gchar prg_pid[64], *prg_name = g_get_prgname (); - + in_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0; is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0; log_level &= G_LOG_LEVEL_MASK; @@ -523,10 +574,8 @@ g_log_default_handler (const gchar *log_domain, /* use write(2) for output, in case we are out of memeory */ ensure_stdout_valid (); write (fd, "\n", 1); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -547,10 +596,8 @@ g_log_default_handler (const gchar *log_domain, case G_LOG_LEVEL_CRITICAL: ensure_stdout_valid (); write (fd, "\n", 1); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -577,10 +624,8 @@ g_log_default_handler (const gchar *log_domain, } ensure_stdout_valid (); write (fd, "\n", 1); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -606,10 +651,9 @@ g_log_default_handler (const gchar *log_domain, return; } ensure_stdout_valid (); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -627,10 +671,9 @@ g_log_default_handler (const gchar *log_domain, break; case G_LOG_LEVEL_INFO: ensure_stdout_valid (); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -648,10 +691,9 @@ g_log_default_handler (const gchar *log_domain, break; case G_LOG_LEVEL_DEBUG: ensure_stdout_valid (); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -672,10 +714,9 @@ g_log_default_handler (const gchar *log_domain, * try to make the best out of it. */ ensure_stdout_valid (); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); diff --git a/gmessages.c b/gmessages.c index c8ec37bd5..3cfaa52a0 100644 --- a/gmessages.c +++ b/gmessages.c @@ -86,7 +86,6 @@ static GPrintFunc glib_message_func = NULL; static GPrivate* g_log_depth = NULL; - /* --- functions --- */ #ifdef G_OS_WIN32 # define STRICT @@ -150,7 +149,59 @@ ensure_stdout_valid (void) #else #define ensure_stdout_valid() /* Define as empty */ #endif - + +static void +g_log_write_prefix (gint fd, + GLogLevelFlags mask) +{ + static GLogLevelFlags g_log_msg_prefix = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG; + static gboolean initted = FALSE; + + g_mutex_lock (g_messages_lock); + + if (!initted) + { + const gchar *val; + initted = TRUE; + + val = g_getenv ("G_PREFIX_MESSAGES"); + + if (val) + { + static const GDebugKey keys[] = { + { "error", G_LOG_LEVEL_ERROR }, + { "critical", G_LOG_LEVEL_CRITICAL }, + { "warning", G_LOG_LEVEL_WARNING }, + { "message", G_LOG_LEVEL_MESSAGE }, + { "info", G_LOG_LEVEL_INFO }, + { "debug", G_LOG_LEVEL_DEBUG } + }; + + g_log_msg_prefix = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys)); + } + } + + g_mutex_unlock (g_messages_lock); + + if ((g_log_msg_prefix & mask) == mask) + { + gchar prg_pid[64], *prg_name; + + prg_name = g_get_prgname (); + + if (!prg_name) + { + prg_name = "(process"; + sprintf (prg_pid, ":%u): ", getpid ()); + } + else + sprintf (prg_pid, " (pid:%u): ", getpid ()); + + write (fd, prg_name, strlen (prg_name)); + write (fd, prg_pid, strlen (prg_pid)); + } +} + static inline GLogDomain* g_log_find_domain (const gchar *log_domain) { @@ -480,7 +531,7 @@ g_log_default_handler (const gchar *log_domain, GWarningFunc local_glib_warning_func; GPrintFunc local_glib_message_func; gchar prg_pid[64], *prg_name = g_get_prgname (); - + in_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0; is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0; log_level &= G_LOG_LEVEL_MASK; @@ -523,10 +574,8 @@ g_log_default_handler (const gchar *log_domain, /* use write(2) for output, in case we are out of memeory */ ensure_stdout_valid (); write (fd, "\n", 1); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -547,10 +596,8 @@ g_log_default_handler (const gchar *log_domain, case G_LOG_LEVEL_CRITICAL: ensure_stdout_valid (); write (fd, "\n", 1); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -577,10 +624,8 @@ g_log_default_handler (const gchar *log_domain, } ensure_stdout_valid (); write (fd, "\n", 1); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -606,10 +651,9 @@ g_log_default_handler (const gchar *log_domain, return; } ensure_stdout_valid (); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -627,10 +671,9 @@ g_log_default_handler (const gchar *log_domain, break; case G_LOG_LEVEL_INFO: ensure_stdout_valid (); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -648,10 +691,9 @@ g_log_default_handler (const gchar *log_domain, break; case G_LOG_LEVEL_DEBUG: ensure_stdout_valid (); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -672,10 +714,9 @@ g_log_default_handler (const gchar *log_domain, * try to make the best out of it. */ ensure_stdout_valid (); -#ifdef G_ENABLE_MSG_PREFIX - write (fd, prg_name, strlen (prg_name)); - write (fd, prg_pid, strlen (prg_pid)); -#endif /* G_ENABLE_MSG_PREFIX */ + + g_log_write_prefix (fd, log_level); + if (log_domain) { write (fd, log_domain, strlen (log_domain));