@@ -43,7 +43,13 @@ Logger_debug(LoggerObject *self, PyObject *args) {
43
43
if (!PyArg_ParseTuple (args, " s" , &msg)) {
44
44
return (0 );
45
45
}
46
- LOG_DEBUG (*kea_logger, DBGLVL_TRACE_BASIC, *kea_message_id).arg (string (msg));
46
+ try {
47
+ LOG_DEBUG (*kea_logger, DBGLVL_TRACE_BASIC, *kea_message_id).arg (string (msg));
48
+ }
49
+ catch (const exception &e) {
50
+ PyErr_SetString (PyExc_TypeError, e.what ());
51
+ return (0 );
52
+ }
47
53
48
54
Py_RETURN_NONE;
49
55
}
@@ -55,7 +61,13 @@ Logger_info(LoggerObject *self, PyObject *args) {
55
61
if (!PyArg_ParseTuple (args, " s" , &msg)) {
56
62
return (0 );
57
63
}
58
- LOG_INFO (*kea_logger, *kea_message_id).arg (string (msg));
64
+ try {
65
+ LOG_INFO (*kea_logger, *kea_message_id).arg (string (msg));
66
+ }
67
+ catch (const exception &e) {
68
+ PyErr_SetString (PyExc_TypeError, e.what ());
69
+ return (0 );
70
+ }
59
71
60
72
Py_RETURN_NONE;
61
73
}
@@ -67,7 +79,13 @@ Logger_warn(LoggerObject *self, PyObject *args) {
67
79
if (!PyArg_ParseTuple (args, " s" , &msg)) {
68
80
return (0 );
69
81
}
70
- LOG_WARN (*kea_logger, *kea_message_id).arg (string (msg));
82
+ try {
83
+ LOG_WARN (*kea_logger, *kea_message_id).arg (string (msg));
84
+ }
85
+ catch (const exception &e) {
86
+ PyErr_SetString (PyExc_TypeError, e.what ());
87
+ return (0 );
88
+ }
71
89
72
90
Py_RETURN_NONE;
73
91
}
@@ -80,7 +98,13 @@ Logger_error(LoggerObject *self, PyObject *args) {
80
98
if (!PyArg_ParseTuple (args, " s" , &msg)) {
81
99
return (0 );
82
100
}
83
- LOG_ERROR (*kea_logger, *kea_message_id).arg (string (msg));
101
+ try {
102
+ LOG_ERROR (*kea_logger, *kea_message_id).arg (string (msg));
103
+ }
104
+ catch (const exception &e) {
105
+ PyErr_SetString (PyExc_TypeError, e.what ());
106
+ return (0 );
107
+ }
84
108
85
109
Py_RETURN_NONE;
86
110
}
@@ -92,7 +116,13 @@ Logger_fatal(LoggerObject *self, PyObject *args) {
92
116
if (!PyArg_ParseTuple (args, " s" , &msg)) {
93
117
return (0 );
94
118
}
95
- LOG_FATAL (*kea_logger, *kea_message_id).arg (string (msg));
119
+ try {
120
+ LOG_FATAL (*kea_logger, *kea_message_id).arg (string (msg));
121
+ }
122
+ catch (const exception &e) {
123
+ PyErr_SetString (PyExc_TypeError, e.what ());
124
+ return (0 );
125
+ }
96
126
97
127
Py_RETURN_NONE;
98
128
}
@@ -105,22 +135,26 @@ Logger_exception(LoggerObject *self, PyObject *args) {
105
135
return (0 );
106
136
}
107
137
PyObject *exc_type, *exc_value, *exc_traceback;
108
- string traceback;
109
138
PyErr_GetExcInfo (&exc_type, &exc_value, &exc_traceback);
110
- if (!format_python_traceback (exc_type, exc_value, exc_traceback, traceback)) {
111
- if (strlen (msg) == 0 ) {
112
- LOG_ERROR (*kea_logger, *kea_message_id).arg (traceback);
139
+ try {
140
+ string traceback;
141
+ // steals reference to exc_* objects
142
+ if (!format_python_traceback (exc_type, exc_value, exc_traceback, traceback)) {
143
+ if (strlen (msg) == 0 ) {
144
+ LOG_ERROR (*kea_logger, *kea_message_id).arg (traceback);
145
+ }
146
+ else {
147
+ LOG_ERROR (*kea_logger, *kea_message_id).arg (string (msg) + " \n " + traceback);
148
+ }
113
149
}
114
150
else {
115
- LOG_ERROR (*kea_logger, *kea_message_id).arg (string (msg) + " \n " + traceback );
151
+ LOG_ERROR (*kea_logger, *kea_message_id).arg (string (msg));
116
152
}
117
153
}
118
- else {
119
- LOG_ERROR (*kea_logger, *kea_message_id).arg (string (msg));
154
+ catch (const exception &e) {
155
+ PyErr_SetString (PyExc_TypeError, e.what ());
156
+ return (0 );
120
157
}
121
- Py_XDECREF (exc_type);
122
- Py_XDECREF (exc_value);
123
- Py_XDECREF (exc_traceback);
124
158
125
159
Py_RETURN_NONE;
126
160
}
0 commit comments