From: Michael Tremer Date: Tue, 15 Jun 2021 15:31:47 +0000 (+0000) Subject: Drop python to libpakfire logging layer X-Git-Tag: 0.9.28~1236 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9f2fb43fb5de573078ba4068e81224488e2d290;p=pakfire.git Drop python to libpakfire logging layer 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 --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index eb814458c..32893cf50 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -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 }, }; diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 1669925ed..7fb2e72ac 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -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 +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); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index f38d80bc9..02c0e05f5 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -128,7 +128,6 @@ global: pakfire_key_unref; # log - pakfire_log; pakfire_log_get_priority; pakfire_log_set_function; pakfire_log_set_priority; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 82cdac855..4347242d3 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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; diff --git a/src/pakfire/base.py b/src/pakfire/base.py index 0b4b6663c..8f5b8665e 100644 --- a/src/pakfire/base.py +++ b/src/pakfire/base.py @@ -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 diff --git a/src/pakfire/logger.py b/src/pakfire/logger.py index ecc798874..92ac94d15 100644 --- a/src/pakfire/logger.py +++ b/src/pakfire/logger.py @@ -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"