libdnf/Set-relevant-g_log-domain-handlers-instead-of-a-defa.patch
2019-12-25 15:52:27 +08:00

75 lines
2.9 KiB
Diff

From b91a898bcfbe2743fb1b5fd524eef077271187e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
Date: Wed, 17 Apr 2019 13:48:26 +0200
Subject: [PATCH 1/3] Set relevant g_log domain handlers instead of a default
one
Sets up logging for the default domain as well as "libdnf" domain
instead of setting a default logging handler. The default handler is a
catch-all for messages with a (domain, level) combination that doesn't
get handled by any other handler.
We certainly don't want to be logging (domain, level) combinations that
we explicitly turned off. The glib's g_log_default_handler() doesn't
print DEBUG and INFO level messages, but ours did, effectively
redirecting anything (using glib logging) that was turned off elsewhere
to hawkey.log.
This commit sets the default log handler to a noop function to prevent
any unhandled messages to be logged here. This in theory should have no
effect if we don't turn off log levels from MESSAGE above (and we don't
have unhandled log domains), but if we ever do that, supposedly it is to
further minimize the logging and thus disabling logging of such messages
is the desired behaviour.
The logging of all libdnf code has the "libdnf" log domain and we also
set the same handler for the default domain (nullptr) just in case we
have some code somewhere using g_log and not having a domain set.
https://bugzilla.redhat.com/show_bug.cgi?id=1580022
https://bugzilla.redhat.com/show_bug.cgi?id=1678598
https://bugzilla.redhat.com/show_bug.cgi?id=1355764
https://bugzilla.redhat.com/show_bug.cgi?id=1695720
backport from:
https://github.com/rpm-software-management/libdnf/pull/707/commits/609d60f2a23182ba329a1d157f7263c13d4a379a
---
python/hawkey/sack-py.cpp | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/python/hawkey/sack-py.cpp b/python/hawkey/sack-py.cpp
index 95764fd..a7ccb37 100644
--- a/python/hawkey/sack-py.cpp
+++ b/python/hawkey/sack-py.cpp
@@ -177,6 +177,11 @@ log_handler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *mess
g_free(msg);
}
+static void
+log_handler_noop(const gchar *, GLogLevelFlags, const gchar *, gpointer)
+{
+}
+
gboolean
set_logfile(const gchar *path, FILE *log_out)
{
@@ -185,7 +190,14 @@ set_logfile(const gchar *path, FILE *log_out)
if (!log_out)
return FALSE;
- g_log_set_default_handler(log_handler, log_out);
+ // The default log handler prints messages that weren't handled by any
+ // other logger to stderr/stdout, we do not want that
+ g_log_set_default_handler(log_handler_noop, nullptr);
+
+ // set the handler for the default domain as well as "libdnf"
+ g_log_set_handler(nullptr, G_LOG_LEVEL_MASK, log_handler, log_out);
+ g_log_set_handler("libdnf", G_LOG_LEVEL_MASK, log_handler, log_out);
+
g_info("=== Started libdnf-%d.%d.%d ===", LIBDNF_MAJOR_VERSION,
LIBDNF_MINOR_VERSION, LIBDNF_MICRO_VERSION);
return TRUE;
--
2.19.1