Skip to content
Snippets Groups Projects

ConsoleLevel is now shared accross modules.

Merged Cyril Moineau requested to merge logIssue into dev
3 files
+ 55
6
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -21,7 +21,14 @@
@@ -21,7 +21,14 @@
#include "aidge/data/half_fmt.hpp"
#include "aidge/data/half_fmt.hpp"
#include "aidge/utils/Attributes.hpp"
#include "aidge/utils/Attributes.hpp"
 
#ifdef PYBIND
 
#include <pybind11/pybind11.h> // get_shared_data, set_shared_data, PyIsInitialized
 
#endif
 
namespace Aidge {
namespace Aidge {
 
#ifdef PYBIND
 
namespace py = pybind11;
 
#endif
/**
/**
* Helper to define a context anywhere, hiding the scoped variable name
* Helper to define a context anywhere, hiding the scoped variable name
* which has no relevance.
* which has no relevance.
@@ -126,8 +133,36 @@ class Log {
@@ -126,8 +133,36 @@ class Log {
*/
*/
static void setConsoleLevel(Level level) {
static void setConsoleLevel(Level level) {
mConsoleLevel = level;
mConsoleLevel = level;
}
// Note: In python each module has a compiled version of Log.
 
// This means each static instance is separated and does not communicate.
 
// To allow the communication between the different modules, we use PyCapsule.
 
// https://docs.python.org/3/extending/extending.html#providing-a-c-api-for-an-extension-module
 
#ifdef PYBIND
 
#define _CRT_SECURE_NO_WARNINGS
 
if (Py_IsInitialized()){
 
// Note: Setting mConsoleLevel and not level is important
 
// to avoid garbage collection of the pointer.
 
py::set_shared_data("consoleLevel", &mConsoleLevel);
 
}
 
#endif // PYBIND
 
}
 
/**
 
* @brief Get the curent Console Level.
 
*
 
* @return const Level
 
*/
 
static Level getConsoleLevel(){
 
#ifdef PYBIND
 
#define _CRT_SECURE_NO_WARNINGS
 
if (Py_IsInitialized()){
 
auto shared_data = reinterpret_cast<Level *>(py::get_shared_data("consoleLevel"));
 
if (shared_data)
 
mConsoleLevel = *shared_data;
 
}
 
#endif // PYBIND
 
return mConsoleLevel;
 
}
/**
/**
* Set or disable colors on console.
* Set or disable colors on console.
* Initial value should be assumed true.
* Initial value should be assumed true.
Loading