2021-03-09 22:24:35 +00:00
|
|
|
#include <common.hpp>
|
2020-06-08 19:15:54 +00:00
|
|
|
#include <memory>
|
2022-07-19 18:22:38 +00:00
|
|
|
#include <llarp/util/logging.hpp>
|
2020-06-08 19:15:54 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
struct PyLogger
|
|
|
|
{
|
2022-07-19 18:22:38 +00:00
|
|
|
std::optional<llarp::log::Level> silenced;
|
2020-06-08 19:15:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
Logger_Init(py::module& mod)
|
|
|
|
{
|
|
|
|
py::class_<PyLogger>(mod, "LogContext")
|
|
|
|
.def(py::init<>())
|
|
|
|
.def_property(
|
|
|
|
"shutup",
|
2022-07-19 18:22:38 +00:00
|
|
|
[](PyLogger& self) { return self.silenced.has_value(); },
|
2020-06-08 19:15:54 +00:00
|
|
|
[](PyLogger& self, bool shutup) {
|
2022-07-19 18:22:38 +00:00
|
|
|
if (shutup and not self.silenced)
|
|
|
|
self.silenced = llarp::log::get_level_default();
|
|
|
|
else if (not shutup and self.silenced)
|
2020-06-08 19:15:54 +00:00
|
|
|
{
|
2022-07-19 18:22:38 +00:00
|
|
|
llarp::log::reset_level(*self.silenced);
|
|
|
|
self.silenced.reset();
|
2020-06-08 19:15:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} // namespace llarp
|