Projet

Général

Profil

0006-python-simplify-get_logger_object-44287.patch

Benjamin Dauvergne, 20 juin 2020 12:44

Télécharger (1,87 ko)

Voir les différences:

Subject: [PATCH 06/21] python: simplify get_logger_object (#44287)

 bindings/python/wrapper_top.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
bindings/python/wrapper_top.c
676 676

  
677 677
static PyObject *get_logger_object(const char *domain) {
678 678
	static PyObject *_logger_object = NULL;
679
	PyObject *lasso_module = NULL;
680
	PyObject *logging_module = NULL;
679 681

  
680
	PyObject *logging_module = PyImport_ImportModule("lasso");
681

  
682
	if (logging_module) {
683
		_logger_object = PyObject_GetAttrString(logging_module, "logger");
684
		Py_DECREF(logging_module);
682
	lasso_module = PyImport_ImportModule("lasso");
683
	if (lasso_module && PyObject_HasAttrString(lasso_module, "logger")) {
684
		_logger_object = PyObject_GetAttrString(lasso_module, "logger");
685 685
		if (_logger_object)
686 686
			goto exit;
687 687
	}
688
	/* XXX: needed so that PyImport_ImportModule("logging") always works */
689
	logging_module = PyImport_ImportModule("sys");
688

  
689
	logging_module = PyImport_ImportModule("logging");
690 690
	if (logging_module) {
691
		Py_DECREF(logging_module);
691
		_logger_object = PyObject_CallMethod(logging_module, "getLogger", "s", domain);
692
	}
693
exit:
694
	if (lasso_module) {
695
		Py_DECREF(lasso_module);
692 696
	}
693
	logging_module = PyImport_ImportModule("logging");
694 697
	if (logging_module) {
695
		_logger_object = PyObject_CallMethod(logging_module, "getLogger",
696
				"s#", domain, strlen(domain));
697 698
		Py_DECREF(logging_module);
698 699
	}
699
exit:
700 700
	if (_logger_object == Py_None) {
701 701
		Py_DECREF(_logger_object);
702 702
		_logger_object = NULL;
703
-