From 40ef43ed30963f15cb9eea4175cc8310d85a11e5 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 17 Apr 2022 09:28:17 -0500 Subject: [PATCH] Boost.Log -> spdlog - wsr88d --- wxdata/source/scwx/wsr88d/ar2v_file.cpp | 61 ++++++++----------- wxdata/source/scwx/wsr88d/level3_file.cpp | 38 +++++------- .../scwx/wsr88d/nexrad_file_factory.cpp | 21 +++---- 3 files changed, 48 insertions(+), 72 deletions(-) diff --git a/wxdata/source/scwx/wsr88d/ar2v_file.cpp b/wxdata/source/scwx/wsr88d/ar2v_file.cpp index 37de5472..7b064de9 100644 --- a/wxdata/source/scwx/wsr88d/ar2v_file.cpp +++ b/wxdata/source/scwx/wsr88d/ar2v_file.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -10,14 +11,14 @@ #include #include #include -#include namespace scwx { namespace wsr88d { -static const std::string logPrefix_ = "[scwx::wsr88d::ar2v_file] "; +static const std::string logPrefix_ = "scwx::wsr88d::ar2v_file"; +static const auto logger_ = util::Logger::Create(logPrefix_); class Ar2vFileImpl { @@ -115,8 +116,7 @@ Ar2vFile::GetElevationScan(rda::DataBlockType dataBlockType, float elevation, std::chrono::system_clock::time_point time) const { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "GetElevationScan: " << elevation << " degrees"; + logger_->debug("GetElevationScan: {} degrees", elevation); constexpr float scaleFactor = 8.0f / 0.043945f; @@ -170,14 +170,13 @@ Ar2vFile::GetElevationScan(rda::DataBlockType dataBlockType, bool Ar2vFile::LoadFile(const std::string& filename) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "LoadFile(" << filename << ")"; + logger_->debug("LoadFile: {}", filename); bool fileValid = true; std::ifstream f(filename, std::ios_base::in | std::ios_base::binary); if (!f.good()) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Could not open file for reading: " << filename; + logger_->warn("Could not open file for reading: {}", filename); fileValid = false; } @@ -191,7 +190,7 @@ bool Ar2vFile::LoadFile(const std::string& filename) bool Ar2vFile::LoadData(std::istream& is) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Loading Data"; + logger_->debug("Loading Data"); bool dataValid = true; @@ -211,21 +210,17 @@ bool Ar2vFile::LoadData(std::istream& is) if (is.eof()) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Could not read Volume Header Record\n"; + logger_->warn("Could not read Volume Header Record"); dataValid = false; } if (dataValid) { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Filename: " << p->tapeFilename_; - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Extension: " << p->extensionNumber_; - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Date: " << p->julianDate_; - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Time: " << p->milliseconds_; - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "ICAO: " << p->icao_; + logger_->debug("Filename: {}", p->tapeFilename_); + logger_->debug("Extension: {}", p->extensionNumber_); + logger_->debug("Date: {}", p->julianDate_); + logger_->debug("Time: {}", p->milliseconds_); + logger_->debug("ICAO: {}", p->icao_); size_t decompressedRecords = p->DecompressLDMRecords(is); if (decompressedRecords == 0) @@ -245,7 +240,7 @@ bool Ar2vFile::LoadData(std::istream& is) size_t Ar2vFileImpl::DecompressLDMRecords(std::istream& is) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Decompressing LDM Records"; + logger_->debug("Decompressing LDM Records"); size_t numRecords = 0; @@ -260,8 +255,7 @@ size_t Ar2vFileImpl::DecompressLDMRecords(std::istream& is) controlWord = ntohl(controlWord); recordSize = std::abs(controlWord); - BOOST_LOG_TRIVIAL(trace) - << logPrefix_ << "LDM Record Found: Size = " << recordSize << " bytes"; + logger_->trace("LDM Record Found: Size = {} bytes", recordSize); if (recordSize == 0) { @@ -278,17 +272,14 @@ size_t Ar2vFileImpl::DecompressLDMRecords(std::istream& is) { std::stringstream ss; std::streamsize bytesCopied = boost::iostreams::copy(in, ss); - BOOST_LOG_TRIVIAL(trace) - << logPrefix_ << "Decompressed record size = " << bytesCopied - << " bytes"; + logger_->trace("Decompressed record size = {} bytes", bytesCopied); rawRecords_.push_back(std::move(ss)); } catch (const boost::iostreams::bzip2_error& ex) { int error = ex.error(); - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Error decompressing record " << numRecords; + logger_->warn("Error decompressing record {}", numRecords); is.seekg(startPosition + std::streampos(recordSize), std::ios_base::beg); @@ -297,15 +288,14 @@ size_t Ar2vFileImpl::DecompressLDMRecords(std::istream& is) ++numRecords; } - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Decompressed " << numRecords << " LDM Records"; + logger_->debug("Decompressed {} LDM Records", numRecords); return numRecords; } void Ar2vFileImpl::ParseLDMRecords() { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Parsing LDM Records"; + logger_->debug("Parsing LDM Records"); size_t count = 0; @@ -313,7 +303,7 @@ void Ar2vFileImpl::ParseLDMRecords() { std::stringstream& ss = *it; - BOOST_LOG_TRIVIAL(trace) << logPrefix_ << "Record " << count++; + logger_->trace("Record {}", count++); ParseLDMRecord(ss); } @@ -346,8 +336,7 @@ void Ar2vFileImpl::ParseLDMRecord(std::istream& is) if (!is.eof() && offset != 0) { - BOOST_LOG_TRIVIAL(trace) - << logPrefix_ << "Next record offset by " << offset << " bytes"; + logger_->trace("Next record offset by {} bytes", offset); } else if (is.eof()) { @@ -382,7 +371,8 @@ void Ar2vFileImpl::HandleMessage(std::shared_ptr& message) std::static_pointer_cast(message)); break; - default: break; + default: + break; } } @@ -402,12 +392,11 @@ void Ar2vFileImpl::ProcessRadarData( void Ar2vFileImpl::IndexFile() { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Indexing file"; + logger_->debug("Indexing file"); if (vcpData_ == nullptr) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Cannot index file without VCP data"; + logger_->warn("Cannot index file without VCP data"); return; } diff --git a/wxdata/source/scwx/wsr88d/level3_file.cpp b/wxdata/source/scwx/wsr88d/level3_file.cpp index 46508b7c..eb5613fc 100644 --- a/wxdata/source/scwx/wsr88d/level3_file.cpp +++ b/wxdata/source/scwx/wsr88d/level3_file.cpp @@ -1,20 +1,21 @@ #include #include #include +#include #include #include #include #include -#include namespace scwx { namespace wsr88d { -static const std::string logPrefix_ = "[scwx::wsr88d::level3_file] "; +static const std::string logPrefix_ = "scwx::wsr88d::level3_file"; +static const auto logger_ = util::Logger::Create(logPrefix_); class Level3FileImpl { @@ -50,14 +51,13 @@ std::shared_ptr Level3File::message() const bool Level3File::LoadFile(const std::string& filename) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "LoadFile(" << filename << ")"; + logger_->debug("LoadFile: {}", filename); bool fileValid = true; std::ifstream f(filename, std::ios_base::in | std::ios_base::binary); if (!f.good()) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Could not open file for reading: " << filename; + logger_->warn("Could not open file for reading: {}", filename); fileValid = false; } @@ -71,7 +71,7 @@ bool Level3File::LoadFile(const std::string& filename) bool Level3File::LoadData(std::istream& is) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Loading Data"; + logger_->debug("Loading Data"); p->wmoHeader_ = std::make_shared(); @@ -79,16 +79,11 @@ bool Level3File::LoadData(std::istream& is) if (dataValid) { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Data Type: " << p->wmoHeader_->data_type(); - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "ICAO: " << p->wmoHeader_->icao(); - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Date/Time: " << p->wmoHeader_->date_time(); - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Category: " << p->wmoHeader_->product_category(); - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Site ID: " << p->wmoHeader_->product_designator(); + logger_->debug("Data Type: {}", p->wmoHeader_->data_type()); + logger_->debug("ICAO: {}", p->wmoHeader_->icao()); + logger_->debug("Date/Time: {}", p->wmoHeader_->date_time()); + logger_->debug("Category: {}", p->wmoHeader_->product_category()); + logger_->debug("Site ID: {}", p->wmoHeader_->product_designator()); // If the header is compressed if (is.peek() == 0x78) @@ -146,20 +141,15 @@ bool Level3FileImpl::DecompressFile(std::istream& is, std::stringstream& ss) { int error = ex.error(); - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Error decompressing data: " << ex.what(); + logger_->warn("Error decompressing data: {}", ex.what()); dataValid = false; } if (dataValid) { - BOOST_LOG_TRIVIAL(trace) - << logPrefix_ << "Input data consumed = " << totalBytesCopied - << " bytes"; - BOOST_LOG_TRIVIAL(trace) - << logPrefix_ << "Decompressed data size = " << totalBytesConsumed - << " bytes"; + logger_->trace("Input data consumed = {} bytes", totalBytesCopied); + logger_->trace("Decompressed data size = {} bytes", totalBytesConsumed); ccbHeader_ = std::make_shared(); dataValid = ccbHeader_->Parse(ss); diff --git a/wxdata/source/scwx/wsr88d/nexrad_file_factory.cpp b/wxdata/source/scwx/wsr88d/nexrad_file_factory.cpp index 08aa2b72..7d46a83f 100644 --- a/wxdata/source/scwx/wsr88d/nexrad_file_factory.cpp +++ b/wxdata/source/scwx/wsr88d/nexrad_file_factory.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -8,19 +9,19 @@ #include #include #include -#include namespace scwx { namespace wsr88d { -static const std::string logPrefix_ = "[scwx::wsr88d::nexrad_file_factory] "; +static const std::string logPrefix_ = "scwx::wsr88d::nexrad_file_factory"; +static const auto logger_ = util::Logger::Create(logPrefix_); std::shared_ptr NexradFileFactory::Create(const std::string& filename) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Create(" << filename << ")"; + logger_->debug("Create: {}", filename); std::shared_ptr nexradFile = nullptr; bool fileValid = true; @@ -28,8 +29,7 @@ NexradFileFactory::Create(const std::string& filename) std::ifstream f(filename, std::ios_base::in | std::ios_base::binary); if (!f.good()) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Could not open file for reading: " << filename; + logger_->warn("Could not open file for reading: {}", filename); fileValid = false; } @@ -74,26 +74,23 @@ std::shared_ptr NexradFileFactory::Create(std::istream& is) dataValid = ss.good(); ss.seekg(pisBegin, std::ios_base::beg); - BOOST_LOG_TRIVIAL(trace) - << logPrefix_ << "Decompressed file = " << bytesCopied << " bytes"; + logger_->trace("Decompressed file = {} bytes", bytesCopied); if (!dataValid) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Error reading decompressed stream"; + logger_->warn("Error reading decompressed stream"); } } catch (const boost::iostreams::gzip_error& ex) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Error decompressing file: " << ex.what(); + logger_->warn("Error decompressing file: {}", ex.what()); dataValid = false; } } else if (!dataValid) { - BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Error reading file"; + logger_->warn("Error reading file"); } if (dataValid)