Skip to content
Snippets Groups Projects
Unverified Commit 932c8ea6 authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

Logging Update (#289)

* Added and registered the log when a new plugin is being created

* Updated frame and ls models to log to a registered spdlogger only if it exists

* Updated h files in line with new named logger approach

* Fixed failing tests

* Resolved rebase changes that snuck back in

* Set default logger for framer

* Updated default logger for the framer

* Added more checks to prevent seg faults from a poorly set environment variable

* Removed try catch blocks and one register command

* Updated sensor models to carry around a pointer to the logger
parent a53f9cfe
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,6 @@
#include "Utilities.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
#include <json/json.hpp>
......@@ -324,7 +323,7 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, virtual public csm::Sett
csm::param::Set pSet = csm::param::VALID,
const GeometricModelList &otherModels = GeometricModelList()) const;
virtual std::shared_ptr<spdlog::logger> getLogger();
virtual void setLogger(std::shared_ptr<spdlog::logger> logger);
virtual void setLogger(std::string logName);
double getValue(int index, const std::vector<double> &adjustments) const;
void calcRotationMatrix(double m[3][3]) const;
void calcRotationMatrix(double m[3][3], const std::vector<double> &adjustments) const;
......@@ -385,8 +384,7 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, virtual public csm::Sett
csm::EcefCoord m_referencePointXyz;
std::string m_logFile;
std::shared_ptr<spdlog::logger> m_logger;
std::shared_ptr<spdlog::logger> m_logger = spdlog::get("usgscsm_logger");
json _state;
static const int _NUM_STATE_KEYWORDS;
......
......@@ -33,7 +33,6 @@
#include "Distortion.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
class UsgsAstroLsSensorModel : public csm::RasterGM, virtual public csm::SettableEllipsoid
{
......@@ -64,7 +63,7 @@ public:
static std::string getModelNameFromModelState(
const std::string& model_state);
std::string constructStateFromIsd(const std::string imageSupportData, csm::WarningList *list) const;
std::string constructStateFromIsd(const std::string imageSupportData, csm::WarningList *list);
// State data elements;
std::string m_imageIdentifier;
......@@ -125,8 +124,7 @@ public:
// Define logging pointer and file content
std::string m_logFile;
std::shared_ptr<spdlog::logger> m_logger;
std::shared_ptr<spdlog::logger> m_logger = spdlog::get("usgscsm_logger");
// Hardcoded
static const std::string _SENSOR_MODEL_NAME; // state date element 0
......@@ -697,7 +695,7 @@ public:
//<
virtual std::shared_ptr<spdlog::logger> getLogger();
virtual void setLogger(std::shared_ptr<spdlog::logger> logger);
virtual void setLogger(std::string logName);
//---
......
......@@ -7,6 +7,9 @@
#include <Plugin.h>
#include <Version.h>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
#include <json/json.hpp>
using json = nlohmann::json;
......
This diff is collapsed.
This diff is collapsed.
......@@ -36,6 +36,21 @@ const int UsgsAstroPlugin::_N_SENSOR_MODELS = 3;
const UsgsAstroPlugin UsgsAstroPlugin::m_registeredPlugin;
UsgsAstroPlugin::UsgsAstroPlugin() {
// Build and register the USGSCSM logger on pluggin creation
char * logFilePtr = getenv("ALE_LOG_FILE");
if (logFilePtr != NULL) {
std::string logFile(logFilePtr);
if (logFile != "") {
std::shared_ptr<spdlog::logger> logger = spdlog::get("usgscsm_logger");
if (!logger) {
std::shared_ptr<spdlog::logger> new_logger = spdlog::basic_logger_mt("usgscsm_logger", logFile);
}
}
}
}
......@@ -264,8 +279,9 @@ csm::Model *UsgsAstroPlugin::constructModelFromISD(const csm::Isd &imageSupportD
UsgsAstroFrameSensorModel *model = new UsgsAstroFrameSensorModel();
try {
model->replaceModelState(model->constructStateFromIsd(stringIsd, warnings));
if (model->getLogger()) {
model->getLogger()->info("Constructed model: {}", modelName);
std::shared_ptr<spdlog::logger> logger = model->getLogger();
if (logger) {
logger->info("Constructed model: {}", modelName);
}
}
catch (std::exception& e) {
......
......@@ -90,11 +90,17 @@ class FrameSensorModelLogging : public ::testing::Test {
// logger name collisions. Use the sensor model's memory addresss.
std::uintptr_t sensorId = reinterpret_cast<std::uintptr_t>(sensorModel);
auto logger = std::make_shared<spdlog::logger>(std::to_string(sensorId), ostream_sink);
sensorModel->setLogger(logger);
spdlog::register_logger(logger);
sensorModel->setLogger(std::to_string(sensorId));
}
void TearDown() override {
if (sensorModel) {
// Remove the logger from the registry for other tests
std::uintptr_t sensorId = reinterpret_cast<std::uintptr_t>(sensorModel);
spdlog::drop(std::to_string(sensorId));
delete sensorModel;
sensorModel = NULL;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment