Fix logger for windows

This commit is contained in:
Sebastian Messmer 2018-08-07 18:27:34 -07:00
parent 70096de4e3
commit 79ba320714
3 changed files with 16 additions and 1 deletions

View File

@ -2,7 +2,10 @@
#ifndef MESSMER_CPPUTILS_LOGGING_LOGGER_H #ifndef MESSMER_CPPUTILS_LOGGING_LOGGER_H
#define MESSMER_CPPUTILS_LOGGING_LOGGER_H #define MESSMER_CPPUTILS_LOGGING_LOGGER_H
#if !defined(_MSC_VER)
#define SPDLOG_ENABLE_SYSLOG #define SPDLOG_ENABLE_SYSLOG
#endif
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include "../macros.h" #include "../macros.h"

View File

@ -6,6 +6,10 @@
#include <stdexcept> #include <stdexcept>
#include <spdlog/fmt/ostr.h> #include <spdlog/fmt/ostr.h>
#if defined(_MSC_VER)
#include <spdlog/sinks/msvc_sink.h>
#endif
namespace cpputils { namespace cpputils {
namespace logging { namespace logging {
@ -66,6 +70,14 @@ namespace cpputils {
inline void LOG(DEBUG_TYPE, const char* fmt, const Args&... args) { inline void LOG(DEBUG_TYPE, const char* fmt, const Args&... args) {
logger()->debug(fmt, args...); logger()->debug(fmt, args...);
} }
inline std::shared_ptr<spdlog::logger> system_logger(const std::string& name) {
#if defined(_MSC_VER)
return spdlog::create<spdlog::sinks::msvc_sink_mt>(name);
#else
return spdlog::syslog_logger(name, name, LOG_PID);
#endif
}
} }
} }

View File

@ -295,7 +295,7 @@ namespace cryfs {
} else if (options.foreground()) { } else if (options.foreground()) {
cpputils::logging::setLogger(spdlog::stderr_logger_mt("cryfs")); cpputils::logging::setLogger(spdlog::stderr_logger_mt("cryfs"));
} else { } else {
cpputils::logging::setLogger(spdlog::syslog_logger("cryfs", "cryfs", LOG_PID)); cpputils::logging::setLogger(cpputils::logging::system_logger("cryfs"));
} }
} }