HAL
log.cpp
Go to the documentation of this file.
2 
4 
5 #include <iostream>
6 
7 namespace hal
8 {
10  {
11  auto log_manager = py::class_<LogManager, RawPtrWrapper<LogManager>>(m, "LogManager");
12 
13  log_manager.def(py::init([]() {
15  return RawPtrWrapper<LogManager>(lm);
16  }));
17 
18  log_manager.def("set_file_name", &LogManager::set_file_name, py::arg("file_name") = "", R"(
19  Set the log file name.
20  If file_name is empty, the default log file will be used.
21 
22  :param str file_name: The desired log file.
23  )");
24 
25  log_manager.def("set_level_of_channel", &LogManager::set_level_of_channel, py::arg("channel_name"), py::arg("level"), R"(
26  Set a channel's severity level.
27 
28  :param str channel_name: Name of the channel.
29  :param str level: The severity level, one out of {}.
30  )");
31 
32  log_manager.def_static(
33  "get_channel", [](std::string channel_name) { LogManager::get_instance()->get_channel(channel_name); }, py::arg("channel_name"), R"(
34  Main purpose of get_channel() method in PYTHON is to create channel if not existing.
35 
36  :param str channel_name: Name of the channel.
37  )");
38 
39  log_manager.def("get_channels", &LogManager::get_channels, R"(
40  Returns all channels' names.
41 
42  :returns: Set of channel names.
43  :rtype: set[str]
44  )");
45 
46  log_manager.def("get_available_log_levels", &LogManager::get_available_log_levels, R"(
47  Get all available severity levels.
48 
49  :returns: Set of severity levels.
50  :rtype: set[str]
51  )");
52 
53  log_manager.def("activate_channel", &LogManager::activate_channel, py::arg("channel_name"), R"(
54  Activate a channel.
55  By default all channels are active.
56 
57  :param str channel_name: The name of the channel.
58  )");
59 
60  log_manager.def("activate_all_channels", &LogManager::activate_all_channels, R"(
61  Activate all logging channels.
62  )");
63 
64  log_manager.def("deactivate_channel", &LogManager::deactivate_channel, py::arg("channel_name"), R"(
65  Deactivate a channel suppressing all output.
66 
67  :param str channel_name: The name of the channel.
68  )");
69 
70  log_manager.def("deactivate_all_channels", &LogManager::deactivate_all_channels, R"(
71  Deactivate all logging channels.
72  )");
73 
74  log_manager.def("get_default_sinks", &LogManager::get_default_sinks, R"(
75  Get the list of default sinks that are added to each newly created logger by default.
76 
77  :returns: list of default sinks.
78  :rtype: list[hal_py.log_sink]
79  )");
80 
81  log_manager.def("remove_sink_from_default", &LogManager::remove_sink_from_default, py::arg("sink_type"), R"(
82  Removes all sinks of the specified type from the default sinks that get a added to each newly created channel by default.
83 
84  :param str sink_type: The type of sink to remove.
85  )");
86 
87  auto log_sink = py::class_<LogManager::log_sink, RawPtrWrapper<LogManager::log_sink>>(log_manager, "log_sink");
88 
89  log_sink.def_readonly("sink_type", &LogManager::log_sink::sink_type, R"(
90  The type of the sink.
91 
92  :type: str
93  )");
94 
95  log_sink.def_readonly("is_file_sink", &LogManager::log_sink::is_file_sink, R"(
96  Boolean indication whether sink is a file sink.
97 
98  :type: bool
99  )");
100 
101  log_sink.def_readonly("truncate", &LogManager::log_sink::truncate, R"(
102  Truncate option passed to sink.
103 
104  :type: bool
105  )");
106 
107  log_sink.def_readonly("path", &LogManager::log_sink::path, R"(
108  The file path incase the sink is a file sink.
109 
110  :type: pathlib.Path
111  )");
112  }
113 } // namespace hal
void set_level_of_channel(const std::string &channel_name, const std::string &level)
Definition: log.cpp:164
void activate_channel(const std::string &channel_name)
Definition: log.cpp:178
void deactivate_all_channels()
Definition: log.cpp:196
void deactivate_channel(const std::string &channel_name)
Definition: log.cpp:191
void activate_all_channels()
Definition: log.cpp:183
std::vector< std::shared_ptr< hal::LogManager::log_sink > > get_default_sinks()
Definition: log.cpp:204
std::set< std::string > get_channels() const
Definition: log.cpp:90
std::shared_ptr< spdlog::logger > get_channel(const std::string &channel_name="stdout")
Definition: log.cpp:75
void remove_sink_from_default(const std::string &sink_type)
Definition: log.cpp:209
static LogManager * get_instance(const std::filesystem::path &file_name="")
Definition: log.cpp:61
std::set< std::string > get_available_log_levels() const
Definition: log.cpp:283
void set_file_name(const std::filesystem::path &file_name)
Definition: log.cpp:291
std::unique_ptr< T, py::nodelete > RawPtrWrapper
void log_init(py::module &m)
Definition: log.cpp:9
const Module * module(const Gate *g, const NodeBoxes &boxes)
std::string sink_type
Definition: log.h:110
std::filesystem::path path
Definition: log.h:113