Boost.Log -> spdlog - awips and common

This commit is contained in:
Dan Paulat 2022-04-16 07:48:49 -05:00
parent 3d162f0336
commit 44bcc7dd4c
10 changed files with 82 additions and 103 deletions

View file

@ -1,15 +1,15 @@
#include <scwx/awips/coded_location.hpp> #include <scwx/awips/coded_location.hpp>
#include <scwx/util/logger.hpp>
#include <sstream> #include <sstream>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace awips 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 class CodedLocationImpl
{ {
@ -93,9 +93,8 @@ bool CodedLocation::Parse(const StringRange& lines, const std::string& wfo)
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn(
<< logPrefix_ << "Invalid WFO location token: \"" << *token "Invalid WFO location token: \"{}\" ({})", *token, ex.what());
<< "\" (" << ex.what() << ")";
dataValid = false; dataValid = false;
break; break;
} }
@ -128,10 +127,8 @@ bool CodedLocation::Parse(const StringRange& lines, const std::string& wfo)
{ {
if (token->size() != 8) if (token->size() != 8)
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Invalid National Center LAT...LON format: \"{}\"",
<< logPrefix_ *token);
<< "Invalid National Center LAT...LON format: \"" << *token
<< "\"";
dataValid = false; dataValid = false;
break; break;
@ -147,9 +144,10 @@ bool CodedLocation::Parse(const StringRange& lines, const std::string& wfo)
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn(
<< logPrefix_ << "Invalid National Center location token: \"" "Invalid National Center location token: \"{}\" ({})",
<< *token << "\" (" << ex.what() << ")"; *token,
ex.what());
dataValid = false; dataValid = false;
break; break;
} }
@ -174,18 +172,17 @@ bool CodedLocation::Parse(const StringRange& lines, const std::string& wfo)
{ {
if (tokenList.empty()) if (tokenList.empty())
{ {
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "LAT...LON not found"; logger_->warn("LAT...LON not found");
} }
else else
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Malformed LAT...LON tokens: (0: {}, size: {})",
<< logPrefix_ tokenList.at(0),
<< "Malformed LAT...LON tokens: (0: " << tokenList.at(0) tokenList.size());
<< ", size: " << tokenList.size() << ")";
for (const auto& token : tokenList) for (const auto& token : tokenList)
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << token; logger_->debug("{}", token);
} }
} }

View file

@ -4,18 +4,17 @@
#endif #endif
#include <scwx/awips/coded_time_motion_location.hpp> #include <scwx/awips/coded_time_motion_location.hpp>
#include <scwx/util/logger.hpp>
#include <sstream> #include <sstream>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace awips namespace awips
{ {
static const std::string logPrefix_ = static const std::string logPrefix_ = "scwx::awips::coded_time_motion_location";
"[scwx::awips::coded_time_motion_location] "; static const auto logger_ = util::Logger::Create(logPrefix_);
class CodedTimeMotionLocationImpl class CodedTimeMotionLocationImpl
{ {
@ -111,8 +110,7 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines,
} }
else else
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Invalid time: \"{}\"", time);
<< logPrefix_ << "Invalid time: \"" << time << "\"";
p->time_ = hh_mm_ss<minutes> {}; p->time_ = hh_mm_ss<minutes> {};
dataValid = false; dataValid = false;
} }
@ -129,16 +127,14 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines,
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn(
<< logPrefix_ << "Invalid direction: \"" << direction << "\" (" "Invalid direction: \"{}\" ({})", direction, ex.what());
<< ex.what() << ")";
dataValid = false; dataValid = false;
} }
} }
else else
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Invalid direction: \"{}\"", direction);
<< logPrefix_ << "Invalid direction: \"" << direction << "\"";
dataValid = false; dataValid = false;
} }
@ -153,15 +149,13 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines,
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Invalid speed: \"" logger_->warn("Invalid speed: \"{}\" ({})", speed, ex.what());
<< speed << "\" (" << ex.what() << ")";
dataValid = false; dataValid = false;
} }
} }
else else
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Invalid speed: \"{}\"", speed);
<< logPrefix_ << "Invalid speed: \"" << speed << "\"";
dataValid = false; dataValid = false;
} }
@ -180,9 +174,8 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines,
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn(
<< logPrefix_ << "Invalid location token: \"" << *token << "\" (" "Invalid location token: \"{}\" ({})", *token, ex.what());
<< ex.what() << ")";
dataValid = false; dataValid = false;
break; break;
} }
@ -212,19 +205,17 @@ bool CodedTimeMotionLocation::Parse(const StringRange& lines,
{ {
if (tokenList.empty()) if (tokenList.empty())
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("TIME...MOT...LOC not found");
<< logPrefix_ << "TIME...MOT...LOC not found";
} }
else else
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Malformed TIME...MOT...LOC tokens: (0: {}, size: {})",
<< logPrefix_ tokenList.at(0),
<< "Malformed TIME...MOT...LOC tokens: (0: " << tokenList.at(0) tokenList.size());
<< ", size: " << tokenList.size() << ")";
for (const auto& token : tokenList) for (const auto& token : tokenList)
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << token; logger_->debug("{}", token);
} }
} }

View file

@ -1,13 +1,13 @@
#include <scwx/awips/message.hpp> #include <scwx/awips/message.hpp>
#include <scwx/util/logger.hpp>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace awips 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 class MessageImpl
{ {
@ -30,13 +30,12 @@ bool Message::ValidateMessage(std::istream& is, size_t bytesRead) const
if (is.eof()) if (is.eof())
{ {
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Reached end of data stream"; logger_->warn("Reached end of data stream");
messageValid = false; messageValid = false;
} }
else if (is.fail()) else if (is.fail())
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Could not read from input stream");
<< logPrefix_ << "Could not read from input stream";
messageValid = false; messageValid = false;
} }
else if (bytesRead != dataSize) else if (bytesRead != dataSize)
@ -47,15 +46,15 @@ bool Message::ValidateMessage(std::istream& is, size_t bytesRead) const
if (bytesRead < dataSize) if (bytesRead < dataSize)
{ {
BOOST_LOG_TRIVIAL(trace) logger_->trace("Message contents smaller than size: {} < {} bytes",
<< logPrefix_ << "Message contents smaller than size: " << bytesRead bytesRead,
<< " < " << dataSize << " bytes"; dataSize);
} }
if (bytesRead > dataSize) if (bytesRead > dataSize)
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Message contents larger than size: {} > {} bytes",
<< logPrefix_ << "Message contents larger than size: " << bytesRead bytesRead,
<< " > " << dataSize << " bytes"; dataSize);
messageValid = false; messageValid = false;
} }
} }

View file

@ -1,16 +1,17 @@
#include <scwx/awips/phenomenon.hpp> #include <scwx/awips/phenomenon.hpp>
#include <scwx/util/logger.hpp>
#include <boost/assign.hpp> #include <boost/assign.hpp>
#include <boost/bimap.hpp> #include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp> #include <boost/bimap/unordered_set_of.hpp>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace awips 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<Phenomenon>, typedef boost::bimap<boost::bimaps::unordered_set_of<Phenomenon>,
boost::bimaps::unordered_set_of<std::string>> boost::bimaps::unordered_set_of<std::string>>
@ -147,8 +148,7 @@ Phenomenon GetPhenomenon(const std::string& code)
{ {
phenomenon = Phenomenon::Unknown; phenomenon = Phenomenon::Unknown;
BOOST_LOG_TRIVIAL(debug) logger_->debug("Unrecognized code: \"{}\"", code);
<< logPrefix_ << "Unrecognized code: \"" << code << "\"";
} }
return phenomenon; return phenomenon;

View file

@ -4,20 +4,21 @@
#endif #endif
#include <scwx/awips/pvtec.hpp> #include <scwx/awips/pvtec.hpp>
#include <scwx/util/logger.hpp>
#include <chrono> #include <chrono>
#include <boost/assign.hpp> #include <boost/assign.hpp>
#include <boost/bimap.hpp> #include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp> #include <boost/bimap/unordered_set_of.hpp>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace awips 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<PVtec::ProductType>, typedef boost::bimap<boost::bimaps::unordered_set_of<PVtec::ProductType>,
boost::bimaps::unordered_set_of<std::string>> boost::bimaps::unordered_set_of<std::string>>
@ -171,9 +172,9 @@ bool PVtec::Parse(const std::string& s)
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Error parsing event tracking number: \"{}\" ({})",
<< logPrefix_ << "Error parsing event tracking number: \"" eventNumberString,
<< eventNumberString << "\" (" << ex.what() << ")"; ex.what());
p->eventTrackingNumber_ = -1; p->eventTrackingNumber_ = -1;
} }
@ -214,8 +215,7 @@ bool PVtec::Parse(const std::string& s)
} }
else else
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Invalid P-VTEC: \"{}\"", s);
<< logPrefix_ << "Invalid P-VTEC: \"" << s << "\"";
} }
p->valid_ = dataValid; p->valid_ = dataValid;
@ -235,8 +235,7 @@ PVtec::ProductType PVtec::GetProductType(const std::string& code)
{ {
productType = ProductType::Unknown; productType = ProductType::Unknown;
BOOST_LOG_TRIVIAL(debug) logger_->debug("Unrecognized product code: \"{}\"", code);
<< logPrefix_ << "Unrecognized product code: \"" << code << "\"";
} }
return productType; return productType;
@ -259,8 +258,7 @@ PVtec::Action PVtec::GetAction(const std::string& code)
{ {
action = Action::Unknown; action = Action::Unknown;
BOOST_LOG_TRIVIAL(debug) logger_->debug("Unrecognized action code: \"{}\"", code);
<< logPrefix_ << "Unrecognized action code: \"" << code << "\"";
} }
return action; return action;

View file

@ -1,16 +1,17 @@
#include <scwx/awips/significance.hpp> #include <scwx/awips/significance.hpp>
#include <scwx/util/logger.hpp>
#include <boost/assign.hpp> #include <boost/assign.hpp>
#include <boost/bimap.hpp> #include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp> #include <boost/bimap/unordered_set_of.hpp>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace awips 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<Significance>, typedef boost::bimap<boost::bimaps::unordered_set_of<Significance>,
boost::bimaps::unordered_set_of<std::string>> boost::bimaps::unordered_set_of<std::string>>
@ -49,8 +50,7 @@ Significance GetSignificance(const std::string& code)
{ {
significance = Significance::Unknown; significance = Significance::Unknown;
BOOST_LOG_TRIVIAL(debug) logger_->debug("Unrecognized code: \"{}\"", code);
<< logPrefix_ << "Unrecognized code: \"" << code << "\"";
} }
return significance; return significance;

View file

@ -1,15 +1,15 @@
#include <scwx/awips/text_product_file.hpp> #include <scwx/awips/text_product_file.hpp>
#include <scwx/util/logger.hpp>
#include <fstream> #include <fstream>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace awips 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 class TextProductFileImpl
{ {
@ -41,14 +41,13 @@ std::shared_ptr<TextProductMessage> TextProductFile::message(size_t i) const
bool TextProductFile::LoadFile(const std::string& filename) bool TextProductFile::LoadFile(const std::string& filename)
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "LoadFile(" << filename << ")"; logger_->debug("LoadFile: {}", filename);
bool fileValid = true; bool fileValid = true;
std::ifstream f(filename, std::ios_base::in | std::ios_base::binary); std::ifstream f(filename, std::ios_base::in | std::ios_base::binary);
if (!f.good()) if (!f.good())
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Could not open file for reading: {}", filename);
<< logPrefix_ << "Could not open file for reading: " << filename;
fileValid = false; fileValid = false;
} }
@ -62,7 +61,7 @@ bool TextProductFile::LoadFile(const std::string& filename)
bool TextProductFile::LoadData(std::istream& is) bool TextProductFile::LoadData(std::istream& is)
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Loading Data"; logger_->debug("Loading Data");
while (!is.eof()) while (!is.eof())
{ {

View file

@ -9,14 +9,12 @@
#include <regex> #include <regex>
#include <string> #include <string>
#include <boost/log/trivial.hpp>
namespace scwx namespace scwx
{ {
namespace awips 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: // Issuance date/time takes one of the following forms:
// * <hhmm>_xM_<tz>_day_mon_<dd>_year // * <hhmm>_xM_<tz>_day_mon_<dd>_year

View file

@ -1,12 +1,11 @@
#include <scwx/awips/wmo_header.hpp> #include <scwx/awips/wmo_header.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/streams.hpp> #include <scwx/util/streams.hpp>
#include <istream> #include <istream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <boost/log/trivial.hpp>
#ifdef WIN32 #ifdef WIN32
# include <WinSock2.h> # include <WinSock2.h>
#else #else
@ -18,7 +17,8 @@ namespace scwx
namespace awips 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 class WmoHeaderImpl
{ {
@ -139,7 +139,7 @@ bool WmoHeader::Parse(std::istream& is)
if (is.eof()) if (is.eof())
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; logger_->debug("Reached end of file");
headerValid = false; headerValid = false;
} }
else else
@ -176,29 +176,28 @@ bool WmoHeader::Parse(std::istream& is)
if (wmoTokenList.size() < 3 || wmoTokenList.size() > 4) if (wmoTokenList.size() < 3 || wmoTokenList.size() > 4)
{ {
BOOST_LOG_TRIVIAL(debug) logger_->debug("Invalid number of WMO tokens");
<< logPrefix_ << "Invalid number of WMO tokens";
headerValid = false; headerValid = false;
} }
else if (wmoTokenList[0].size() != 6) else if (wmoTokenList[0].size() != 6)
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "WMO identifier malformed"; logger_->debug("WMO identifier malformed");
headerValid = false; headerValid = false;
} }
else if (wmoTokenList[1].size() != 4) else if (wmoTokenList[1].size() != 4)
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "ICAO malformed"; logger_->debug("ICAO malformed");
headerValid = false; headerValid = false;
} }
else if (wmoTokenList[2].size() != 6) else if (wmoTokenList[2].size() != 6)
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Date/time malformed"; logger_->debug("Date/time malformed");
headerValid = false; headerValid = false;
} }
else if (wmoTokenList.size() == 4 && wmoTokenList[3].size() != 3) else if (wmoTokenList.size() == 4 && wmoTokenList[3].size() != 3)
{ {
// BBB indicator is optional // BBB indicator is optional
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "BBB indicator malformed"; logger_->debug("BBB indicator malformed");
headerValid = false; headerValid = false;
} }
else else
@ -227,8 +226,7 @@ bool WmoHeader::Parse(std::istream& is)
{ {
if (awipsLine.size() != 6) if (awipsLine.size() != 6)
{ {
BOOST_LOG_TRIVIAL(debug) logger_->debug("AWIPS Identifier Line bad size");
<< logPrefix_ << "AWIPS Identifier Line bad size";
headerValid = false; headerValid = false;
} }
else else

View file

@ -1,4 +1,5 @@
#include <scwx/common/color_table.hpp> #include <scwx/common/color_table.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/streams.hpp> #include <scwx/util/streams.hpp>
#include <cmath> #include <cmath>
@ -9,7 +10,6 @@
#include <sstream> #include <sstream>
#include <boost/gil.hpp> #include <boost/gil.hpp>
#include <boost/log/trivial.hpp>
#include <hsluv.h> #include <hsluv.h>
@ -18,7 +18,8 @@ namespace scwx
namespace common 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 enum class ColorMode
{ {
@ -135,8 +136,7 @@ bool ColorTable::IsValid() const
std::shared_ptr<ColorTable> ColorTable::Load(const std::string& filename) std::shared_ptr<ColorTable> ColorTable::Load(const std::string& filename)
{ {
BOOST_LOG_TRIVIAL(debug) logger_->debug("Loading color table: {}", filename);
<< logPrefix_ << "Loading color table: " << filename;
std::shared_ptr<ColorTable> p = std::make_shared<ColorTable>(); std::shared_ptr<ColorTable> p = std::make_shared<ColorTable>();
@ -167,8 +167,7 @@ std::shared_ptr<ColorTable> ColorTable::Load(const std::string& filename)
} }
catch (const std::exception&) catch (const std::exception&)
{ {
BOOST_LOG_TRIVIAL(warning) logger_->warn("Could not parse line: {}", line);
<< logPrefix_ << "Could not parse line: " << line;
} }
} }
} }