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 PyErr_Warn(PyExc_DeprecationWarning, "Logger.get(\"name\") is deprecated. "
29 "Simply use Logger(\"name\") instead");
30 return std::make_shared<Logger>(name);
31}
32
33std::shared_ptr<Logger> create(const std::string &name) { return std::make_shared<Logger>(name); }
34
35void fatal(Logger *self, const std::string &message) {
37 self->fatal(message);
38}
39
40void error(Logger *self, const std::string &message) {
42 self->error(message);
43}
44
45void warning(Logger *self, const std::string &message) {
47 self->warning(message);
48}
49
50void notice(Logger *self, const std::string &message) {
52 self->notice(message);
53}
54
55void information(Logger *self, const std::string &message) {
57 self->information(message);
58}
59
60void debug(Logger *self, const std::string &message) {
62 self->debug(message);
63}
64
65} // namespace
66
68 register_ptr_to_python<std::shared_ptr<Logger>>();
69
70 class_<Logger, boost::noncopyable>("Logger", init<std::string>((arg("self"), arg("name"))))
71 .def("__init__", make_constructor(&create, default_call_policies(), args("name")))
72 .def("fatal", fatal, (arg("self"), arg("message")),
73 "Send a message at fatal priority: "
74 "An unrecoverable error has occured and the application will "
75 "terminate")
76 .def("error", error, (arg("self"), arg("message")),
77 "Send a message at error priority: "
78 "An error has occured but the framework is able to handle it and "
79 "continue")
80 .def("warning", warning, (arg("self"), arg("message")),
81 "Send a message at warning priority: "
82 "Something was wrong but the framework was able to continue despite "
83 "the problem.")
84 .def("notice", notice, (arg("self"), arg("message")),
85 "Sends a message at notice priority: "
86 "Really important information that should be displayed to the user, "
87 "this should be minimal. The default logging level is set here "
88 "unless it is altered.")
89 .def("information", information, (arg("self"), arg("message")),
90 "Send a message at information priority: "
91 "Useful but not vital information to be relayed back to the user.")
92 .def("debug", debug, (arg("self"), arg("message")),
93 "Send a message at debug priority:"
94 ". Anything that may be useful to understand what the code has been "
95 "doing for debugging purposes.")
96 .def("accumulate", (LoggerMsgFunction)&Logger::accumulate, (arg("self"), arg("message")),
97 "accumulate a message to report later")
98 .def("flush", (LoggerFlushFunction)&Logger::flush, (arg("self")),
99 "Flush the accumulated message to the current channel.")
100 .def("flushDebug", (LoggerFlushFunction)&Logger::flushDebug, (arg("self")),
101 "Flush the accumulated message to the debug channel.")
102 .def("flushInformation", (LoggerFlushFunction)&Logger::flushInformation, (arg("self")),
103 "Flush the accumulated message to the debug channel.")
104 .def("flushNotice", (LoggerFlushFunction)&Logger::flushNotice, (arg("self")),
105 "Flush the accumulated message to the notice channel.")
106 .def("flushWarning", (LoggerFlushFunction)&Logger::flushWarning, (arg("self")),
107 "Flush the accumulated message to the warning channel.")
108 .def("flushError", (LoggerFlushFunction)&Logger::flushError, (arg("self")),
109 "Flush the accumulated message to the error channel.")
110 .def("flushFatal", (LoggerFlushFunction)&Logger::flushFatal, (arg("self")),
111 "Flush the accumulated message to the fatal channel.")
112 .def("purge", (LoggerFlushFunction)&Logger::purge, (arg("self")),
113 "Clear the accumulated messages without logging.")
114 // -- deprecated --
115 .def("get", &getLogger,
116 "Creates the named logger. "
117 "This method is static, call as Logger.get('logger_name'). The name "
118 "is used as a prefix within the "
119 "log file so that msg origins can be traced more easily.")
120 .staticmethod("get");
121}
double error
Definition: IndexPeaks.cpp:133
void(Logger::*)(const std::string &) LoggerMsgFunction
Definition: Logger.cpp:18
void(Logger::*)() LoggerFlushFunction
Definition: Logger.cpp:19
void export_Logger()
Definition: Logger.cpp:67
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
void flushInformation()
flushes the accumulated message with information priority
Definition: Logger.cpp:262
void flushFatal()
flushes the accumulated message with fatal priority
Definition: Logger.cpp:274
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
void flushDebug()
flushes the accumulated message with debug priority
Definition: Logger.cpp:259
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
void flushError()
flushes the accumulated message with error priority
Definition: Logger.cpp:271
void fatal(const std::string &msg)
Logs at Fatal level.
Definition: Logger.cpp:68
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
void purge()
flushes the accumulated messages without logging them
Definition: Logger.cpp:277
void flush()
flushes accumulated messages to the current level
Definition: Logger.cpp:250
void flushWarning()
flushes the accumulated message with warning priority
Definition: Logger.cpp:268
void flushNotice()
flushes the accumulated message with notice priority
Definition: Logger.cpp:265
void accumulate(const std::string &msg)
accumulates a message
Definition: Logger.cpp:245
Defines a structure for releasing the Python GIL using the RAII pattern.