Package init

This commit is contained in:
dogsheng 2019-12-25 15:52:27 +08:00
parent 6e7d450630
commit 7f5bb8fb1f
4 changed files with 257 additions and 1 deletions

View File

@ -0,0 +1,69 @@
From 19d44b7ddf8266aabc04b18a0a6eb4716d08f9d0 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, 27 Mar 2019 15:08:59 +0100
Subject: [PATCH 2/3] Add a debug argument to Librepolog::addHandler
When set to false (default), only logs messages from INFO up, when true,
logs all messages, including DEBUG.
The argument having a default 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=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/daa9d69f98c96de54966905e80c4caa95f50d587
---
libdnf/repo/Repo.cpp | 11 +++++++++--
libdnf/repo/Repo.hpp | 2 +-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/libdnf/repo/Repo.cpp b/libdnf/repo/Repo.cpp
index 2844bfe..2c28541 100644
--- a/libdnf/repo/Repo.cpp
+++ b/libdnf/repo/Repo.cpp
@@ -1740,7 +1740,7 @@ static void librepoLogCB(G_GNUC_UNUSED const gchar *log_domain, GLogLevelFlags l
}
}
-long LibrepoLog::addHandler(const std::string & filePath)
+long LibrepoLog::addHandler(const std::string & filePath, bool debug)
{
static long uid = 0;
@@ -1755,7 +1755,14 @@ long LibrepoLog::addHandler(const std::string & filePath)
data->fd = fd;
// Set handler
- data->handlerId = g_log_set_handler(LR_LOGDOMAIN, G_LOG_LEVEL_MASK, librepoLogCB, data.get());
+ 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);
+
+ data->handlerId = g_log_set_handler(LR_LOGDOMAIN, log_mask, librepoLogCB, data.get());
data->used = true;
// Save user data (in a thread safe way)
diff --git a/libdnf/repo/Repo.hpp b/libdnf/repo/Repo.hpp
index 06e94f6..d5bef20 100644
--- a/libdnf/repo/Repo.hpp
+++ b/libdnf/repo/Repo.hpp
@@ -296,7 +296,7 @@ private:
struct LibrepoLog {
public:
- static long addHandler(const std::string & filePath);
+ static long addHandler(const std::string & filePath, bool debug = false);
static void removeHandler(long uid);
static void removeAllHandlers();
};
--
2.19.1

View File

@ -0,0 +1,106 @@
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

View File

@ -0,0 +1,74 @@
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

View File

@ -13,7 +13,7 @@
Name: libdnf
Version: 0.22.0
Release: 8
Release: 9
Summary: Library providing simplified C and Python API to libsolv
License: LGPLv2+
URL: https://github.com/rpm-software-management/libdnf
@ -24,6 +24,10 @@ Patch0003: 0003-swdb-create-persistent-WAL-files-RhBug1640235.patch
Patch0004: 0004-Relocate-ModuleContainer-save-hook-RhBug1632518.patch
Patch0005: 0005-Test-if-sack-is-present-and-run-save-module-persistor-RhBug1632518.patch
Patch6000: Set-relevant-g_log-domain-handlers-instead-of-a-defa.patch
Patch6001: Add-a-debug-argument-to-Librepolog-addHandler.patch
Patch6002: Add-a-logdebug-argument-to-hawkey.Sack.patch
BuildRequires: cmake gcc gcc-c++ libsolv-devel >= %{libsolv_version} pkgconfig(librepo) pkgconfig(check)
BuildRequires: pkgconfig(gio-unix-2.0) >= 2.46.0 pkgconfig(gtk-doc) pkgconfig(sqlite3) pkgconfig(json-c)
BuildRequires: rpm-devel >= 4.11.0 pkgconfig(cppunit) pkgconfig(smartcols)
@ -170,6 +174,9 @@ popd
%{python3_sitearch}/hawkey/
%changelog
* Sat Dec 21 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.22.0-9
- Not log DEBUG messages by default (RhBug:1355764)
* Sat Nov 9 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.22.0-8
- Type:bugfix
- Id:NA