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

View file

@ -1,6 +1,6 @@
#include <scwx/qt/gl/draw/draw_item.hpp> #include <scwx/qt/gl/draw/draw_item.hpp>
#include <boost/log/trivial.hpp> #include <string>
namespace scwx namespace scwx
{ {
@ -11,7 +11,7 @@ namespace gl
namespace draw 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 class DrawItemImpl
{ {

View file

@ -2,8 +2,6 @@
#include <optional> #include <optional>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace qt namespace qt
@ -13,7 +11,7 @@ namespace gl
namespace draw 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_RECTANGLES = 5;
static constexpr size_t NUM_TRIANGLES = NUM_RECTANGLES * 2; static constexpr size_t NUM_TRIANGLES = NUM_RECTANGLES * 2;

View file

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

View file

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

View file

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

View file

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