forked from aldebaran/libqi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpylog.cpp
More file actions
89 lines (79 loc) · 3.23 KB
/
pylog.cpp
File metadata and controls
89 lines (79 loc) · 3.23 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
** Copyright (C) 2020 SoftBank Robotics Europe
** See COPYING for the license
*/
#include <qipython/pylog.hpp>
#include <qipython/common.hpp>
#include <qipython/pyguard.hpp>
#include <qi/application.hpp>
#include <qi/log.hpp>
#include <qi/os.hpp>
#include <pybind11/pybind11.h>
namespace py = pybind11;
namespace qi
{
namespace py
{
void exportLog(::py::module& m)
{
using namespace ::py;
using namespace ::py::literals;
GILAcquire lock;
enum_<LogLevel>(m, "LogLevel")
.value("Silent", LogLevel_Silent)
.value("Fatal", LogLevel_Fatal)
.value("Error", LogLevel_Error)
.value("Warning", LogLevel_Warning)
.value("Info", LogLevel_Info)
.value("Verbose", LogLevel_Verbose)
.value("Debug", LogLevel_Debug);
m.def("pylog",
[](LogLevel level, const std::string& name, const std::string& message,
const std::string& file, const std::string& func, int line) {
log::log(level, name.c_str(), message.c_str(), file.c_str(),
func.c_str(), line);
},
call_guard<GILRelease>(), "level"_a, "name"_a, "message"_a,
"file"_a, "func"_a, "line"_a);
m.def("setFilters",
[](const std::string& filters) { log::addFilters(filters); },
call_guard<GILRelease>(), "filters"_a,
doc("Set log filtering options.\n"
"Each rule can be:\n\n"
" +CAT: enable category CAT\n\n"
" -CAT: disable category CAT\n\n"
" CAT=level : set category CAT to level\n\n"
"Each category can include a '*' for globbing.\n"
"\n"
".. code-block:: python\n"
"\n"
" qi.logging.setFilter(\"qi.*=debug:-qi.foo:+qi.foo.bar\")\n"
"\n"
"(all qi.* logs in info, remove all qi.foo logs except qi.foo.bar)\n"
":param filters: List of rules separated by colon."));
m.def("setContext", [](int context) { qi::log::setContext(context); },
call_guard<GILRelease>(), "context"_a,
doc(" 1 : Verbosity \n"
" 2 : ShortVerbosity \n"
" 4 : Date \n"
" 8 : ThreadId \n"
" 16 : Category \n"
" 32 : File \n"
" 64 : Function \n"
" 128: EndOfLine \n\n"
" Some useful values for context are: \n"
" 26 : (verb+threadId+cat) \n"
" 30 : (verb+threadId+date+cat) \n"
" 126: (verb+threadId+date+cat+file+fun) \n"
" 254: (verb+threadId+date+cat+file+fun+eol)\n\n"
":param context: A bitfield (sum of described values)."));
m.def("setLevel", [](LogLevel level) { log::setLogLevel(level); },
call_guard<GILRelease>(), "level"_a,
doc(
"Sets the threshold for the logger to level. "
"Logging messages which are less severe than level will be ignored. "
"Note that the logger is created with level INFO.\n"
":param level: The minimum log level."));
}
} // namespace py
} // namespace qi