| 27 | } |
| 28 | |
| 29 | void BindLogging(py::module& m) { |
| 30 | py::classh<Logging> PyLogging(m, "logging", py::module_local()); |
| 31 | |
| 32 | py::enum_<Logging::LogSeverity>(PyLogging, "Level") |
| 33 | .value("INFO", Logging::LogSeverity::GLOG_INFO) |
| 34 | .value("WARNING", Logging::LogSeverity::GLOG_WARNING) |
| 35 | .value("ERROR", Logging::LogSeverity::GLOG_ERROR) |
| 36 | .value("FATAL", Logging::LogSeverity::GLOG_FATAL) |
| 37 | .export_values(); |
| 38 | |
| 39 | PyLogging.def_readwrite_static("minloglevel", &FLAGS_minloglevel) |
| 40 | .def_readwrite_static("stderrthreshold", &FLAGS_stderrthreshold) |
| 41 | .def_readwrite_static("log_dir", &FLAGS_log_dir) |
| 42 | .def_readwrite_static("logtostderr", &FLAGS_logtostderr) |
| 43 | .def_readwrite_static("alsologtostderr", &FLAGS_alsologtostderr) |
| 44 | .def_readwrite_static("verbose_level", &FLAGS_v) |
| 45 | .def_static( |
| 46 | "set_log_destination", |
| 47 | [](const Logging::LogSeverity severity, |
| 48 | const std::filesystem::path& path) { |
| 49 | google::SetLogDestination( |
| 50 | static_cast<google::LogSeverity>(severity), |
| 51 | path.string().c_str()); |
| 52 | }, |
| 53 | py::arg("level"), |
| 54 | py::arg("path")) |
| 55 | .def_static( |
| 56 | "verbose", |
| 57 | [](const int level, const std::string& msg) { |
| 58 | if (VLOG_IS_ON(level)) { |
| 59 | const auto frame = GetPythonCallFrame(); |
| 60 | google::LogMessage(frame.first.c_str(), frame.second).stream() |
| 61 | << msg; |
| 62 | } |
| 63 | }, |
| 64 | py::arg("level"), |
| 65 | py::arg("message")) |
| 66 | .def_static( |
| 67 | "info", |
| 68 | [](const std::string& msg) { |
| 69 | const auto frame = GetPythonCallFrame(); |
| 70 | google::LogMessage(frame.first.c_str(), frame.second).stream() |
| 71 | << msg; |
| 72 | }, |
| 73 | py::arg("message")) |
| 74 | .def_static( |
| 75 | "warning", |
| 76 | [](const std::string& msg) { |
| 77 | const auto frame = GetPythonCallFrame(); |
| 78 | google::LogMessage( |
| 79 | frame.first.c_str(), frame.second, google::GLOG_WARNING) |
| 80 | .stream() |
| 81 | << msg; |
| 82 | }, |
| 83 | py::arg("message")) |
| 84 | .def_static( |
| 85 | "error", |
| 86 | [](const std::string& msg) { |
no test coverage detected