34 #ifdef OSVR_UTIL_LOG_SINGLETON
40 #include <boost/filesystem.hpp>
41 #include <spdlog/spdlog.h>
51 #ifdef OSVR_UTIL_LOG_SINGLETON
52 bool tryInitializingLoggingWithBaseName(std::string
const &baseName) {
53 auto sanitized = sanitizeFilenamePiece(baseName);
55 auto &inst = LogRegistry::instance(&sanitized);
57 return (inst.getLogFileBaseName() == sanitized);
60 LoggerPtr make_logger(
const std::string &logger_name) {
61 return LogRegistry::instance().getOrCreateLogger(logger_name);
64 void drop(
const std::string &logger_name) {
65 LogRegistry::instance().drop(logger_name);
68 void dropAll() { LogRegistry::instance().dropAll(); }
70 void flush() { LogRegistry::instance().flush(); }
81 LoggerPtr make_logger(
const std::string &logger_name) {
84 auto sink = std::make_shared<stdout_sink_mt>();
86 std::make_shared< ::spdlog::logger>(logger_name, sink);
87 spd_logger->set_pattern(
"%b %d %T.%e %l %n: %v");
92 void drop(
const std::string &logger_name) {
104 bool tryInitializingLoggingWithBaseName(std::string
const &) {
110 std::string getLoggingDirectory(
bool make_dir) {
111 namespace fs = boost::filesystem;
115 #if defined(OSVR_LINUX)
128 log_dir = *xdg_cache_dir;
131 log_dir = fs::path(*home_dir) /
".cache";
133 log_dir /= fs::path(
"osvr") /
"logs";
134 #elif defined(OSVR_MACOSX)
139 log_dir /=
"Library" / fs::path(
"Logs") /
"OSVR";
140 #elif defined(OSVR_WINDOWS)
145 log_dir = *local_app_dir;
149 log_dir /= fs::path(
"OSVR") /
"Logs";
152 if (fs::is_directory(log_dir))
153 return log_dir.string();
156 auto success = fs::create_directories(log_dir);
162 return log_dir.string();
static LoggerPtr makeFromExistingImplementation(std::string const &name, std::shared_ptr< spdlog::logger > logger)
Compile-time logging configuration.
Header for basic internal log reference. To actually log to the produced loggers, include
Regstry to maintain instantiated loggers and global settings.
boost::optional< std::string > getEnvironmentVariable(std::string const &var)
Gets an environment variable's value. On systems that don't distinguish between having a variable def...
Header to include for OSVR-internal usage of the logging mechanism: provides the needed definition of...