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);
METH_VARARGS|METH_KEYWORDS,
NULL
},
- {
- "_log",
- (PyCFunction)Pakfire_log,
- METH_VARARGS|METH_KEYWORDS,
- NULL
- },
{ NULL },
};
// 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);
#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);
pakfire_key_unref;
# log
- pakfire_log;
pakfire_log_get_priority;
pakfire_log_set_function;
pakfire_log_set_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;
import string
from . import _pakfire
-from . import logger
from . import util
from .system import system
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
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"