Initial setup for spdlog

This commit is contained in:
Dan Paulat 2022-04-13 20:08:04 -05:00
parent 7aef98b002
commit 20b8c75234
5 changed files with 67 additions and 0 deletions

View file

@ -0,0 +1,20 @@
#pragma once
#include <memory>
#include <string>
#include <spdlog/logger.h>
namespace scwx
{
namespace util
{
namespace Logger
{
void Initialize();
std::shared_ptr<spdlog::logger> Create(const std::string& name);
} // namespace Logger
} // namespace util
} // namespace scwx

View file

@ -0,0 +1,37 @@
#include <scwx/util/logger.hpp>
#include <mutex>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
namespace scwx
{
namespace util
{
namespace Logger
{
void Initialize()
{
spdlog::set_pattern("[%Y-%m-%d %T.%e] [%t] [%^%l%$] [%n] %v");
}
std::shared_ptr<spdlog::logger> Create(const std::string& name)
{
// Create a shared sink
static auto sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
// Create the logger
std::shared_ptr<spdlog::logger> logger =
std::make_shared<spdlog::logger>(name, sink);
// Register the logger, so it can be retrieved later using spdlog::get()
spdlog::register_logger(logger);
return logger;
}
} // namespace Logger
} // namespace util
} // namespace scwx

View file

@ -1,6 +1,7 @@
project(scwx-data)
find_package(Boost)
find_package(spdlog)
set(HDR_AWIPS include/scwx/awips/coded_location.hpp
include/scwx/awips/coded_time_motion_location.hpp
@ -34,12 +35,14 @@ set(SRC_COMMON source/scwx/common/color_table.cpp
source/scwx/common/vcp.cpp)
set(HDR_UTIL include/scwx/util/float.hpp
include/scwx/util/iterator.hpp
include/scwx/util/logger.hpp
include/scwx/util/rangebuf.hpp
include/scwx/util/streams.hpp
include/scwx/util/threads.hpp
include/scwx/util/time.hpp
include/scwx/util/vectorbuf.hpp)
set(SRC_UTIL source/scwx/util/float.cpp
source/scwx/util/logger.cpp
source/scwx/util/rangebuf.cpp
source/scwx/util/streams.cpp
source/scwx/util/time.cpp
@ -191,6 +194,7 @@ if(MSVC)
target_compile_options(wxdata PRIVATE /W3)
endif()
target_link_libraries(wxdata PUBLIC spdlog::spdlog)
target_link_libraries(wxdata INTERFACE Boost::iostreams
Boost::log
BZip2::BZip2