preCICE v3.2.0
Loading...
Searching...
No Matches
Logger.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <string_view>
6
7namespace precice::logging {
8
11 const char *file;
12 int line;
13 const char *func;
14};
15
17class Logger {
18public:
22 explicit Logger(std::string_view module);
23
24 Logger(const Logger &other);
25 Logger(Logger &&other) noexcept;
26 Logger &operator=(Logger other);
28
29 void swap(Logger &other) noexcept;
30
33 void error(LogLocation loc, std::string_view mess) noexcept;
34 void warning(LogLocation loc, std::string_view mess) noexcept;
35 void info(LogLocation loc, std::string_view mess) noexcept;
36 void debug(LogLocation loc, std::string_view mess) noexcept;
37 void trace(LogLocation loc, std::string_view mess) noexcept;
39
40private:
42 class LoggerImpl;
43
46};
47
49template <class Error>
50inline void logErrorAndThrow [[noreturn]] (precice::logging::Logger &log, precice::logging::LogLocation location, const std::string &message)
51{
52 log.error(location, message);
53 throw Error{message};
54}
55
56} // namespace precice::logging
57
58// Include LogMacros here, because using it works only together with a Logger
59#include "LogMacros.hpp"
This class provides a lightweight logger.
Definition Logger.hpp:17
void warning(LogLocation loc, std::string_view mess) noexcept
Definition Logger.cpp:165
void error(LogLocation loc, std::string_view mess) noexcept
Definition Logger.cpp:157
Logger & operator=(Logger other)
Definition Logger.cpp:142
void debug(LogLocation loc, std::string_view mess) noexcept
Definition Logger.cpp:181
void info(LogLocation loc, std::string_view mess) noexcept
Definition Logger.cpp:173
Logger(Logger &&other) noexcept
void swap(Logger &other) noexcept
Definition Logger.cpp:148
Logger(std::string_view module)
Definition Logger.cpp:128
~Logger()
This is required for the std::unique_ptr.
std::unique_ptr< LoggerImpl > _impl
Pimpl to the logger implementation.
Definition Logger.hpp:45
void trace(LogLocation loc, std::string_view mess) noexcept
Definition Logger.cpp:189
contains the logging framework.
void logErrorAndThrow(precice::logging::Logger &log, precice::logging::LogLocation location, const std::string &message)
Utility function to log an error and throw an exception of given type.
Definition Logger.hpp:50
Struct used to capture the original location of a log request.
Definition Logger.hpp:10