From 44bcc7dd4ce91d402a49bea874ffde79831c950b Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 16 Apr 2022 07:48:49 -0500 Subject: [PATCH] Boost.Log -> spdlog - awips and common --- wxdata/source/scwx/awips/coded_location.cpp | 35 ++++++++-------- .../scwx/awips/coded_time_motion_location.cpp | 41 ++++++++----------- wxdata/source/scwx/awips/message.cpp | 23 +++++------ wxdata/source/scwx/awips/phenomenon.cpp | 8 ++-- wxdata/source/scwx/awips/pvtec.cpp | 20 ++++----- wxdata/source/scwx/awips/significance.cpp | 8 ++-- .../source/scwx/awips/text_product_file.cpp | 13 +++--- .../scwx/awips/text_product_message.cpp | 4 +- wxdata/source/scwx/awips/wmo_header.cpp | 22 +++++----- wxdata/source/scwx/common/color_table.cpp | 11 +++-- 10 files changed, 82 insertions(+), 103 deletions(-) diff --git a/wxdata/source/scwx/awips/coded_location.cpp b/wxdata/source/scwx/awips/coded_location.cpp index f6ff067a..fb93b9fb 100644 --- a/wxdata/source/scwx/awips/coded_location.cpp +++ b/wxdata/source/scwx/awips/coded_location.cpp @@ -1,15 +1,15 @@ #include +#include #include -#include - namespace scwx { namespace awips { -static const std::string logPrefix_ = "[scwx::awips::coded_location] "; +static const std::string logPrefix_ = "scwx::awips::coded_location"; +static const auto logger_ = util::Logger::Create(logPrefix_); class CodedLocationImpl { @@ -93,9 +93,8 @@ bool CodedLocation::Parse(const StringRange& lines, const std::string& wfo) } catch (const std::exception& ex) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Invalid WFO location token: \"" << *token - << "\" (" << ex.what() << ")"; + logger_->warn( + "Invalid WFO location token: \"{}\" ({})", *token, ex.what()); dataValid = false; break; } @@ -128,10 +127,8 @@ bool CodedLocation::Parse(const StringRange& lines, const std::string& wfo) { if (token->size() != 8) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ - << "Invalid National Center LAT...LON format: \"" << *token - << "\""; + logger_->warn("Invalid National Center LAT...LON format: \"{}\"", + *token); dataValid = false; break; @@ -147,9 +144,10 @@ bool CodedLocation::Parse(const StringRange& lines, const std::string& wfo) } catch (const std::exception& ex) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Invalid National Center location token: \"" - << *token << "\" (" << ex.what() << ")"; + logger_->warn( + "Invalid National Center location token: \"{}\" ({})", + *token, + ex.what()); dataValid = false; break; } @@ -174,18 +172,17 @@ bool CodedLocation::Parse(const StringRange& lines, const std::string& wfo) { if (tokenList.empty()) { - BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "LAT...LON not found"; + logger_->warn("LAT...LON not found"); } else { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ - << "Malformed LAT...LON tokens: (0: " << tokenList.at(0) - << ", size: " << tokenList.size() << ")"; + logger_->warn("Malformed LAT...LON tokens: (0: {}, size: {})", + tokenList.at(0), + tokenList.size()); for (const auto& token : tokenList) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << token; + logger_->debug("{}", token); } } diff --git a/wxdata/source/scwx/awips/coded_time_motion_location.cpp b/wxdata/source/scwx/awips/coded_time_motion_location.cpp index e3f94bea..f5b5a4ab 100644 --- a/wxdata/source/scwx/awips/coded_time_motion_location.cpp +++ b/wxdata/source/scwx/awips/coded_time_motion_location.cpp @@ -4,18 +4,17 @@ #endif #include +#include #include -#include - namespace scwx { namespace awips { -static const std::string logPrefix_ = - "[scwx::awips::coded_time_motion_location] "; +static const std::string logPrefix_ = "scwx::awips::coded_time_motion_location"; +static const auto logger_ = util::Logger::Create(logPrefix_); class CodedTimeMotionLocationImpl { @@ -111,8 +110,7 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines, } else { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Invalid time: \"" << time << "\""; + logger_->warn("Invalid time: \"{}\"", time); p->time_ = hh_mm_ss {}; dataValid = false; } @@ -129,16 +127,14 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines, } catch (const std::exception& ex) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Invalid direction: \"" << direction << "\" (" - << ex.what() << ")"; + logger_->warn( + "Invalid direction: \"{}\" ({})", direction, ex.what()); dataValid = false; } } else { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Invalid direction: \"" << direction << "\""; + logger_->warn("Invalid direction: \"{}\"", direction); dataValid = false; } @@ -153,15 +149,13 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines, } catch (const std::exception& ex) { - BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Invalid speed: \"" - << speed << "\" (" << ex.what() << ")"; + logger_->warn("Invalid speed: \"{}\" ({})", speed, ex.what()); dataValid = false; } } else { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Invalid speed: \"" << speed << "\""; + logger_->warn("Invalid speed: \"{}\"", speed); dataValid = false; } @@ -180,9 +174,8 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines, } catch (const std::exception& ex) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Invalid location token: \"" << *token << "\" (" - << ex.what() << ")"; + logger_->warn( + "Invalid location token: \"{}\" ({})", *token, ex.what()); dataValid = false; break; } @@ -212,19 +205,17 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines, { if (tokenList.empty()) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "TIME...MOT...LOC not found"; + logger_->warn("TIME...MOT...LOC not found"); } else { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ - << "Malformed TIME...MOT...LOC tokens: (0: " << tokenList.at(0) - << ", size: " << tokenList.size() << ")"; + logger_->warn("Malformed TIME...MOT...LOC tokens: (0: {}, size: {})", + tokenList.at(0), + tokenList.size()); for (const auto& token : tokenList) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << token; + logger_->debug("{}", token); } } diff --git a/wxdata/source/scwx/awips/message.cpp b/wxdata/source/scwx/awips/message.cpp index 23005396..73ae88a2 100644 --- a/wxdata/source/scwx/awips/message.cpp +++ b/wxdata/source/scwx/awips/message.cpp @@ -1,13 +1,13 @@ #include - -#include +#include namespace scwx { namespace awips { -static const std::string logPrefix_ = "[scwx::awips::message] "; +static const std::string logPrefix_ = "scwx::awips::message"; +static const auto logger_ = util::Logger::Create(logPrefix_); class MessageImpl { @@ -30,13 +30,12 @@ bool Message::ValidateMessage(std::istream& is, size_t bytesRead) const if (is.eof()) { - BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Reached end of data stream"; + logger_->warn("Reached end of data stream"); messageValid = false; } else if (is.fail()) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Could not read from input stream"; + logger_->warn("Could not read from input stream"); messageValid = false; } else if (bytesRead != dataSize) @@ -47,15 +46,15 @@ bool Message::ValidateMessage(std::istream& is, size_t bytesRead) const if (bytesRead < dataSize) { - BOOST_LOG_TRIVIAL(trace) - << logPrefix_ << "Message contents smaller than size: " << bytesRead - << " < " << dataSize << " bytes"; + logger_->trace("Message contents smaller than size: {} < {} bytes", + bytesRead, + dataSize); } if (bytesRead > dataSize) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Message contents larger than size: " << bytesRead - << " > " << dataSize << " bytes"; + logger_->warn("Message contents larger than size: {} > {} bytes", + bytesRead, + dataSize); messageValid = false; } } diff --git a/wxdata/source/scwx/awips/phenomenon.cpp b/wxdata/source/scwx/awips/phenomenon.cpp index ea97fe3f..ee8e549d 100644 --- a/wxdata/source/scwx/awips/phenomenon.cpp +++ b/wxdata/source/scwx/awips/phenomenon.cpp @@ -1,16 +1,17 @@ #include +#include #include #include #include -#include namespace scwx { namespace awips { -static const std::string logPrefix_ = "[scwx::awips::phenomenon] "; +static const std::string logPrefix_ = "scwx::awips::phenomenon"; +static const auto logger_ = util::Logger::Create(logPrefix_); typedef boost::bimap, boost::bimaps::unordered_set_of> @@ -147,8 +148,7 @@ Phenomenon GetPhenomenon(const std::string& code) { phenomenon = Phenomenon::Unknown; - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Unrecognized code: \"" << code << "\""; + logger_->debug("Unrecognized code: \"{}\"", code); } return phenomenon; diff --git a/wxdata/source/scwx/awips/pvtec.cpp b/wxdata/source/scwx/awips/pvtec.cpp index e8987052..1e8ded8d 100644 --- a/wxdata/source/scwx/awips/pvtec.cpp +++ b/wxdata/source/scwx/awips/pvtec.cpp @@ -4,20 +4,21 @@ #endif #include +#include #include #include #include #include -#include namespace scwx { namespace awips { -static const std::string logPrefix_ = "[scwx::awips::pvtec] "; +static const std::string logPrefix_ = "scwx::awips::pvtec"; +static const auto logger_ = util::Logger::Create(logPrefix_); typedef boost::bimap, boost::bimaps::unordered_set_of> @@ -171,9 +172,9 @@ bool PVtec::Parse(const std::string& s) } catch (const std::exception& ex) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Error parsing event tracking number: \"" - << eventNumberString << "\" (" << ex.what() << ")"; + logger_->warn("Error parsing event tracking number: \"{}\" ({})", + eventNumberString, + ex.what()); p->eventTrackingNumber_ = -1; } @@ -214,8 +215,7 @@ bool PVtec::Parse(const std::string& s) } else { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Invalid P-VTEC: \"" << s << "\""; + logger_->warn("Invalid P-VTEC: \"{}\"", s); } p->valid_ = dataValid; @@ -235,8 +235,7 @@ PVtec::ProductType PVtec::GetProductType(const std::string& code) { productType = ProductType::Unknown; - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Unrecognized product code: \"" << code << "\""; + logger_->debug("Unrecognized product code: \"{}\"", code); } return productType; @@ -259,8 +258,7 @@ PVtec::Action PVtec::GetAction(const std::string& code) { action = Action::Unknown; - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Unrecognized action code: \"" << code << "\""; + logger_->debug("Unrecognized action code: \"{}\"", code); } return action; diff --git a/wxdata/source/scwx/awips/significance.cpp b/wxdata/source/scwx/awips/significance.cpp index 0be08056..6d1d8671 100644 --- a/wxdata/source/scwx/awips/significance.cpp +++ b/wxdata/source/scwx/awips/significance.cpp @@ -1,16 +1,17 @@ #include +#include #include #include #include -#include namespace scwx { namespace awips { -static const std::string logPrefix_ = "[scwx::awips::significance] "; +static const std::string logPrefix_ = "scwx::awips::significance"; +static const auto logger_ = util::Logger::Create(logPrefix_); typedef boost::bimap, boost::bimaps::unordered_set_of> @@ -49,8 +50,7 @@ Significance GetSignificance(const std::string& code) { significance = Significance::Unknown; - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Unrecognized code: \"" << code << "\""; + logger_->debug("Unrecognized code: \"{}\"", code); } return significance; diff --git a/wxdata/source/scwx/awips/text_product_file.cpp b/wxdata/source/scwx/awips/text_product_file.cpp index 724c258c..1e738ef6 100644 --- a/wxdata/source/scwx/awips/text_product_file.cpp +++ b/wxdata/source/scwx/awips/text_product_file.cpp @@ -1,15 +1,15 @@ #include +#include #include -#include - namespace scwx { namespace awips { -static const std::string logPrefix_ = "[scwx::awips::text_product_file] "; +static const std::string logPrefix_ = "scwx::awips::text_product_file"; +static const auto logger_ = util::Logger::Create(logPrefix_); class TextProductFileImpl { @@ -41,14 +41,13 @@ std::shared_ptr TextProductFile::message(size_t i) const bool TextProductFile::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; } @@ -62,7 +61,7 @@ bool TextProductFile::LoadFile(const std::string& filename) bool TextProductFile::LoadData(std::istream& is) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Loading Data"; + logger_->debug("Loading Data"); while (!is.eof()) { diff --git a/wxdata/source/scwx/awips/text_product_message.cpp b/wxdata/source/scwx/awips/text_product_message.cpp index c6250041..f5753a8a 100644 --- a/wxdata/source/scwx/awips/text_product_message.cpp +++ b/wxdata/source/scwx/awips/text_product_message.cpp @@ -9,14 +9,12 @@ #include #include -#include - namespace scwx { namespace awips { -static const std::string logPrefix_ = "[scwx::awips::text_product_message] "; +static const std::string logPrefix_ = "scwx::awips::text_product_message"; // Issuance date/time takes one of the following forms: // * _xM__day_mon_
_year diff --git a/wxdata/source/scwx/awips/wmo_header.cpp b/wxdata/source/scwx/awips/wmo_header.cpp index 04a98192..6fa813cc 100644 --- a/wxdata/source/scwx/awips/wmo_header.cpp +++ b/wxdata/source/scwx/awips/wmo_header.cpp @@ -1,12 +1,11 @@ #include +#include #include #include #include #include -#include - #ifdef WIN32 # include #else @@ -18,7 +17,8 @@ namespace scwx namespace awips { -static const std::string logPrefix_ = "[scwx::awips::wmo_header] "; +static const std::string logPrefix_ = "scwx::awips::wmo_header"; +static const auto logger_ = util::Logger::Create(logPrefix_); class WmoHeaderImpl { @@ -139,7 +139,7 @@ bool WmoHeader::Parse(std::istream& is) if (is.eof()) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; + logger_->debug("Reached end of file"); headerValid = false; } else @@ -176,29 +176,28 @@ bool WmoHeader::Parse(std::istream& is) if (wmoTokenList.size() < 3 || wmoTokenList.size() > 4) { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Invalid number of WMO tokens"; + logger_->debug("Invalid number of WMO tokens"); headerValid = false; } else if (wmoTokenList[0].size() != 6) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "WMO identifier malformed"; + logger_->debug("WMO identifier malformed"); headerValid = false; } else if (wmoTokenList[1].size() != 4) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "ICAO malformed"; + logger_->debug("ICAO malformed"); headerValid = false; } else if (wmoTokenList[2].size() != 6) { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Date/time malformed"; + logger_->debug("Date/time malformed"); headerValid = false; } else if (wmoTokenList.size() == 4 && wmoTokenList[3].size() != 3) { // BBB indicator is optional - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "BBB indicator malformed"; + logger_->debug("BBB indicator malformed"); headerValid = false; } else @@ -227,8 +226,7 @@ bool WmoHeader::Parse(std::istream& is) { if (awipsLine.size() != 6) { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "AWIPS Identifier Line bad size"; + logger_->debug("AWIPS Identifier Line bad size"); headerValid = false; } else diff --git a/wxdata/source/scwx/common/color_table.cpp b/wxdata/source/scwx/common/color_table.cpp index e24cb8eb..48d9f0ea 100644 --- a/wxdata/source/scwx/common/color_table.cpp +++ b/wxdata/source/scwx/common/color_table.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -9,7 +10,6 @@ #include #include -#include #include @@ -18,7 +18,8 @@ namespace scwx namespace common { -static const std::string logPrefix_ {"[scwx::common::color_table] "}; +static const std::string logPrefix_ {"scwx::common::color_table"}; +static const auto logger_ = util::Logger::Create(logPrefix_); enum class ColorMode { @@ -135,8 +136,7 @@ bool ColorTable::IsValid() const std::shared_ptr ColorTable::Load(const std::string& filename) { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Loading color table: " << filename; + logger_->debug("Loading color table: {}", filename); std::shared_ptr p = std::make_shared(); @@ -167,8 +167,7 @@ std::shared_ptr ColorTable::Load(const std::string& filename) } catch (const std::exception&) { - BOOST_LOG_TRIVIAL(warning) - << logPrefix_ << "Could not parse line: " << line; + logger_->warn("Could not parse line: {}", line); } } }