28 #ifndef INCLUDED_Logger_h_GUID_D8ADC0E7_A358_4FF2_960F_10F098A22F4E 29 #define INCLUDED_Logger_h_GUID_D8ADC0E7_A358_4FF2_960F_10F098A22F4E 32 #include <osvr/Util/Export.h> 40 #include <initializer_list> 53 using sink_ptr = std::shared_ptr<spdlog::sinks::sink>;
54 using sinks_init_list = std::initializer_list<sink_ptr>;
69 struct PrivateConstructor;
74 Logger(std::string
const &name,
75 std::shared_ptr<spdlog::logger> logger,
76 PrivateConstructor *);
82 OSVR_UTIL_EXPORT
static LoggerPtr makeFromExistingImplementation(
83 std::string
const &name,
84 std::shared_ptr<spdlog::logger> logger);
91 OSVR_UTIL_EXPORT
static LoggerPtr
92 makeWithSink(std::string
const &name, spdlog::sink_ptr sink);
99 OSVR_UTIL_EXPORT
static LoggerPtr
100 makeWithSinks(std::string
const &name,
101 spdlog::sinks_init_list sinks);
110 OSVR_UTIL_EXPORT ~
Logger();
114 OSVR_UTIL_EXPORT
LogLevel getLogLevel()
const;
118 OSVR_UTIL_EXPORT
void setLogLevel(
LogLevel level);
121 OSVR_UTIL_EXPORT
void flushOn(
LogLevel level);
130 : logger_(logger), level_(level),
131 os_(
new std::ostringstream) {}
134 const std::string &msg)
135 : logger_(logger), level_(level),
136 os_(
new std::ostringstream) {
143 if (active_ && os_) {
144 logger_.write(level_, os_->str().c_str());
150 : logger_(other.logger_), level_(other.level_),
151 os_(
std::move(other.os_)), active_(other.active_) {
152 other.active_ =
false;
158 operator std::ostream &() {
return (*os_); }
160 template <
typename T> std::ostream &operator<<(
T &&what) {
161 (*os_) << std::forward<T>(what);
168 std::unique_ptr<std::ostringstream> os_;
175 OSVR_UTIL_EXPORT
StreamProxy trace(
const char *msg);
176 OSVR_UTIL_EXPORT
StreamProxy debug(
const char *msg);
177 OSVR_UTIL_EXPORT
StreamProxy info(
const char *msg);
178 OSVR_UTIL_EXPORT
StreamProxy notice(
const char *msg);
179 OSVR_UTIL_EXPORT
StreamProxy warn(
const char *msg);
180 OSVR_UTIL_EXPORT
StreamProxy error(
const char *msg);
181 OSVR_UTIL_EXPORT
StreamProxy critical(
const char *msg);
203 OSVR_UTIL_EXPORT
void flush();
212 makeLogger(std::string
const &name,
213 std::shared_ptr<spdlog::logger>
const &logger);
217 static LoggerPtr makeFallback(std::string
const &name);
220 OSVR_UTIL_EXPORT
void write(
LogLevel level,
const char* msg);
222 const std::string name_;
223 std::shared_ptr<spdlog::logger> logger_;
230 #endif // INCLUDED_Logger_h_GUID_D8ADC0E7_A358_4FF2_960F_10F098A22F4E Definition: RunLoopManager.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: TypeSafeIdHash.h:44
OSVR_UTIL_EXPORT void flush()
For implementations with a centralized logger registry, flush all logger sinks.
Definition: Log.cpp:100
Header for basic internal log reference.
LogLevel
Log message severity levels.
Definition: LogLevel.h:45
An object allowing you to log messages with a given log source name.
Definition: Logger.h:67
~StreamProxy()
destructor appends the finished stringstream at the end of the expression.
Definition: Logger.h:142
StreamProxy(StreamProxy &&other)
move construction
Definition: Logger.h:149
An object returned the logging functions (including operator<<), serves to accumulate streamed output...
Definition: Logger.h:127
std::string const & getName() const
Get the logger name.
Definition: Logger.h:206