Boost.Log -> spdlog - config, gl, manager

This commit is contained in:
Dan Paulat 2022-04-18 08:39:24 -05:00
parent 40ef43ed30
commit 15bc3afc87
7 changed files with 51 additions and 68 deletions

View file

@ -1,11 +1,10 @@
#include <scwx/qt/config/radar_site.hpp>
#include <scwx/qt/util/json.hpp>
#include <scwx/common/sites.hpp>
#include <scwx/util/logger.hpp>
#include <unordered_map>
#include <boost/log/trivial.hpp>
namespace scwx
{
namespace qt
@ -13,7 +12,8 @@ namespace qt
namespace config
{
static const std::string logPrefix_ = "[scwx::qt::settings::radar_site] ";
static const std::string logPrefix_ = "scwx::qt::settings::radar_site";
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
static const std::string defaultRadarSiteFile_ =
":/res/config/radar_sites.json";
@ -121,8 +121,7 @@ void RadarSite::Initialize()
size_t RadarSite::ReadConfig(const std::string& path)
{
BOOST_LOG_TRIVIAL(info) << logPrefix_ << "Loading radar sites from \""
<< path << "\"...";
logger_->info("Loading radar sites from \"{}\"...", path);
bool dataValid = true;
size_t sitesAdded = 0;
@ -139,7 +138,7 @@ size_t RadarSite::ReadConfig(const std::string& path)
if (!ValidateJsonEntry(o))
{
BOOST_LOG_TRIVIAL(info) << logPrefix_ << "Incorrect format: " << v;
logger_->info("Incorrect format: {}", boost::json::serialize(v));
}
else
{
@ -168,9 +167,9 @@ size_t RadarSite::ReadConfig(const std::string& path)
}
else
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Site ID conflict: " << siteIdMap_.at(siteId)
<< " and " << site->p->id_;
logger_->warn("Site ID conflict: {} and {}",
siteIdMap_.at(siteId),
site->p->id_);
}
}
}

View file

@ -1,6 +1,6 @@
#include <scwx/qt/gl/draw/draw_item.hpp>
#include <boost/log/trivial.hpp>
#include <string>
namespace scwx
{
@ -11,7 +11,7 @@ namespace gl
namespace draw
{
static const std::string logPrefix_ = "[scwx::qt::gl::draw::draw_item] ";
static const std::string logPrefix_ = "scwx::qt::gl::draw::draw_item";
class DrawItemImpl
{

View file

@ -2,8 +2,6 @@
#include <optional>
#include <boost/log/trivial.hpp>
namespace scwx
{
namespace qt
@ -13,7 +11,7 @@ namespace gl
namespace draw
{
static const std::string logPrefix_ = "[scwx::qt::gl::draw::rectangle] ";
static const std::string logPrefix_ = "scwx::qt::gl::draw::rectangle";
static constexpr size_t NUM_RECTANGLES = 5;
static constexpr size_t NUM_TRIANGLES = NUM_RECTANGLES * 2;

View file

@ -1,9 +1,8 @@
#include <scwx/qt/gl/shader_program.hpp>
#include <scwx/util/logger.hpp>
#include <QFile>
#include <boost/log/trivial.hpp>
namespace scwx
{
namespace qt
@ -11,7 +10,8 @@ namespace qt
namespace gl
{
static const std::string logPrefix_ = "[scwx::qt::gl::shader_program] ";
static const std::string logPrefix_ = "scwx::qt::gl::shader_program";
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
static constexpr GLsizei INFO_LOG_BUF_SIZE = 512;
@ -53,8 +53,7 @@ GLuint ShaderProgram::id() const
bool ShaderProgram::Load(const std::string& vertexPath,
const std::string& fragmentPath)
{
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Load(\"" << vertexPath << "\", \""
<< fragmentPath << "\")";
logger_->debug("Load: {}, {}", vertexPath, fragmentPath);
OpenGLFunctions& gl = p->gl_;
@ -71,15 +70,13 @@ bool ShaderProgram::Load(const std::string& vertexPath,
if (!vertexFile.isOpen())
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Could not load vertex shader: " << vertexPath;
logger_->error("Could not load vertex shader: {}", vertexPath);
return false;
}
if (!fragmentFile.isOpen())
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Could not load fragment shader: " << fragmentPath;
logger_->error("Could not load fragment shader: {}", fragmentPath);
return false;
}
@ -108,14 +105,12 @@ bool ShaderProgram::Load(const std::string& vertexPath,
gl.glGetShaderInfoLog(vertexShader, INFO_LOG_BUF_SIZE, &logLength, infoLog);
if (!glSuccess)
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Vertex shader compilation failed: " << infoLog;
logger_->error("Vertex shader compilation failed: {}", infoLog);
success = false;
}
else if (logLength > 0)
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Vertex shader compiled with warnings: " << infoLog;
logger_->error("Vertex shader compiled with warnings: {}", infoLog);
}
// Create a fragment shader
@ -131,14 +126,12 @@ bool ShaderProgram::Load(const std::string& vertexPath,
fragmentShader, INFO_LOG_BUF_SIZE, &logLength, infoLog);
if (!glSuccess)
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Fragment shader compilation failed: " << infoLog;
logger_->error("Fragment shader compilation failed: {}", infoLog);
success = false;
}
else if (logLength > 0)
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Fragment shader compiled with warnings: " << infoLog;
logger_->error("Fragment shader compiled with warnings: {}", infoLog);
}
if (success)
@ -152,14 +145,12 @@ bool ShaderProgram::Load(const std::string& vertexPath,
gl.glGetProgramInfoLog(p->id_, INFO_LOG_BUF_SIZE, &logLength, infoLog);
if (!glSuccess)
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Shader program link failed: " << infoLog;
logger_->error("Shader program link failed: {}", infoLog);
success = false;
}
else if (logLength > 0)
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Shader program linked with warnings: " << infoLog;
logger_->error("Shader program linked with warnings: {}", infoLog);
}
}

View file

@ -1,6 +1,6 @@
#include <scwx/qt/gl/text_shader.hpp>
#include <scwx/util/logger.hpp>
#include <boost/log/trivial.hpp>
#include <glm/gtc/type_ptr.hpp>
namespace scwx
@ -10,7 +10,8 @@ namespace qt
namespace gl
{
static const std::string logPrefix_ = "[scwx::qt::gl::text_shader] ";
static const std::string logPrefix_ = "scwx::qt::gl::text_shader";
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
class TextShaderImpl
{
@ -46,7 +47,7 @@ bool TextShader::Initialize()
p->projectionLocation_ = gl.glGetUniformLocation(id(), "projection");
if (p->projectionLocation_ == -1)
{
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Could not find projection";
logger_->warn("Could not find projection");
}
return success;

View file

@ -1,6 +1,7 @@
#include <scwx/qt/manager/radar_product_manager.hpp>
#include <scwx/common/constants.hpp>
#include <scwx/util/threads.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/wsr88d/nexrad_file_factory.hpp>
#include <deque>
@ -8,7 +9,6 @@
#include <mutex>
#include <shared_mutex>
#include <boost/log/trivial.hpp>
#include <boost/range/irange.hpp>
#include <boost/timer/timer.hpp>
#include <GeographicLib/Geodesic.hpp>
@ -22,7 +22,8 @@ namespace manager
{
static const std::string logPrefix_ =
"[scwx::qt::manager::radar_product_manager] ";
"scwx::qt::manager::radar_product_manager";
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
typedef std::function<std::shared_ptr<wsr88d::NexradFile>()>
CreateNexradFileFunction;
@ -59,8 +60,7 @@ public:
{
if (radarSite_ == nullptr)
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Radar site not found: \"" << radarId_ << "\"";
logger_->warn("Radar site not found: \"{}\"", radarId_);
radarSite_ = std::make_shared<config::RadarSite>();
}
}
@ -130,7 +130,7 @@ void RadarProductManager::Initialize()
return;
}
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()";
logger_->debug("Initialize()");
boost::timer::cpu_timer timer;
@ -176,9 +176,8 @@ void RadarProductManager::Initialize()
coordinates0_5Degree[offset + 1] = longitude;
});
timer.stop();
BOOST_LOG_TRIVIAL(debug)
<< logPrefix_ << "Coordinates (0.5 degree) calculated in "
<< timer.format(6, "%ws");
logger_->debug("Coordinates (0.5 degree) calculated in {}",
timer.format(6, "%ws"));
// Calculate 1 degree azimuth coordinates
timer.start();
@ -214,9 +213,8 @@ void RadarProductManager::Initialize()
coordinates1Degree[offset + 1] = longitude;
});
timer.stop();
BOOST_LOG_TRIVIAL(debug)
<< logPrefix_ << "Coordinates (1 degree) calculated in "
<< timer.format(6, "%ws");
logger_->debug("Coordinates (1 degree) calculated in {}",
timer.format(6, "%ws"));
p->initialized_ = true;
}
@ -224,7 +222,7 @@ void RadarProductManager::Initialize()
void RadarProductManager::LoadData(
std::istream& is, std::shared_ptr<request::NexradFileRequest> request)
{
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "LoadData()";
logger_->debug("LoadData()");
RadarProductManagerImpl::LoadNexradFile(
[=, &is]() -> std::shared_ptr<wsr88d::NexradFile>
@ -236,7 +234,7 @@ void RadarProductManager::LoadFile(
const std::string& filename,
std::shared_ptr<request::NexradFileRequest> request)
{
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "LoadFile(" << filename << ")";
logger_->debug("LoadFile: {}", filename);
std::shared_ptr<types::RadarProductRecord> existingRecord = nullptr;
@ -245,8 +243,7 @@ void RadarProductManager::LoadFile(
auto it = fileIndex_.find(filename);
if (it != fileIndex_.cend())
{
BOOST_LOG_TRIVIAL(debug)
<< logPrefix_ << "File previously loaded, loading from file cache";
logger_->debug("File previously loaded, loading from file cache");
existingRecord = it->second;
}
@ -385,7 +382,7 @@ std::shared_ptr<types::RadarProductRecord>
RadarProductManagerImpl::StoreRadarProductRecord(
std::shared_ptr<types::RadarProductRecord> record)
{
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "StoreRadarProductRecord()";
logger_->debug("StoreRadarProductRecord()");
std::shared_ptr<types::RadarProductRecord> storedRecord = record;
@ -394,9 +391,8 @@ RadarProductManagerImpl::StoreRadarProductRecord(
auto it = level2ProductRecords_.find(record->time());
if (it != level2ProductRecords_.cend())
{
BOOST_LOG_TRIVIAL(debug)
<< logPrefix_
<< "Level 2 product previously loaded, loading from cache";
logger_->debug(
"Level 2 product previously loaded, loading from cache");
storedRecord = it->second;
}
@ -412,9 +408,8 @@ RadarProductManagerImpl::StoreRadarProductRecord(
auto it = productMap.find(record->time());
if (it != productMap.cend())
{
BOOST_LOG_TRIVIAL(debug)
<< logPrefix_
<< "Level 3 product previously loaded, loading from cache";
logger_->debug(
"Level 3 product previously loaded, loading from cache");
storedRecord = it->second;
}

View file

@ -1,5 +1,6 @@
#include <scwx/qt/manager/settings_manager.hpp>
#include <scwx/qt/util/json.hpp>
#include <scwx/util/logger.hpp>
#include <filesystem>
#include <fstream>
@ -7,8 +8,6 @@
#include <QDir>
#include <QStandardPaths>
#include <boost/log/trivial.hpp>
namespace scwx
{
namespace qt
@ -18,7 +17,8 @@ namespace manager
namespace SettingsManager
{
static const std::string logPrefix_ = "[scwx::qt::manager::settings_manager] ";
static const std::string logPrefix_ = "scwx::qt::manager::settings_manager";
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
static std::shared_ptr<settings::GeneralSettings> generalSettings_ = nullptr;
static std::shared_ptr<settings::PaletteSettings> paletteSettings_ = nullptr;
@ -37,9 +37,8 @@ void Initialize()
{
if (!std::filesystem::create_directories(appDataPath))
{
BOOST_LOG_TRIVIAL(error)
<< logPrefix_ << "Unable to create application data directory: \""
<< appDataPath << "\"";
logger_->error("Unable to create application data directory: \"{}\"",
appDataPath);
}
}
@ -97,7 +96,7 @@ static boost::json::value ConvertSettingsToJson()
static void GenerateDefaultSettings()
{
BOOST_LOG_TRIVIAL(info) << logPrefix_ << "Generating default settings";
logger_->info("Generating default settings");
generalSettings_ = settings::GeneralSettings::Create();
paletteSettings_ = settings::PaletteSettings::Create();
@ -105,7 +104,7 @@ static void GenerateDefaultSettings()
static bool LoadSettings(const boost::json::object& settingsJson)
{
BOOST_LOG_TRIVIAL(info) << logPrefix_ << "Loading settings";
logger_->info("Loading settings");
bool jsonDirty = false;