Python binding of FGLogger#1406
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1406 +/- ##
=======================================
Coverage 25.23% 25.23%
=======================================
Files 169 169
Lines 18631 18631
=======================================
Hits 4701 4701
Misses 13930 13930 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Looks good. |
|
Thanks. PR merged. |
|
Hmm... The CI is failing following the merge of this PR. This seems to be due to the changes introduced by the PR #1405 that trigger the following jsbsim/python/src/PyLogger.cxx Line 122 in fc8156d |
|
Need to display the |
I have submitted the PR #1413 that fixes the issue. |
This PR exposes the class
FGLoggerand the functionSetLoggerto the Python module to allow managing JSBSim logged output from Python.User manual
It defines the Python class
FGLoggerthat can be inherited and passed toset_logger:A trivial example is given in
jsbsim.pyx.in:then a class instance can be passed to JSBSim using
set_logger:Under the hood
PyLoggeris defined which inherits from the C++ classFGLogger. It basically passes the data received from the C++ code to the Python class that has been set viaset_logger.fpectlmodule.handExceptionManagement.hhave been protected against multiple inclusions using#ifdef FPECTLMODULE_Hand#ifdef EXCEPTIONMANAGEMENT_H.ExceptionManagement.hare now in the C++ namespaceJSBSim, especially since it uses quite generic names such asbase_error.PyObjectPtris defined that uses RAII to properly manage the different calls toPy_INCREFandPy_DECREF, calls which otherwise are a mess to manage.There is a subtlety in the order in which the objects are destroyed at exit. It happens that
Py_Finalize()is called before the C++ destructors so the instance of the C++ classPyLoggermay be destroyed after all the Python objects have been deleted which could result in a SEGFAULT.To prevent this error from happening a small function
_reset_logger()is passed toatexitin order to be called byPy_Finalize. This allows thePyLoggerinstance to be destroyed before the Python objects it is pointing to are destroyed themselves.