5#include <ChimeraTK/cppext/future_queue.hpp>
7#include <boost/algorithm/string.hpp>
8#include <boost/thread.hpp>
37 [[nodiscard]]
constexpr operator Value() {
return _value; }
40 [[nodiscard]]
constexpr std::string_view
toString()
const;
49 constexpr static std::expected<Logger::Severity, std::string>
fromString(
const std::string&
string);
107 static std::shared_ptr<Logger>& getSharedPtr();
115 void log(
Severity severity, std::string context, std::string message)
noexcept;
121 static std::string severityToString(
Severity severity);
131 cppext::future_queue<LogMessage> _messageQueue{10};
135 std::atomic<Severity> _minSeverity{defaultSeverityFromEnv()};
140 boost::thread _mainLoopThread{[
this] { mainLoop(); }};
146 static Severity defaultSeverityFromEnv();
163 return *getSharedPtr();
168 inline std::shared_ptr<Logger>& Logger::getSharedPtr() {
169 static std::shared_ptr<Logger> instance(
new Logger());
195 auto stringLower = boost::algorithm::to_lower_copy(std::string(
string));
196 if(stringLower ==
"trace") {
199 if(stringLower ==
"debug") {
202 if(stringLower ==
"info") {
205 if(stringLower ==
"warning") {
208 if(stringLower ==
"error") {
211 return std::unexpected(
"Valid values are: trace, debug, info, warning, error.");
Severity levels used by the Logger.
static constexpr std::expected< Logger::Severity, std::string > fromString(const std::string &string)
Set Severity from string.
constexpr auto operator<=>(const Severity::Value &other) const
constexpr std::string_view toString() const
Convert Severity into string.
constexpr Severity(const Value &value)
constexpr auto operator<=>(const Severity &other) const =default
Proxy for output stream, handed out to the log sources by the Logger::Module.
void setMinSeverity(Severity minSeverity)
Set the minimum severity level to be passed to the logger.
StreamProxy getStream(Severity severity, std::string context)
Return an output stream object for the given severity.
static Logger & getInstance()
Obtain global instance of Logger singleton.
InvalidityTracer application module.
Logger::StreamProxy logger(Logger::Severity severity, std::string context)
Convenience function to obtain the logger stream.