+/**
+ * g_log:
+ * @log_domain: the log domain, usually #G_LOG_DOMAIN
+ * @log_level: the log level, either from #GLogLevelFlags
+ * or a user-defined level
+ * @format: the message format. See the printf() documentation
+ * @...: the parameters to insert into the format string
+ *
+ * Logs an error or debugging message.
+ *
+ * If the log level has been set as fatal, the abort()
+ * function is called to terminate the program.
+ *
+ * If g_log_default_handler() is used as the log handler function, a new-line
+ * character will automatically be appended to @..., and need not be entered
+ * manually.
+ */
+void
+g_log (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *format,
+ ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ g_logv (log_domain, log_level, format, args);
+ va_end (args);
+}
+
+void
+g_return_if_fail_warning (const char *log_domain,
+ const char *pretty_function,
+ const char *expression)
+{
+ g_log (log_domain,
+ G_LOG_LEVEL_CRITICAL,
+ "%s: assertion '%s' failed",
+ pretty_function,
+ expression);
+}
+
+void
+g_warn_message (const char *domain,
+ const char *file,
+ int line,
+ const char *func,
+ const char *warnexpr)
+{
+ char *s, lstr[32];
+ g_snprintf (lstr, 32, "%d", line);
+ if (warnexpr)
+ s = g_strconcat ("(", file, ":", lstr, "):",
+ func, func[0] ? ":" : "",
+ " runtime check failed: (", warnexpr, ")", NULL);
+ else
+ s = g_strconcat ("(", file, ":", lstr, "):",
+ func, func[0] ? ":" : "",
+ " ", "code should not be reached", NULL);
+ g_log (domain, G_LOG_LEVEL_WARNING, "%s", s);
+ g_free (s);
+}
+
+void
+g_assert_warning (const char *log_domain,
+ const char *file,
+ const int line,
+ const char *pretty_function,
+ const char *expression)
+{
+ if (expression)
+ g_log (log_domain,
+ G_LOG_LEVEL_ERROR,
+ "file %s: line %d (%s): assertion failed: (%s)",
+ file,
+ line,
+ pretty_function,
+ expression);
+ else
+ g_log (log_domain,
+ G_LOG_LEVEL_ERROR,
+ "file %s: line %d (%s): should not be reached",
+ file,
+ line,
+ pretty_function);
+ _g_log_abort (FALSE);
+ abort ();
+}
+
+/**
+ * g_test_expect_message:
+ * @log_domain: (allow-none): the log domain of the message
+ * @log_level: the log level of the message
+ * @pattern: a glob-style [pattern][glib-Glob-style-pattern-matching]
+ *
+ * Indicates that a message with the given @log_domain and @log_level,
+ * with text matching @pattern, is expected to be logged. When this
+ * message is logged, it will not be printed, and the test case will
+ * not abort.
+ *
+ * Use g_test_assert_expected_messages() to assert that all
+ * previously-expected messages have been seen and suppressed.
+ *
+ * You can call this multiple times in a row, if multiple messages are
+ * expected as a result of a single call. (The messages must appear in
+ * the same order as the calls to g_test_expect_message().)
+ *
+ * For example:
+ *
+ * |[<!-- language="C" -->
+ * // g_main_context_push_thread_default() should fail if the
+ * // context is already owned by another thread.
+ * g_test_expect_message (G_LOG_DOMAIN,
+ * G_LOG_LEVEL_CRITICAL,
+ * "assertion*acquired_context*failed");
+ * g_main_context_push_thread_default (bad_context);
+ * g_test_assert_expected_messages ();
+ * ]|
+ *
+ * Note that you cannot use this to test g_error() messages, since
+ * g_error() intentionally never returns even if the program doesn't
+ * abort; use g_test_trap_subprocess() in this case.
+ *
+ * If messages at %G_LOG_LEVEL_DEBUG are emitted, but not explicitly
+ * expected via g_test_expect_message() then they will be ignored.
+ *
+ * Since: 2.34
+ */
+void
+g_test_expect_message (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *pattern)
+{
+ GTestExpectedMessage *expected;
+
+ g_return_if_fail (log_level != 0);
+ g_return_if_fail (pattern != NULL);
+ g_return_if_fail (~log_level & G_LOG_LEVEL_ERROR);
+
+ expected = g_new (GTestExpectedMessage, 1);
+ expected->log_domain = g_strdup (log_domain);
+ expected->log_level = log_level;
+ expected->pattern = g_strdup (pattern);
+
+ expected_messages = g_slist_append (expected_messages, expected);
+}
+
+void
+g_test_assert_expected_messages_internal (const char *domain,
+ const char *file,
+ int line,
+ const char *func)
+{
+ if (expected_messages)
+ {
+ GTestExpectedMessage *expected;
+ gchar level_prefix[STRING_BUFFER_SIZE];
+ gchar *message;
+
+ expected = expected_messages->data;
+
+ mklevel_prefix (level_prefix, expected->log_level);
+ message = g_strdup_printf ("Did not see expected message %s: %s",
+ level_prefix, expected->pattern);
+ g_assertion_message (domain, file, line, func, message);
+ g_free (message);
+ }
+}
+
+/**
+ * g_test_assert_expected_messages:
+ *
+ * Asserts that all messages previously indicated via
+ * g_test_expect_message() have been seen and suppressed.
+ *
+ * If messages at %G_LOG_LEVEL_DEBUG are emitted, but not explicitly
+ * expected via g_test_expect_message() then they will be ignored.
+ *
+ * Since: 2.34
+ */
+
+void
+_g_log_fallback_handler (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer unused_data)
+{
+ gchar level_prefix[STRING_BUFFER_SIZE];
+#ifndef G_OS_WIN32
+ gchar pid_string[FORMAT_UNSIGNED_BUFSIZE];
+#endif
+ int fd;
+
+ /* we cannot call _any_ GLib functions in this fallback handler,
+ * which is why we skip UTF-8 conversion, etc.
+ * since we either recursed or ran out of memory, we're in a pretty
+ * pathologic situation anyways, what we can do is giving the
+ * the process ID unconditionally however.
+ */
+
+ fd = mklevel_prefix (level_prefix, log_level);
+ if (!message)
+ message = "(NULL) message";
+
+#ifndef G_OS_WIN32
+ format_unsigned (pid_string, getpid (), 10);
+#endif
+
+ if (log_domain)
+ write_string (fd, "\n");
+ else
+ write_string (fd, "\n** ");
+
+#ifndef G_OS_WIN32
+ write_string (fd, "(process:");
+ write_string (fd, pid_string);
+ write_string (fd, "): ");
+#endif
+
+ if (log_domain)
+ {
+ write_string (fd, log_domain);
+ write_string (fd, "-");
+ }
+ write_string (fd, level_prefix);
+ write_string (fd, ": ");
+ write_string (fd, message);
+}
+
+static void
+escape_string (GString *string)
+{
+ const char *p = string->str;
+ gunichar wc;
+
+ while (p < string->str + string->len)
+ {
+ gboolean safe;
+
+ wc = g_utf8_get_char_validated (p, -1);
+ if (wc == (gunichar)-1 || wc == (gunichar)-2)