qlogging.sip 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // qlogging.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtCore Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. %ModuleCode
  22. #include <qlogging.h>
  23. %End
  24. enum QtMsgType
  25. {
  26. QtDebugMsg,
  27. QtWarningMsg,
  28. QtCriticalMsg,
  29. QtFatalMsg,
  30. QtSystemMsg,
  31. QtInfoMsg,
  32. };
  33. class QMessageLogContext /NoDefaultCtors/
  34. {
  35. %TypeHeaderCode
  36. #include <qlogging.h>
  37. %End
  38. public:
  39. %If (Qt_6_8_0 -)
  40. static const int CurrentVersion;
  41. %End
  42. int line;
  43. const char *file;
  44. const char *function;
  45. const char *category;
  46. };
  47. class QMessageLogger
  48. {
  49. %TypeHeaderCode
  50. #include <qlogging.h>
  51. %End
  52. public:
  53. QMessageLogger();
  54. QMessageLogger(const char *file, int line, const char *function);
  55. QMessageLogger(const char *file, int line, const char *function, const char *category);
  56. void debug(const char *msg) const /ReleaseGIL/;
  57. %MethodCode
  58. Py_BEGIN_ALLOW_THREADS
  59. sipCpp->debug("%s", a0);
  60. Py_END_ALLOW_THREADS
  61. %End
  62. void debug(const QLoggingCategory &cat, const char *msg) const /ReleaseGIL/;
  63. %MethodCode
  64. Py_BEGIN_ALLOW_THREADS
  65. sipCpp->debug(*a0, "%s", a1);
  66. Py_END_ALLOW_THREADS
  67. %End
  68. void info(const char *msg) const /ReleaseGIL/;
  69. %MethodCode
  70. Py_BEGIN_ALLOW_THREADS
  71. sipCpp->info("%s", a0);
  72. Py_END_ALLOW_THREADS
  73. %End
  74. void info(const QLoggingCategory &cat, const char *msg) const /ReleaseGIL/;
  75. %MethodCode
  76. Py_BEGIN_ALLOW_THREADS
  77. sipCpp->info(*a0, "%s", a1);
  78. Py_END_ALLOW_THREADS
  79. %End
  80. void warning(const char *msg) const /ReleaseGIL/;
  81. %MethodCode
  82. Py_BEGIN_ALLOW_THREADS
  83. sipCpp->warning("%s", a0);
  84. Py_END_ALLOW_THREADS
  85. %End
  86. void warning(const QLoggingCategory &cat, const char *msg) const /ReleaseGIL/;
  87. %MethodCode
  88. Py_BEGIN_ALLOW_THREADS
  89. sipCpp->warning(*a0, "%s", a1);
  90. Py_END_ALLOW_THREADS
  91. %End
  92. void critical(const char *msg) const /ReleaseGIL/;
  93. %MethodCode
  94. Py_BEGIN_ALLOW_THREADS
  95. sipCpp->critical("%s", a0);
  96. Py_END_ALLOW_THREADS
  97. %End
  98. void critical(const QLoggingCategory &cat, const char *msg) const /ReleaseGIL/;
  99. %MethodCode
  100. Py_BEGIN_ALLOW_THREADS
  101. sipCpp->critical(*a0, "%s", a1);
  102. Py_END_ALLOW_THREADS
  103. %End
  104. void fatal(const char *msg) const /ReleaseGIL/;
  105. %MethodCode
  106. Py_BEGIN_ALLOW_THREADS
  107. sipCpp->fatal("%s", a0);
  108. Py_END_ALLOW_THREADS
  109. %End
  110. %If (Qt_6_5_0 -)
  111. void fatal(const QLoggingCategory &cat, const char *msg) const /ReleaseGIL/;
  112. %MethodCode
  113. Py_BEGIN_ALLOW_THREADS
  114. sipCpp->fatal(*a0, "%s", a1);
  115. Py_END_ALLOW_THREADS
  116. %End
  117. %End
  118. private:
  119. QMessageLogger(const QMessageLogger &);
  120. };
  121. void qCritical(const char *msg) /ReleaseGIL/;
  122. %MethodCode
  123. const char *file, *function;
  124. int line = qpycore_current_context(&file, &function);
  125. Py_BEGIN_ALLOW_THREADS
  126. QMessageLogger(file, line, function).critical("%s", a0);
  127. Py_END_ALLOW_THREADS
  128. %End
  129. void qDebug(const char *msg) /ReleaseGIL/;
  130. %MethodCode
  131. const char *file, *function;
  132. int line = qpycore_current_context(&file, &function);
  133. Py_BEGIN_ALLOW_THREADS
  134. QMessageLogger(file, line, function).debug("%s", a0);
  135. Py_END_ALLOW_THREADS
  136. %End
  137. void qFatal(const char *msg) /ReleaseGIL/;
  138. %MethodCode
  139. const char *file, *function;
  140. int line = qpycore_current_context(&file, &function);
  141. Py_BEGIN_ALLOW_THREADS
  142. QMessageLogger(file, line, function).fatal("%s", a0);
  143. Py_END_ALLOW_THREADS
  144. %End
  145. void qInfo(const char *msg) /ReleaseGIL/;
  146. %MethodCode
  147. const char *file, *function;
  148. int line = qpycore_current_context(&file, &function);
  149. Py_BEGIN_ALLOW_THREADS
  150. QMessageLogger(file, line, function).info("%s", a0);
  151. Py_END_ALLOW_THREADS
  152. %End
  153. void qWarning(const char *msg) /ReleaseGIL/;
  154. %MethodCode
  155. const char *file, *function;
  156. int line = qpycore_current_context(&file, &function);
  157. Py_BEGIN_ALLOW_THREADS
  158. QMessageLogger(file, line, function).warning("%s", a0);
  159. Py_END_ALLOW_THREADS
  160. %End
  161. SIP_PYCALLABLE qInstallMessageHandler(SIP_PYCALLABLE /AllowNone,TypeHint="Optional[Callable[[QtMsgType, QMessageLogContext, QString], None]]"/) /TypeHint="Optional[Callable[[QtMsgType, QMessageLogContext, QString], None]]"/;
  162. %MethodCode
  163. // Treat None as the default handler.
  164. QtMessageHandler old = qInstallMessageHandler((a0 != Py_None) ? qtcore_MessageHandler : 0);
  165. // If we recognise the old handler, then return it. Otherwise return
  166. // the default handler. This doesn't exactly mimic the Qt behaviour
  167. // but it is probably close enough for the way it will be used.
  168. sipRes = (old == qtcore_MessageHandler) ? qtcore_PyMessageHandler : Py_None;
  169. Py_INCREF(sipRes);
  170. // Save the new Python handler.
  171. Py_XDECREF(qtcore_PyMessageHandler);
  172. qtcore_PyMessageHandler = a0;
  173. Py_INCREF(qtcore_PyMessageHandler);
  174. %End
  175. // Module code needed by qInstallMessageHandler().
  176. %ModuleCode
  177. // The user supplied Python handler.
  178. static PyObject *qtcore_PyMessageHandler = 0;
  179. // The C++ wrapper around the Python handler.
  180. static void qtcore_MessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
  181. {
  182. PyObject *res;
  183. SIP_BLOCK_THREADS
  184. res = sipCallMethod(0, qtcore_PyMessageHandler, "FDD", type, sipType_QtMsgType, &context, sipType_QMessageLogContext, NULL, &msg, sipType_QString, NULL);
  185. Py_XDECREF(res);
  186. if (res != NULL && res != Py_None)
  187. {
  188. PyErr_SetString(PyExc_TypeError, "invalid result type from PyQt message handler");
  189. res = NULL;
  190. }
  191. if (res == NULL)
  192. pyqt6_err_print();
  193. SIP_UNBLOCK_THREADS
  194. }
  195. %End
  196. void qSetMessagePattern(const QString &messagePattern);
  197. QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &buf);