- format_exception_func = PyObject_GetAttrString(traceback_module,
- traceback ? "format_exception" : "format_exception_only");
- if (!format_exception_func) {
- BT_LOGE_STR("Failed to log Python exception (could not find format_exception).");
- goto end;
- }
-
- if (!PyCallable_Check(format_exception_func)) {
- BT_LOGE_STR("Failed to log Python exception (format_exception is not callable).");
- goto end;
- }
-
- exc_str_list = PyObject_CallFunctionObjArgs(format_exception_func, type, value, traceback, NULL);
- if (!exc_str_list) {
- PyErr_Print();
- BT_LOGE_STR("Failed to log Python exception (call to format_exception failed).");
- goto end;
- }
-
- msg_buf = g_string_new(NULL);
-
- for (i = 0; i < PyList_Size(exc_str_list); i++) {
- PyObject *exc_str = PyList_GetItem(exc_str_list, i);
- const char *str = PyUnicode_AsUTF8(exc_str);
- if (!str) {
- BT_LOGE_STR("Failed to log Python exception (failed to convert exception to string).");
- goto end;
+ BT_LOG_WRITE(log_level, BT_LOG_TAG, "%s", gstr->str);
+
+ if (append_error) {
+ if (self_component_class) {
+ BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
+ self_component_class, "%s", gstr->str);
+ } else if (self_component) {
+ BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(
+ self_component, "%s", gstr->str);
+ } else if (self_message_iterator) {
+ BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
+ self_message_iterator, "%s", gstr->str);
+ } else {
+ BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
+ "Python", "%s", gstr->str);