 |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Go to the documentation of this file.
6 #ifndef LLU_ERRORLOG_LOGGER_H
7 #define LLU_ERRORLOG_LOGGER_H
9 #include <initializer_list>
24 #define LLU_LOG_LEVEL_DEBUG
25 #define LLU_LOG_WARNING
26 #define LLU_LOG_DEBUG // workaround for a Doxygen bug
33 #ifdef LLU_LOG_WARNING
34 #define LLU_LOG_LEVEL_WARNING
43 #define LLU_LOG_LEVEL_ERROR
48 #ifdef LLU_LOG_LEVEL_DEBUG
55 #define LLU_DEBUG(...) LLU::Logger::log<LLU::Logger::Level::Debug>(__LINE__, __FILE__, __func__, __VA_ARGS__)
57 #define LLU_DEBUG(...) ((void)0)
60 #ifdef LLU_LOG_LEVEL_WARNING
67 #define LLU_WARNING(...) LLU::Logger::log<LLU::Logger::Level::Warning>(__LINE__, __FILE__, __func__, __VA_ARGS__)
69 #define LLU_WARNING(...) ((void)0)
72 #ifdef LLU_LOG_LEVEL_ERROR
79 #define LLU_ERROR(...) LLU::Logger::log<LLU::Logger::Level::Error>(__LINE__, __FILE__, __func__, __VA_ARGS__)
81 #define LLU_ERROR(...) ((void)0)
93 enum class Level { Debug, Warning, Error };
107 template<
Level L,
typename... T>
108 static void log(WolframLibraryData libData,
int line,
const std::string& fileName,
const std::string&
function, T&&... args);
121 template<
Level L,
typename... T>
122 static void log(
int line,
const std::string& fileName,
const std::string&
function, T&&... args);
136 logSymbolContext = std::move(context);
144 return logSymbolContext + topLevelLogCallback;
149 static constexpr
const char* topLevelLogCallback =
"Logger`LogHandler";
150 static std::mutex mlinkGuard;
151 static std::string logSymbolContext;
162 template<WS::Encoding EIn, WS::Encoding EOut>
168 void Logger::log(WolframLibraryData libData,
int line,
const std::string& fileName,
const std::string&
function, T&&... args) {
172 std::lock_guard<std::mutex> lock(mlinkGuard);
177 mls << L << line << fileName <<
function;
178 Unused((mls << ... << args));
179 libData->processWSLINK(mls.get());
180 auto pkt = WSNextPacket(mls.get());
181 if (pkt == RETURNPKT) {
187 void Logger::log(
int line,
const std::string& fileName,
const std::string&
function, T&&... args) {
188 log<L>(
LibraryData::API(), line, fileName,
function, std::forward<T>(args)...);
192 #endif // LLU_ERRORLOG_LOGGER_H
static std::string to_string(Level l)
Converts Logger::Level value to std::string.
Definition: Logger.cpp:15
static void setContext(std::string context)
Set new context for the top-level symbol that will handle logging.
Definition: Logger.h:135
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
Wrapper class over WSTP with a stream-like interface.
Definition: WSTP/Utilities.h:21
Structure representing any function in Wolfram Language, i.e. a head plus number of arguments.
Definition: WSTP/Utilities.h:65
Logger class is responsible for sending log messages via WSTP to Mathematica.
Definition: Logger.h:90
Header file for WSStream class.
static WolframLibraryData API()
Get currently owned WolframLibraryData, if any.
Definition: LibraryData.cpp:22
static void log(WolframLibraryData libData, int line, const std::string &fileName, const std::string &function, T &&... args)
Send a log message of given severity.
Definition: Logger.h:168
void Unused(Ts &&...)
Dummy function called on otherwise unused parameters to eliminate compiler warnings.
Definition: Utilities.hpp:115
WSStream< EIn, EOut > & NewPacket(WSStream< EIn, EOut > &ms)
NewPacket is a WSStream token which tells WSTP to skip to the end of the current packet.
Definition: WSTP/Utilities.h:203
Level
Possible log severity levels.
Definition: Logger.h:93
std::ostream & operator<<(std::ostream &os, const MArray< T > &c)
Insertion operator to allow pretty-printing of MArray.
Definition: MArray.hpp:167
static std::string getSymbol()
Get the top-level symbol with full context, to which all logs are sent.
Definition: Logger.h:143