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 *);
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
101 spdlog::sinks_init_list sinks);
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);
186 OSVR_UTIL_EXPORT StreamProxy trace();
187 OSVR_UTIL_EXPORT StreamProxy debug();
188 OSVR_UTIL_EXPORT StreamProxy info();
189 OSVR_UTIL_EXPORT StreamProxy notice();
190 OSVR_UTIL_EXPORT StreamProxy warn();
191 OSVR_UTIL_EXPORT StreamProxy error();
192 OSVR_UTIL_EXPORT StreamProxy critical();
197 OSVR_UTIL_EXPORT StreamProxy
log(LogLevel level,
const char *msg);
200 OSVR_UTIL_EXPORT StreamProxy
log(LogLevel level);
203 OSVR_UTIL_EXPORT
void flush();
206 OSVR_UTIL_EXPORT std::string
const &
getName()
const {
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
The main namespace for all C++ elements of the framework, internal and external.
Header for basic internal log reference. To actually log to the produced loggers, include
void setLogLevel(LogLevel level)
std::string const & getName() const
Get the logger name.
static LoggerPtr makeWithSinks(std::string const &name, spdlog::sinks_init_list sinks)
LogLevel getLogLevel() const
An object allowing you to log messages with a given log source name.
static LoggerPtr makeWithSink(std::string const &name, spdlog::sink_ptr sink)
StreamProxy(StreamProxy &&other)
move construction
StreamProxy log(LogLevel level, const char *msg)
Logger(std::string const &name, std::shared_ptr< spdlog::logger > logger, PrivateConstructor *)
Logger & operator=(const Logger &)=delete
Non-copy-assignable.
void flushOn(LogLevel level)
Set the log level at which this logger will trigger a flush.
static LoggerPtr makeFromExistingImplementation(std::string const &name, std::shared_ptr< spdlog::logger > logger)
void flush()
Make sure this logger has written out its data.