Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ all clean:
$(MAKE) -C test/examples/9-Domains $@
$(MAKE) -C test/examples/10-Archiving $@
$(MAKE) -C test/examples/13-Relay $@
$(MAKE) -C test/examples/15-SpdlogDynamicConfiguration $@

# Perform each of the following in their own if block, otherwise a failure in the below make commands
# won't cause the overall build to fail.
Expand Down Expand Up @@ -131,6 +132,7 @@ test-prep:
chmod 755 test/examples/13-Relay/run.sh
chmod 755 test/examples/14-AnomalyDetection/train.sh
chmod 755 test/examples/14-AnomalyDetection/detect.sh
chmod 755 test/examples/15-SpdlogDynamicConfiguration/run.sh

test: distributable test-prep components
./test/testall.sh
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -6227,7 +6227,7 @@ fi

CPPFLAGS="$CPPFLAGS -Wall"

ac_config_files="$ac_config_files Makefile src/api/MATLAB/Makefile src/api/cpp/Makefile src/components/cpp/Makefile src/components/cpp/Archiver/Makefile src/components/cpp/ConfigServer/Makefile src/components/cpp/LogRecorder/Makefile src/components/cpp/Playback/Makefile src/components/cpp/Relay/Makefile src/components/cpp/ServiceDirectory/Makefile src/keyvalue_parser/Makefile test/components/cpp/Makefile test/components/cpp/ServiceDirectory/Makefile test/components/cpp/ServiceDirectoryReregister/Makefile src/api/java/cpp_makefile src/api/java/java_makefile src/api/python/cpp_makefile src/api/python/Makefile test/api/cpp/Makefile test/api/java/Makefile test/api/python/Makefile test/components/cpp/ServiceDirectory/test.sh test/components/cpp/ServiceDirectoryReregister/test.sh test/api/cpp/test.sh test/api/java/test.sh test/api/python/test.sh test/examples/1-BasicDataProduct/Makefile test/examples/1-BasicDataProduct/run.sh test/examples/2-ProtobufDataProduct/Makefile test/examples/2-ProtobufDataProduct/run.sh test/examples/3-MultipleDataProduct/Makefile test/examples/3-MultipleDataProduct/run.sh test/examples/4-BasicService/Makefile test/examples/4-BasicService/run.sh test/examples/5-MiscFunctionality/Makefile test/examples/5-MiscFunctionality/run.sh test/examples/6-JavaProtobufDataProduct/Makefile test/examples/6-JavaProtobufDataProduct/run.sh test/examples/7-JavaBasicService/Makefile test/examples/7-JavaBasicService/run.sh test/examples/8-ConfigFile/Makefile test/examples/8-ConfigFile/run.sh test/examples/9-Domains/Makefile test/examples/9-Domains/run.sh test/examples/10-Archiving/Makefile test/examples/10-Archiving/run.sh test/examples/11-PythonPubSub/run.sh test/examples/11-PythonPubSub/Makefile test/examples/12-PythonBasicService/run.sh test/examples/12-PythonBasicService/Makefile test/examples/13-Relay/Makefile test/examples/13-Relay/run.sh test/examples/14-AnomalyDetection/train.sh test/examples/14-AnomalyDetection/detect.sh "
ac_config_files="$ac_config_files Makefile src/api/MATLAB/Makefile src/api/cpp/Makefile src/components/cpp/Makefile src/components/cpp/Archiver/Makefile src/components/cpp/ConfigServer/Makefile src/components/cpp/LogRecorder/Makefile src/components/cpp/Playback/Makefile src/components/cpp/Relay/Makefile src/components/cpp/ServiceDirectory/Makefile src/keyvalue_parser/Makefile test/components/cpp/Makefile test/components/cpp/ServiceDirectory/Makefile test/components/cpp/ServiceDirectoryReregister/Makefile src/api/java/cpp_makefile src/api/java/java_makefile src/api/python/cpp_makefile src/api/python/Makefile test/api/cpp/Makefile test/api/java/Makefile test/api/python/Makefile test/components/cpp/ServiceDirectory/test.sh test/components/cpp/ServiceDirectoryReregister/test.sh test/api/cpp/test.sh test/api/java/test.sh test/api/python/test.sh test/examples/1-BasicDataProduct/Makefile test/examples/1-BasicDataProduct/run.sh test/examples/2-ProtobufDataProduct/Makefile test/examples/2-ProtobufDataProduct/run.sh test/examples/3-MultipleDataProduct/Makefile test/examples/3-MultipleDataProduct/run.sh test/examples/4-BasicService/Makefile test/examples/4-BasicService/run.sh test/examples/5-MiscFunctionality/Makefile test/examples/5-MiscFunctionality/run.sh test/examples/6-JavaProtobufDataProduct/Makefile test/examples/6-JavaProtobufDataProduct/run.sh test/examples/7-JavaBasicService/Makefile test/examples/7-JavaBasicService/run.sh test/examples/8-ConfigFile/Makefile test/examples/8-ConfigFile/run.sh test/examples/9-Domains/Makefile test/examples/9-Domains/run.sh test/examples/10-Archiving/Makefile test/examples/10-Archiving/run.sh test/examples/11-PythonPubSub/run.sh test/examples/11-PythonPubSub/Makefile test/examples/12-PythonBasicService/run.sh test/examples/12-PythonBasicService/Makefile test/examples/13-Relay/Makefile test/examples/13-Relay/run.sh test/examples/14-AnomalyDetection/train.sh test/examples/14-AnomalyDetection/detect.sh test/examples/15-SpdlogDynamicConfiguration/Makefile test/examples/15-SpdlogDynamicConfiguration/run.sh "


cat >confcache <<\_ACEOF
Expand Down
6 changes: 4 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ AC_CONFIG_FILES([Makefile
test/examples/12-PythonBasicService/Makefile
test/examples/13-Relay/Makefile
test/examples/13-Relay/run.sh
test/examples/14-AnomalyDetection/train.sh
test/examples/14-AnomalyDetection/detect.sh])
test/examples/14-AnomalyDetection/train.sh
test/examples/14-AnomalyDetection/detect.sh
test/examples/15-SpdlogDynamicConfiguration/Makefile
test/examples/15-SpdlogDynamicConfiguration/run.sh])

AC_OUTPUT

Expand Down
1 change: 1 addition & 0 deletions src/api/cpp/CommUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace gravity
const std::string METRICS_DATA_DPID = "GravityMetricsData";
const std::string GRAVITY_SETTINGS_DPID = "GRAVITY_SETTINGS";
const std::string GRAVITY_LOGGER_DPID = "GRAVITY_LOGGER";
const std::string SPD_LOG_CONFIG_DPID = "GravitySpdLogConfig";
}

/**
Expand Down
88 changes: 41 additions & 47 deletions src/api/cpp/GravityNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,61 +577,41 @@ void GravityNode::configSpdLoggers()
auto app_console_level = spdlog::level::from_str(StringToLowerCase(getStringParam("AppConsoleLogLevel", "off")));
auto app_publish_level = spdlog::level::from_str(StringToLowerCase(getStringParam("AppNetworkLogLevel", "off")));

bool has_gravity_file_logger = gravity_file_level != SPDLOG_LEVEL_OFF;
bool has_app_file_logger = app_file_level != SPDLOG_LEVEL_OFF;
bool has_app_console_logger = app_console_level != SPDLOG_LEVEL_OFF;
bool has_app_publish_logger = app_publish_level != SPDLOG_LEVEL_OFF;

bool has_app_logger = has_app_file_logger || has_app_console_logger || has_app_publish_logger;

// Create lists to hold sinks
std::list<shared_ptr<spdlog::sinks::sink>> app_sink_list = {};
std::list<shared_ptr<spdlog::sinks::sink>> gravity_sink_list = {};

// Always create console loggers
// Always create all loggers, some may be set to off
auto shared_console_sink = make_shared<spdlog::sinks::stdout_color_sink_mt>();

auto console_proxy_for_gravity = std::make_shared<proxy_dist_sink_mt>();
console_proxy_for_gravity->add_sink(shared_console_sink);
console_proxy_for_gravity->set_level(gravity_console_level);
gravity_sink_list.push_back(console_proxy_for_gravity);

auto console_proxy_for_app = std::make_shared<proxy_dist_sink_mt>();
console_proxy_for_app->add_sink(shared_console_sink);
console_proxy_for_app->set_level(app_console_level);
app_sink_list.push_back(console_proxy_for_app);

// Configure file logger (if specified)
if (has_gravity_file_logger || has_app_file_logger)
{
string filename = getStringParam("LogDirectory", ".") + file_separator + componentID + ".log";
auto sharedFileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename);

if (has_gravity_file_logger)
{
auto file_proxy_for_gravity = std::make_shared<proxy_dist_sink_mt>();
file_proxy_for_gravity->add_sink(sharedFileSink);
file_proxy_for_gravity->set_level(gravity_file_level);
gravity_sink_list.push_back(file_proxy_for_gravity);
}
string filename = getStringParam("LogDirectory", ".") + file_separator + componentID + ".log";
auto sharedFileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename);

auto file_proxy_for_gravity = std::make_shared<proxy_dist_sink_mt>();
file_proxy_for_gravity->add_sink(sharedFileSink);
file_proxy_for_gravity->set_level(gravity_file_level);
gravity_sink_list.push_back(file_proxy_for_gravity);

if (has_app_file_logger)
{
auto file_proxy_for_app = std::make_shared<proxy_dist_sink_mt>();
file_proxy_for_app->add_sink(sharedFileSink);
file_proxy_for_app->set_level(app_file_level);
app_sink_list.push_back(file_proxy_for_app);
}
auto file_proxy_for_app = std::make_shared<proxy_dist_sink_mt>();
file_proxy_for_app->add_sink(sharedFileSink);
file_proxy_for_app->set_level(app_file_level);
app_sink_list.push_back(file_proxy_for_app);

}

// Configure publish logger
if (has_app_publish_logger)
{
auto publishSink = std::make_shared<PublishSink<std::mutex>>(this);
auto publish_proxy_for_app = std::make_shared<proxy_dist_sink_mt>();
publish_proxy_for_app->add_sink(publishSink);
publish_proxy_for_app->set_level(app_publish_level);
app_sink_list.push_back(publish_proxy_for_app);
}
auto publishSink = std::make_shared<PublishSink<std::mutex>>(this);
auto publish_proxy_for_app = std::make_shared<proxy_dist_sink_mt>();
publish_proxy_for_app->add_sink(publishSink);
publish_proxy_for_app->set_level(app_publish_level);
app_sink_list.push_back(publish_proxy_for_app);

// Configure GravityLogger.
logger = std::make_shared<spdlog::logger>("GravityLogger");
Expand All @@ -654,12 +634,9 @@ void GravityNode::configSpdLoggers()
app_logger->flush_on(spdlog::level::trace); // logger will flush on all messages
app_logger->set_pattern("[%Y-%m-%d %T.%f " + componentID + "-%l] %v");
spdlog::register_logger(app_logger);

if (has_app_logger)
{
// Set the ApplicaitonLogger as the default
spdlog::set_default_logger(app_logger);
}

// Set the ApplicationLogger as the default
spdlog::set_default_logger(app_logger);
}

GravityReturnCode GravityNode::init()
Expand Down Expand Up @@ -1022,6 +999,16 @@ GravityReturnCode GravityNode::init(std::string componentID)
logger->warn("Gravity.ini specifies both Domain and URL. Using URL.");
}

if(componentID != "ServiceDirectory")
{
// Register subscriber to allow for dynamic logging changes
GravityReturnCode ret = registerSpdlogDynamicConfiguration();
if (ret!=GravityReturnCodes::SUCCESS)
{
logger->error(" {}'s Dynamic SpdLog Subscriber not registered ( code: {})", componentID, ret);
}
}

initLock.Unlock();

return ret;
Expand Down Expand Up @@ -1615,7 +1602,6 @@ GravityReturnCode GravityNode::ServiceDirectoryDataProductLookup(std::string dat

// Send request to service directory
GravityReturnCode ret = sendRequestToServiceDirectory(request, response);

if (ret == GravityReturnCodes::SUCCESS)
{
ComponentDataLookupResponsePB pb;
Expand Down Expand Up @@ -1691,7 +1677,8 @@ GravityReturnCode GravityNode::subscribeInternal(string dataProductID, const Gra

GravityReturnCode ret;
ret = ServiceDirectoryDataProductLookup(dataProductID, publisherInfoPBs, domain);
if(ret != GravityReturnCodes::SUCCESS) {
if(ret != GravityReturnCodes::SUCCESS)
{
return ret;
}

Expand Down Expand Up @@ -2518,6 +2505,13 @@ GravityReturnCode GravityNode::unregisterHeartbeatListener(string componentID, s
return GravityReturnCodes::SUCCESS;
}

GravityReturnCode GravityNode::registerSpdlogDynamicConfiguration()
{
// Set up the subscriber for any reconfiguration messages
spdLogConfigSub.init(componentID);
return this->subscribe(gravity::constants::SPD_LOG_CONFIG_DPID, spdLogConfigSub);
}

GravityReturnCode GravityNode::registerRelay(string dataProductID, const GravitySubscriber& subscriber, bool localOnly, GravityTransportType transportType)
{
return registerRelay(dataProductID, subscriber, localOnly, transportType, false);
Expand Down
10 changes: 10 additions & 0 deletions src/api/cpp/GravityNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "GravitySemaphore.h"
#include "GravityServiceProvider.h"
#include "GravitySubscriptionMonitor.h"
#include "GravitySpdLogConfigSubscriber.h"
#include "Utility.h"
#include "CommUtil.h"
//#include "PublishSink.h"
Expand Down Expand Up @@ -211,6 +212,8 @@ class GravityNode

bool defaultCacheLastSentDataprodut;
bool defaultReceiveLastSentDataproduct;

SpdLogConfigSubscriber spdLogConfigSub;

std::thread subscriptionManagerThread;

Expand Down Expand Up @@ -500,6 +503,13 @@ class GravityNode
*/
GRAVITY_API GravityReturnCode unregisterHeartbeatListener(std::string componentID, std::string domain = "");


/**
* Registers a subscriber to receive messages about dynamic spdlog changes
* \return success flag
*/
GRAVITY_API GravityReturnCode registerSpdlogDynamicConfiguration();

/**
* Register a Relay that will act as a pass-through for the given dataProductID. It will be a publisher and subscriber
* for the given dataProductID, but other components will only subscribe to this data if they are on the same host (localOnly == true), or
Expand Down
50 changes: 50 additions & 0 deletions src/api/cpp/GravitySpdLogConfigSubscriber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <memory>
#include <iostream>
#include <stdio.h>
#include "GravitySpdLogConfigSubscriber.h"
#include "spdlog/spdlog.h"
#include "protobuf/GravitySpdLogConfigPB.pb.h"


namespace gravity {
SpdLogConfigSubscriber::SpdLogConfigSubscriber(){}

void SpdLogConfigSubscriber::init(std::string compID)
{
componentID = compID;
}

void SpdLogConfigSubscriber::subscriptionFilled(const std::vector< std::shared_ptr<GravityDataProduct> >& dataProducts)
{
for(std::vector< std::shared_ptr<GravityDataProduct> >::const_iterator i = dataProducts.begin(); i != dataProducts.end(); i++)
{
//Get the protobuf object from the message
GravitySpdLogConfigPB spdLogConfigPB;
(*i)->populateMessage(spdLogConfigPB);
// Reconfigure the loggers based on this
reconfigSpdLoggers(spdLogConfigPB);
}
}

// Determines if correct ID and reconfigures accordingly
void SpdLogConfigSubscriber::reconfigSpdLoggers(GravitySpdLogConfigPB spdLogConfigPB)
{
// Check if it is one of the specfied components, return if not
if (spdLogConfigPB.has_component_id() && spdLogConfigPB.component_id() != componentID)
{
return;
}
if (spdLogConfigPB.logger_id() == GravitySpdLogConfigPB_LoggerType_GravityConsoleLogger || spdLogConfigPB.logger_id() == GravitySpdLogConfigPB_LoggerType_GravityFileLogger)
{
auto log = spdlog::get("GravityLogger");
log->sinks()[spdLogConfigPB.logger_id()]-> set_level((spdlog::level::level_enum)(spdLogConfigPB.logger_level()));

}
else
{
auto log = spdlog::get("GravityApplicationLogger");
log->sinks()[spdLogConfigPB.logger_id() - 2]-> set_level((spdlog::level::level_enum)(spdLogConfigPB.logger_level()));

}
}
}
19 changes: 19 additions & 0 deletions src/api/cpp/GravitySpdLogConfigSubscriber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include "Utility.h"
#include "GravitySubscriber.h"
#include "protobuf/GravitySpdLogConfigPB.pb.h"

namespace gravity {
//Declare class for receiving published messages about the log.
class SpdLogConfigSubscriber: public GravitySubscriber
{
private:
std::string componentID;
void reconfigSpdLoggers(GravitySpdLogConfigPB spdLogConfigPB);
public:
SpdLogConfigSubscriber();
void init(std::string compID);
void subscriptionFilled(const std::vector< std::shared_ptr<GravityDataProduct> >& dataProducts);

};
}
49 changes: 49 additions & 0 deletions src/api/protobufs/GravitySpdLogConfigPB.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/** (C) Copyright 2013, Applied Physical Sciences Corp., A General Dynamics Company
**
** Gravity is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this program;
** If not, see <http://www.gnu.org/licenses/>.
**
*/

syntax = "proto2";
option optimize_for = SPEED;
option java_outer_classname = "ComponentDataLookupResponseContainer";
option java_package = "com.aphysci.gravity.protobuf";

package gravity;
message GravitySpdLogConfigPB
{
optional string component_id = 1;
enum LoggerLevel
{
trace = 0;
debug = 1;
info = 2;
warn = 3;
error = 4;
critical = 5;
off = 6;
}
optional LoggerLevel logger_level = 2;
enum LoggerType
{
GravityConsoleLogger = 0;
GravityFileLogger = 1;
ApplicationConsoleLogger = 2;
ApplicationFileLogger = 3;
ApplicationNetworkLogger = 4;

}
optional LoggerType logger_id = 3;
}
16 changes: 16 additions & 0 deletions test/examples/15-SpdlogDynamicConfiguration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.17)
include(GravitySupport)
project(SpdlogDynamicConfiguration)

find_package(PThreadsWin32 REQUIRED)
gravity_find_protobuf(ON)
gravity_find_zeromq(ON)
gravity_find_spdlog(ON)
find_package(GravityKeyValueParser REQUIRED)
find_package(Gravity REQUIRED)

set(CMAKE_DEBUG_POSTFIX _d)
add_executable(SpdlogDynamicConfiguration SpdlogDynamicConfiguration.cpp)
set_target_properties(SpdlogDynamicConfiguration PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
target_link_libraries(SpdlogDynamicConfiguration gravity)
install(TARGETS SpdlogDynamicConfiguration DESTINATION bin)
11 changes: 11 additions & 0 deletions test/examples/15-SpdlogDynamicConfiguration/Gravity.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[general]
NoConfigServer=true
Domain=GravityTest
ServiceDirectoryBroadcastTimeout=15
GravityFileLogLevel=off
GravityConsoleLogLevel=off
AppFileLogLevel=off
AppConsoleLogLevel=off
AppNetworkLogLevel=off
[ServiceDirectory]
BroadcastEnabled=true
Loading