diff --git a/include/hal_core/python_bindings/python_bindings.h b/include/hal_core/python_bindings/python_bindings.h index 5995eb2e07c..bebfee4fb82 100644 --- a/include/hal_core/python_bindings/python_bindings.h +++ b/include/hal_core/python_bindings/python_bindings.h @@ -78,13 +78,6 @@ namespace hal { - /** - * Wrapper for LogManager::set_level_of_channel() - * @param channel_name - Name of log channel - * @param level - One of trace, debug, info, warn, err, critical, off - */ - void set_log_level_of_channel(std::string channel_name, std::string level); - namespace py = pybind11; /** @@ -326,6 +319,12 @@ namespace hal */ void netlist_modification_decorator_init(py::module& m); + /** + * Initializes Python bindings for the HAL LogManager in a python module. + * + * @param[in] m - the python module + */ + void log_init(py::module& m); /** * @} */ diff --git a/plugins/gui/src/python/python_thread.cpp b/plugins/gui/src/python/python_thread.cpp index 9a9f3e9ee91..c6b4bf28d65 100644 --- a/plugins/gui/src/python/python_thread.cpp +++ b/plugins/gui/src/python/python_thread.cpp @@ -15,12 +15,12 @@ namespace hal { : QThread(parent), mScript(script), mSingleStatement(singleStatement), mAbortRequested(false), mSpamCount(0) { - qDebug() << "+++PythonThread" << hex << (quintptr) this; + // qDebug() << "+++PythonThread" << hex << (quintptr) this; } PythonThread::~PythonThread() { - qDebug() << "---PythonThread" << hex << (quintptr) this; + // qDebug() << "---PythonThread" << hex << (quintptr) this; } void PythonThread::run() diff --git a/src/python_bindings/bindings/log.cpp b/src/python_bindings/bindings/log.cpp new file mode 100644 index 00000000000..fd7fb01ea03 --- /dev/null +++ b/src/python_bindings/bindings/log.cpp @@ -0,0 +1,41 @@ +#include "hal_core/python_bindings/python_bindings.h" +#include "hal_core/utilities/log.h" +#include + +namespace hal +{ + void log_init(py::module& m) + { + py::class_>(m, "LogManager") + .def(py::init([](){ + LogManager* lm = LogManager::get_instance(); + return RawPtrWrapper(lm); })) + + .def("set_level_of_channel", &LogManager::set_level_of_channel, py::arg("channel_name"), py::arg("level"), R"( + Set a channel's severity level. + + :param str channel_name: Name of the channel. + :param str level: The severity level, one out of {}. + )") + + .def_static("get_channel", [](std::string channel_name) { LogManager::get_instance()->get_channel(channel_name); } , py::arg("channel_name"), R"( + Main purpose of get_channel() method in PYTHON is to create channel if not existing. + + :param str channel_name: Name of the channel. + )") + + .def("get_channels", &LogManager::get_channels, R"( + Returns all channels' names. + + :returns: Set of channel names. + :rtype: set[str] + )") + + .def("get_available_log_levels", &LogManager::get_available_log_levels, R"( + Get all available severity levels. + + :returns: Set of severity levels. + :rtype: set[str] + )"); + } +} diff --git a/src/python_bindings/python_bindings.cpp b/src/python_bindings/python_bindings.cpp index 047a0c24ebc..7e39d491c0a 100644 --- a/src/python_bindings/python_bindings.cpp +++ b/src/python_bindings/python_bindings.cpp @@ -2,13 +2,6 @@ namespace hal { - void set_log_level_of_channel(std::string channel_name, std::string level) - { - LogManager* lm = LogManager::get_instance(); - log_info(channel_name, "Set log level of channel '{}' to '{}'.", channel_name, level); - if (lm) lm->set_level_of_channel(channel_name,level); - } - #ifdef PYBIND11_MODULE PYBIND11_MODULE(hal_py, m) { @@ -22,13 +15,6 @@ namespace hal m.def( "log_info", [](std::string& message) { log_info("python_context", message); }, R"( some documentation info)"); - m.def("set_log_level_of_channel", set_log_level_of_channel, py::arg("channel_name"), py::arg("level"), R"( - Set log level for channel. - - :param str channel_name: Name of channel. - :param str level: Selected level, one out of [trace, debug, info, warn, err, critical, off]. - )"); - data_container_init(m); core_utils_init(m); @@ -89,6 +75,8 @@ namespace hal netlist_modification_decorator_init(m); + log_init(m); + #ifndef PYBIND11_MODULE return m.ptr(); #endif // PYBIND11_MODULE