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/util/logger.hpp>
#include <sstream>
#include <boost/log/trivial.hpp>
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);
}
}

View file

@ -4,18 +4,17 @@
#endif
#include <scwx/awips/coded_time_motion_location.hpp>
#include <scwx/util/logger.hpp>
#include <sstream>
#include <boost/log/trivial.hpp>
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<minutes> {};
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);
}
}

View file

@ -1,13 +1,13 @@
#include <scwx/awips/message.hpp>
#include <boost/log/trivial.hpp>
#include <scwx/util/logger.hpp>
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;
}
}

View file

@ -1,16 +1,17 @@
#include <scwx/awips/phenomenon.hpp>
#include <scwx/util/logger.hpp>
#include <boost/assign.hpp>
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/log/trivial.hpp>
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<Phenomenon>,
boost::bimaps::unordered_set_of<std::string>>
@ -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;

View file

@ -4,20 +4,21 @@
#endif
#include <scwx/awips/pvtec.hpp>
#include <scwx/util/logger.hpp>
#include <chrono>
#include <boost/assign.hpp>
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/log/trivial.hpp>
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<PVtec::ProductType>,
boost::bimaps::unordered_set_of<std::string>>
@ -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;

View file

@ -1,16 +1,17 @@
#include <scwx/awips/significance.hpp>
#include <scwx/util/logger.hpp>
#include <boost/assign.hpp>
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/log/trivial.hpp>
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<Significance>,
boost::bimaps::unordered_set_of<std::string>>
@ -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;

View file

@ -1,15 +1,15 @@
#include <scwx/awips/text_product_file.hpp>
#include <scwx/util/logger.hpp>
#include <fstream>
#include <boost/log/trivial.hpp>
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<TextProductMessage> 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())
{

View file

@ -9,14 +9,12 @@
#include <regex>
#include <string>
#include <boost/log/trivial.hpp>
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:
// * <hhmm>_xM_<tz>_day_mon_<dd>_year

View file

@ -1,12 +1,11 @@
#include <scwx/awips/wmo_header.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/streams.hpp>
#include <istream>
#include <sstream>
#include <string>
#include <boost/log/trivial.hpp>
#ifdef WIN32
# include <WinSock2.h>
#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

View file

@ -1,4 +1,5 @@
#include <scwx/common/color_table.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/streams.hpp>
#include <cmath>
@ -9,7 +10,6 @@
#include <sstream>
#include <boost/gil.hpp>
#include <boost/log/trivial.hpp>
#include <hsluv.h>
@ -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> ColorTable::Load(const std::string& filename)
{
BOOST_LOG_TRIVIAL(debug)
<< logPrefix_ << "Loading color table: " << filename;
logger_->debug("Loading color table: {}", filename);
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&)
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Could not parse line: " << line;
logger_->warn("Could not parse line: {}", line);
}
}
}