-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger.hpp
More file actions
39 lines (35 loc) · 1.22 KB
/
Copy pathlogger.hpp
File metadata and controls
39 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef HTOOL_PYTHON_MISC_LOGGER_CPP
#define HTOOL_PYTHON_MISC_LOGGER_CPP
#include <htool/misc/logger.hpp>
#include <pybind11/pybind11.h>
namespace py = pybind11;
// Delegates formatting and filtering to python logging module
// mapping python logging level to Htool logging level
class PythonLoggerWriter : public htool::IObjectWriter {
public:
void write(htool::LogLevel logging_level, const std::string &message) override {
py::object logging_module = py::module::import("logging");
py::object logger = logging_module.attr("getLogger")("Htool");
switch (logging_level) {
case htool::LogLevel::CRITICAL:
logger.attr("critical")(message);
break;
case htool::LogLevel::ERROR:
logger.attr("error")(message);
break;
case htool::LogLevel::WARNING:
logger.attr("warning")(message);
break;
case htool::LogLevel::DEBUG:
logger.attr("debug")(message);
break;
case htool::LogLevel::INFO:
logger.attr("info")(message);
break;
}
}
// LCOV_EXCL_START
void set_log_level(htool::LogLevel log_level) override {}
// LCOV_EXCL_STOP
};
#endif