Mantid
Loading...
Searching...
No Matches
Logger.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9#include <boost/python/class.hpp>
10#include <boost/python/make_constructor.hpp>
11#include <boost/python/reference_existing_object.hpp>
12#include <boost/python/register_ptr_to_python.hpp>
13#include <memory>
14
17using namespace boost::python;
18using LoggerMsgFunction = void (Logger::*)(const std::string &);
19using LoggerFlushFunction = void (Logger::*)();
20
21namespace {
27std::shared_ptr<Logger> getLogger(const std::string &name) {
28 if (PyErr_Warn(PyExc_DeprecationWarning, "Logger.get(\"name\") is deprecated. "
29 "Simply use Logger(\"name\") instead") < 0)
30 throw boost::python::error_already_set();
31 return std::make_shared<Logger>(name);
32}
33
34std::shared_ptr<Logger> create(const std::string &name) { return std::make_shared<Logger>(name); }
35
36void fatal(Logger *self, const std::string &message) {
38 self->fatal(message);
39}
40
41void error(Logger *self, const std::string &message) {
43 self->error(message);
44}
45
46void warning(Logger *self, const std::string &message) {
48 self->warning(message);
49}
50
51void notice(Logger *self, const std::string &message) {
53 self->notice(message);
54}
55
56void information(Logger *self, const std::string &message) {
58 self->information(message);
59}
60
61void debug(Logger *self, const std::string &message) {
63 self->debug(message);
64}
65
66} // namespace
67
69 register_ptr_to_python<std::shared_ptr<Logger>>();
70
71 class_<Logger, boost::noncopyable>("Logger", init<std::string>((arg("self"), arg("name"))))
72 .def("__init__", make_constructor(&create, default_call_policies(), args("name")))
73 .def("fatal", fatal, (arg("self"), arg("message")),
74 "Send a message at fatal priority: "
75 "An unrecoverable error has occured and the application will "
76 "terminate")
77 .def("error", error, (arg("self"), arg("message")),
78 "Send a message at error priority: "
79 "An error has occured but the framework is able to handle it and "
80 "continue")
81 .def("warning", warning, (arg("self"), arg("message")),
82 "Send a message at warning priority: "
83 "Something was wrong but the framework was able to continue despite "
84 "the problem.")
85 .def("notice", notice, (arg("self"), arg("message")),
86 "Sends a message at notice priority: "
87 "Really important information that should be displayed to the user, "
88 "this should be minimal. The default logging level is set here "
89 "unless it is altered.")
90 .def("information", information, (arg("self"), arg("message")),
91 "Send a message at information priority: "
92 "Useful but not vital information to be relayed back to the user.")
93 .def("debug", debug, (arg("self"), arg("message")),
94 "Send a message at debug priority:"
95 ". Anything that may be useful to understand what the code has been "
96 "doing for debugging purposes.")
97 .def("accumulate", (LoggerMsgFunction)&Logger::accumulate, (arg("self"), arg("message")),
98 "accumulate a message to report later")
99 .def("flush", (LoggerFlushFunction)&Logger::flush, (arg("self")),
100 "Flush the accumulated message to the current channel.")
101 .def("flushDebug", (LoggerFlushFunction)&Logger::flushDebug, (arg("self")),
102 "Flush the accumulated message to the debug channel.")
103 .def("flushInformation", (LoggerFlushFunction)&Logger::flushInformation, (arg("self")),
104 "Flush the accumulated message to the debug channel.")
105 .def("flushNotice", (LoggerFlushFunction)&Logger::flushNotice, (arg("self")),
106 "Flush the accumulated message to the notice channel.")
107 .def("flushWarning", (LoggerFlushFunction)&Logger::flushWarning, (arg("self")),
108 "Flush the accumulated message to the warning channel.")
109 .def("flushError", (LoggerFlushFunction)&Logger::flushError, (arg("self")),
110 "Flush the accumulated message to the error channel.")
111 .def("flushFatal", (LoggerFlushFunction)&Logger::flushFatal, (arg("self")),
112 "Flush the accumulated message to the fatal channel.")
113 .def("purge", (LoggerFlushFunction)&Logger::purge, (arg("self")),
114 "Clear the accumulated messages without logging.")
115 // -- deprecated --
116 .def("get", &getLogger,
117 "Creates the named logger. "
118 "This method is static, call as Logger.get('logger_name'). The name "
119 "is used as a prefix within the "
120 "log file so that msg origins can be traced more easily.")
121 .staticmethod("get");
122}
std::string name
Definition Run.cpp:60
double error
void(Logger::*)(const std::string &) LoggerMsgFunction
Definition Logger.cpp:18
void(Logger::*)() LoggerFlushFunction
Definition Logger.cpp:19
void export_Logger()
Definition Logger.cpp:68
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
void flushInformation()
flushes the accumulated message with information priority
Definition Logger.cpp:302
void flushFatal()
flushes the accumulated message with fatal priority
Definition Logger.cpp:314
void debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
void notice(const std::string &msg)
Logs at notice level.
Definition Logger.cpp:126
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
void flushDebug()
flushes the accumulated message with debug priority
Definition Logger.cpp:299
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
void flushError()
flushes the accumulated message with error priority
Definition Logger.cpp:311
void fatal(const std::string &msg)
Logs at Fatal level.
Definition Logger.cpp:99
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
void purge()
flushes the accumulated messages without logging them
Definition Logger.cpp:317
void flush()
flushes accumulated messages to the current level
Definition Logger.cpp:290
void flushWarning()
flushes the accumulated message with warning priority
Definition Logger.cpp:308
void flushNotice()
flushes the accumulated message with notice priority
Definition Logger.cpp:305
void accumulate(const std::string &msg)
accumulates a message
Definition Logger.cpp:285
Defines a structure for releasing the Python GIL using the RAII pattern.
STL namespace.