Make it easier to filter logging
RFC patches for #2087.
gmessages: Add API to move info and debug messages to stderr
GLib code normally prints info and debug messages to stdout, but that interferes with programs that are documented to produce machine-readable output such as JSON or XML on stdout. In particular, if a program uses a GLib-based library, setting G_MESSAGES_DEBUG will typically result in that library's debug messages going to the program's stdout and corrupting the machine-readable output.
Unix programs can avoid this by using dup2() to move the original stdout to another fd, then dup2() again to make the new stdout a copy of stderr, but it's easier if we provide a way to not write debug messages to stdout in the first place. Calling g_log_writer_default_set_prefer_stderr (TRUE) results in behaviour resembling Python's logging.basicConfig(), with all diagnostics going to stderr.
Suggested by Allison Karlitskaya on #2087.
gmessages: Expose our default filtering as API
This allows programs that want to change how log messages are printed, such as gnome-terminal (gnome-terminal#42 (closed)) and Flatpak, to override the log-writer or the legacy log-handler without having to reimplement the G_MESSAGES_DEBUG filtering logic.