107 lines
4.4 KiB
Diff
107 lines
4.4 KiB
Diff
From 76e0943e4f2b72c11cdf4ac2001d647abae0617f 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: Thu, 18 Apr 2019 13:41:04 +0200
|
|
Subject: [PATCH 3/3] Add a logdebug argument to hawkey.Sack()
|
|
|
|
When set to false (default), only logs messages from INFO up, when true,
|
|
logs all messages, including DEBUG.
|
|
|
|
The fact that its a keyword argument means the change is compatible with
|
|
older consumers of the API, but the bahaviour will be changed, the debug
|
|
messages will not be logged anymore.
|
|
|
|
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/6c52bd330b37e07a3a708cee29c0d0772a161053
|
|
---
|
|
python/hawkey/sack-py.cpp | 29 +++++++++++++++++++++--------
|
|
python/hawkey/sack-py.hpp | 2 +-
|
|
2 files changed, 22 insertions(+), 9 deletions(-)
|
|
|
|
diff --git a/python/hawkey/sack-py.cpp b/python/hawkey/sack-py.cpp
|
|
index a7ccb37..58b0f19 100644
|
|
--- a/python/hawkey/sack-py.cpp
|
|
+++ b/python/hawkey/sack-py.cpp
|
|
@@ -183,7 +183,7 @@ log_handler_noop(const gchar *, GLogLevelFlags, const gchar *, gpointer)
|
|
}
|
|
|
|
gboolean
|
|
-set_logfile(const gchar *path, FILE *log_out)
|
|
+set_logfile(const gchar *path, FILE *log_out, bool debug)
|
|
{
|
|
log_out = fopen(path, "a");
|
|
|
|
@@ -194,9 +194,16 @@ set_logfile(const gchar *path, FILE *log_out)
|
|
// other logger to stderr/stdout, we do not want that
|
|
g_log_set_default_handler(log_handler_noop, nullptr);
|
|
|
|
+ GLogLevelFlags log_mask = debug ? G_LOG_LEVEL_MASK : static_cast<GLogLevelFlags>(
|
|
+ G_LOG_LEVEL_INFO |
|
|
+ G_LOG_LEVEL_MESSAGE |
|
|
+ G_LOG_LEVEL_WARNING |
|
|
+ G_LOG_LEVEL_CRITICAL |
|
|
+ G_LOG_LEVEL_ERROR);
|
|
+
|
|
// 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_log_set_handler(nullptr, log_mask, log_handler, log_out);
|
|
+ g_log_set_handler("libdnf", log_mask, log_handler, log_out);
|
|
|
|
g_info("=== Started libdnf-%d.%d.%d ===", LIBDNF_MAJOR_VERSION,
|
|
LIBDNF_MINOR_VERSION, LIBDNF_MICRO_VERSION);
|
|
@@ -216,16 +223,22 @@ sack_init(_SackObject *self, PyObject *args, PyObject *kwds)
|
|
PyObject *logfile_py = NULL;
|
|
self->log_out = NULL;
|
|
int make_cache_dir = 0;
|
|
+ PyObject *debug_object = nullptr;
|
|
gboolean all_arch = FALSE;
|
|
const char *kwlist[] = {"cachedir", "arch", "rootdir", "pkgcls",
|
|
- "pkginitval", "make_cache_dir", "logfile", "all_arch",
|
|
- NULL};
|
|
+ "pkginitval", "make_cache_dir", "logfile", "logdebug",
|
|
+ "all_arch", NULL};
|
|
|
|
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OssOOiOi", (char**) kwlist,
|
|
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OssOOiOO!i", (char**) kwlist,
|
|
&cachedir_py, &arch, &rootdir,
|
|
&custom_class, &custom_val,
|
|
- &make_cache_dir, &logfile_py, &all_arch))
|
|
+ &make_cache_dir, &logfile_py,
|
|
+ &PyBool_Type, &debug_object,
|
|
+ &all_arch))
|
|
return -1;
|
|
+
|
|
+ bool debug = debug_object != nullptr && PyObject_IsTrue(debug_object);
|
|
+
|
|
if (cachedir_py != NULL) {
|
|
cachedir = PycompString(cachedir_py);
|
|
if (!cachedir.getCString())
|
|
@@ -249,7 +262,7 @@ sack_init(_SackObject *self, PyObject *args, PyObject *kwds)
|
|
PycompString logfile(logfile_py);
|
|
if (!logfile.getCString())
|
|
return -1;
|
|
- if (!set_logfile(logfile.getCString(), self->log_out)) {
|
|
+ if (!set_logfile(logfile.getCString(), self->log_out, debug)) {
|
|
PyErr_Format(PyExc_IOError, "Failed to open log file: %s", logfile.getCString());
|
|
return -1;
|
|
}
|
|
diff --git a/python/hawkey/sack-py.hpp b/python/hawkey/sack-py.hpp
|
|
index cba8acc..50289d7 100644
|
|
--- a/python/hawkey/sack-py.hpp
|
|
+++ b/python/hawkey/sack-py.hpp
|
|
@@ -35,7 +35,7 @@ DnfSack *sackFromPyObject(PyObject *o);
|
|
int sack_converter(PyObject *o, DnfSack **sack_ptr);
|
|
|
|
PyObject *new_package(PyObject *sack, Id id);
|
|
-gboolean set_logfile(const gchar *path, FILE *log_out);
|
|
+gboolean set_logfile(const gchar *path, FILE *log_out, bool debug = false);
|
|
const char *log_level_name(int level);
|
|
|
|
#endif // SACK_PY_H
|
|
--
|
|
2.19.1
|
|
|