]> git.ipfire.org Git - pakfire.git/commitdiff
Drop python to libpakfire logging layer
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Jun 2021 15:31:47 +0000 (15:31 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Jun 2021 15:31:47 +0000 (15:31 +0000)
Since most code is now implemented in C, we do not need to send log
messages back and forth between Python and C.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/libpakfire.sym
src/libpakfire/pakfire.c
src/pakfire/base.py
src/pakfire/logger.py

index eb814458c95e54609552767754bd94f8f4a7425b..32893cf500ff05352a721c50d5017b491e521a53 100644 (file)
@@ -176,27 +176,6 @@ static PyObject* Pakfire_repr(PakfireObject* self) {
        return PyUnicode_FromFormat("<_pakfire.Pakfire %s (%s)>", path, arch);
 }
 
-static PyObject* Pakfire_log(PakfireObject* self, PyObject* args, PyObject* kwds) {
-       char* kwlist[] = { "priority", "message", "filename", "lineno", "function", NULL };
-
-       int priority;
-       const char* message;
-
-       const char* filename = NULL;
-       int lineno = 0;
-       const char* function = NULL;
-
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "is|sis", kwlist, &priority, &message,
-                       &filename, &lineno, &function))
-               return NULL;
-
-       // Send message to the pakfire logger
-       if (pakfire_log_get_priority(self->pakfire) >= priority)
-               pakfire_log(self->pakfire, priority, filename, lineno, function, "%s\n", message);
-
-       Py_RETURN_NONE;
-}
-
 static PyObject* Pakfire_get_path(PakfireObject* self) {
     const char* path = pakfire_get_path(self->pakfire);
 
@@ -967,12 +946,6 @@ static struct PyMethodDef Pakfire_methods[] = {
                METH_VARARGS|METH_KEYWORDS,
                NULL
        },
-       {
-               "_log",
-               (PyCFunction)Pakfire_log,
-               METH_VARARGS|METH_KEYWORDS,
-               NULL
-       },
        { NULL },
 };
 
index 1669925ed71400075fa17877d4d4a853af086502..7fb2e72ac443c8b0566dd43486042935985a7a84 100644 (file)
@@ -71,10 +71,6 @@ int pakfire_cache_destroy(Pakfire pakfire, const char* path);
 
 // Logging
 
-void pakfire_log(Pakfire pakfire, int priority, const char *file,
-       int line, const char *fn, const char *format, ...)
-       __attribute__((format(printf, 6, 7)));
-
 int pakfire_log_get_priority(Pakfire pakfire);
 void pakfire_log_set_priority(Pakfire pakfire, int priority);
 
@@ -95,6 +91,10 @@ int pakfire_update(Pakfire pakfire, const char** packages, int flags, int* chang
 
 #include <pakfire/config.h>
 
+void pakfire_log(Pakfire pakfire, int priority, const char *file,
+       int line, const char *fn, const char *format, ...)
+       __attribute__((format(printf, 6, 7)));
+
 int pakfire_has_flag(Pakfire pakfire, int flag);
 
 struct pakfire_config* pakfire_get_config(Pakfire pakfire);
index f38d80bc98187ae0482262ee276a9d6bb8231630..02c0e05f581658b69501084b2cefb3c280c63b4d 100644 (file)
@@ -128,7 +128,6 @@ global:
        pakfire_key_unref;
 
        # log
-       pakfire_log;
        pakfire_log_get_priority;
        pakfire_log_set_function;
        pakfire_log_set_priority;
index 82cdac8559bb2dfed0d6c85c597281641b7a7d9a..4347242d38dcc905f23810360de6ee18bf089561 100644 (file)
@@ -1418,7 +1418,7 @@ PAKFIRE_EXPORT void pakfire_log_set_priority(Pakfire pakfire, int priority) {
        pakfire->log_priority = priority;
 }
 
-PAKFIRE_EXPORT void pakfire_log(Pakfire pakfire, int priority, const char* file, int line,
+void pakfire_log(Pakfire pakfire, int priority, const char* file, int line,
                const char* fn, const char* format, ...) {
        va_list args;
 
index 0b4b6663c00842af892a8a26e57fa4c94a845f70..8f5b8665e8aff3a5b924b959372456ba30df58b9 100644 (file)
@@ -25,7 +25,6 @@ import random
 import string
 
 from . import _pakfire
-from . import logger
 from . import util
 
 from .system import system
@@ -36,25 +35,6 @@ from .i18n import _
 class Pakfire(_pakfire.Pakfire):
        __version__ = PAKFIRE_VERSION
 
-       def __init__(self, path=None, arch=None, conf=None, offline=False, **kwargs):
-               _pakfire.Pakfire.__init__(self, path, arch, conf=conf, offline=offline, **kwargs)
-
-               # Initialise logging system
-               self.log = self._setup_logger()
-
-       def _setup_logger(self):
-               log = logging.getLogger("pakfire")
-               log.propagate = 0
-
-               # Always process all messages (include debug)
-               log.setLevel(logging.DEBUG)
-
-               # Pass everything down to libpakfire
-               handler = logger.PakfireLogHandler(self)
-               log.addHandler(handler)
-
-               return log
-
        def __enter__(self):
                """
                        Called to initialize this Pakfire instance when
index ecc7988744383645913876a6161f3b61e2576d59..92ac94d154e5b040f9b3040c274fa0721462ea7f 100644 (file)
@@ -23,40 +23,6 @@ import logging
 import sys
 import time
 
-class PakfireLogHandler(logging.Handler):
-       LOG_EMERG     = 0       #  system is unusable
-       LOG_ALERT     = 1       #  action must be taken immediately
-       LOG_CRIT      = 2       #  critical conditions
-       LOG_ERR       = 3       #  error conditions
-       LOG_WARNING   = 4       #  warning conditions
-       LOG_NOTICE    = 5       #  normal but significant condition
-       LOG_INFO      = 6       #  informational
-       LOG_DEBUG     = 7       #  debug-level messages
-
-       priority_map = {
-               "DEBUG"    : LOG_DEBUG,
-               "INFO"     : LOG_INFO,
-               "WARNING"  : LOG_WARNING,
-               "ERROR"    : LOG_ERR,
-               "CRITICAL" : LOG_CRIT,
-       }
-
-       def __init__(self, pakfire):
-               logging.Handler.__init__(self)
-
-               self.pakfire = pakfire
-
-       def emit(self, record):
-               line = self.format(record)
-               prio = self._get_priority(record.levelname)
-
-               self.pakfire._log(prio, line, filename=record.pathname,
-                       lineno=record.lineno, function=record.funcName)
-
-       def _get_priority(self, level):
-               return self.priority_map.get(level, self.LOG_WARNING)
-
-
 class BuildFormatter(logging.Formatter):
        def __init__(self):
                self._fmt = "[%(asctime)s] %(message)s"