Skip to content

Commit

Permalink
Stop using LoggingService
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Sep 13, 2024
1 parent 56efd92 commit f2dc0d5
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 85 deletions.
1 change: 0 additions & 1 deletion docs/doxygen/doxygen_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ This website provides documentation for JANA2 C++ API automatically generated by

## Internal services

* [JLoggingService](class_j_logging_service.html): Furnish the user with a logger already configured for that particular component
* [JParameterManager](class_j_parameter_manager.html): Furnish the user with parameters extracted from command line flags and configuration files

## Parallelism engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

void dummy_publisher_loop(JApplication* app) {

auto params = app->GetJParameterManager();

JBenchUtils bench_utils = JBenchUtils();
size_t delay_ms = 1;
auto logger = app->GetService<JLoggingService>()->get_logger("dummy_publisher_loop");
auto logger = params->GetLogger("dummy_publisher_loop");
bench_utils.set_seed(7, "InteractiveStreamingExample.cc:dummy_publisher_loop");

std::this_thread::yield();
Expand Down Expand Up @@ -71,7 +73,7 @@ extern "C" {
void InitPlugin(JApplication* app) {

InitJANAPlugin(app);
auto logger = app->GetService<JLoggingService>()->get_logger("streamDet");
auto logger = app->GetJParameterManager()->GetLogger("streamDet");

app->SetParameterValue("nthreads", 4);
app->SetParameterValue("jana:extended_report", true);
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/JANA/CLI/JBenchmarker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "JBenchmarker.h"

#include <JANA/Utils/JCpuInfo.h>
#include <JANA/Services/JLoggingService.h>

#include <fstream>
#include <cmath>
Expand All @@ -15,10 +14,11 @@
JBenchmarker::JBenchmarker(JApplication* app) : m_app(app) {

m_max_threads = JCpuInfo::GetNumCpus();
m_logger = app->GetService<JLoggingService>()->get_logger("JBenchmarker");

auto params = app->GetJParameterManager();

m_logger = params->GetLogger("JBenchmarker");

params->SetParameter("jana:nevents", 0);
// Prevent users' choice of nevents from interfering with everything

Expand Down
3 changes: 1 addition & 2 deletions src/libraries/JANA/Calibrations/JCalibrationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <JANA/Calibrations/JCalibrationGenerator.h>

#include <JANA/Services/JServiceLocator.h>
#include <JANA/Services/JLoggingService.h>

#include <algorithm>
#include "JLargeCalibration.h"
Expand All @@ -30,9 +29,9 @@ class JCalibrationManager : public JService {
void acquire_services(JServiceLocator *service_locator) {

// Configure our logger
m_logger = service_locator->get<JLoggingService>()->get_logger("JCalibrationManager");

m_params = service_locator->get<JParameterManager>();
m_logger = m_params->GetLogger("JCalibrationManager");

// Url and context may be passed in either as environment variables
// or configuration parameters. Default values are used if neither is available.
Expand Down
7 changes: 2 additions & 5 deletions src/libraries/JANA/Components/JOmniFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
* which might be changed by user parameters.
*/

#include "JANA/Services/JParameterManager.h"
#include <JANA/JEvent.h>
#include <JANA/JMultifactory.h>
#include <JANA/JVersion.h>
#include <JANA/Components/JHasInputs.h>

#include <JANA/JLogger.h>
#include <JANA/Services/JLoggingService.h>

#include <string>
#include <vector>

Expand Down Expand Up @@ -271,8 +269,7 @@ class JOmniFactory : public JMultifactory, public jana::components::JHasInputs {
}

// Obtain logger
//m_logger = m_app->GetService<Log_service>()->logger(m_prefix);
m_logger = m_app->GetService<JLoggingService>()->get_logger(m_prefix);
m_logger = m_app->GetService<JParameterManager>()->GetLogger(m_prefix);

// Configure logger. Priority = [JParameterManager, system log level]
// std::string default_log_level = eicrecon::LogLevelToString(m_logger->level());
Expand Down
12 changes: 6 additions & 6 deletions src/libraries/JANA/Engine/JArrowProcessingController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2020, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.

#include "JANA/Services/JParameterManager.h"
#include <JANA/Engine/JArrowProcessingController.h>
#include <JANA/Engine/JPerfSummary.h>
#include <JANA/Topology/JTopologyBuilder.h>
Expand All @@ -14,15 +15,14 @@ using millisecs = std::chrono::duration<double, std::milli>;
using secs = std::chrono::duration<double>;

void JArrowProcessingController::acquire_services(JServiceLocator * sl) {
auto ls = sl->get<JLoggingService>();
m_logger = ls->get_logger("JArrowProcessingController");
m_worker_logger = ls->get_logger("JWorker");
m_scheduler_logger = ls->get_logger("JScheduler");

auto params = sl->get<JParameterManager>();
m_logger = params->GetLogger("JArrowProcessingController");
m_worker_logger = params->GetLogger("JWorker");
m_scheduler_logger = params->GetLogger("JScheduler");

m_topology = sl->get<JTopologyBuilder>();

// Obtain timeouts from parameter manager
auto params = sl->get<JParameterManager>();
params->SetDefaultParameter("jana:timeout", m_timeout_s, "Max time (in seconds) JANA will wait for a thread to update its heartbeat before hard-exiting. 0 to disable timeout completely.");
params->SetDefaultParameter("jana:warmup_timeout", m_warmup_timeout_s, "Max time (in seconds) JANA will wait for 'initial' events to complete before hard-exiting.");
// Originally "THREAD_TIMEOUT" and "THREAD_TIMEOUT_FIRST_EVENT"
Expand Down
1 change: 0 additions & 1 deletion src/libraries/JANA/Engine/JScheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "JScheduler.h"
#include <JANA/Engine/JScheduler.h>
#include <JANA/Topology/JTopologyBuilder.h>
#include <JANA/Services/JLoggingService.h>


JScheduler::JScheduler(std::shared_ptr<JTopologyBuilder> topology)
Expand Down
1 change: 0 additions & 1 deletion src/libraries/JANA/Engine/JWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#pragma once
#include <thread>
#include <JANA/Services/JLoggingService.h>
#include <JANA/Engine/JScheduler.h>
#include <JANA/Engine/JWorkerMetrics.h>
#include <JANA/Engine/JPerfSummary.h>
Expand Down
5 changes: 1 addition & 4 deletions src/libraries/JANA/JApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <JANA/Services/JComponentManager.h>
#include <JANA/Services/JWiringService.h>
#include <JANA/Topology/JTopologyBuilder.h>
#include <JANA/Services/JLoggingService.h>
#include <JANA/Services/JGlobalRootLock.h>
#include <JANA/Engine/JArrowProcessingController.h>
#include <JANA/Utils/JApplicationInspector.h>
Expand Down Expand Up @@ -47,7 +46,6 @@ JApplication::JApplication(JParameterManager* params) {
ProvideService(m_params);
ProvideService(m_component_manager);
ProvideService(m_plugin_loader);
ProvideService(std::make_shared<JLoggingService>());
ProvideService(std::make_shared<JGlobalRootLock>());
ProvideService(std::make_shared<JTopologyBuilder>());

Expand Down Expand Up @@ -121,13 +119,12 @@ void JApplication::Initialize() {
m_services_available = true;

// We trigger initialization
auto logging_service = m_service_locator->get<JLoggingService>();
auto component_manager = m_service_locator->get<JComponentManager>();
auto plugin_loader = m_service_locator->get<JPluginLoader>();
auto topology_builder = m_service_locator->get<JTopologyBuilder>();

// Set logger on JApplication itself
m_logger = logging_service->get_logger("JApplication");
m_logger = m_params->GetLogger("JApplication");
m_logger.show_classname = false;

// Set up wiring
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/JANA/JFactoryGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class JFactoryGeneratorT : public JFactoryGenerator {
factory->SetTypeName(JTypeInfo::demangle<T>());
factory->SetPluginName(GetPluginName());
factory->SetApplication(GetApplication());
factory->SetLogger(GetApplication()->template GetService<JLoggingService>()->get_logger(factory->GetPrefix()));
factory->SetLogger(GetApplication()->GetJParameterManager()->GetLogger(factory->GetPrefix()));
factory_set->Add(factory);
}
};
Expand Down
1 change: 1 addition & 0 deletions src/libraries/JANA/JLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sstream>
#include <JANA/Compatibility/JStreamLog.h>


struct JLogger {
enum class Level { TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF };
Level level;
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/JANA/Services/JComponentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ void JComponentManager::configure_components() {
void JComponentManager::preinitialize_components() {
for (auto* src : m_evt_srces) {
src->SetApplication(GetApplication());
src->SetLogger(m_logging->get_logger(src->GetLoggerName()));
src->SetLogger(m_params->GetLogger(src->GetLoggerName()));
}
for (auto* proc : m_evt_procs) {
proc->SetApplication(GetApplication());
proc->SetLogger(m_logging->get_logger(proc->GetLoggerName()));
proc->SetLogger(m_params->GetLogger(proc->GetLoggerName()));
}
for (auto* fac_gen : m_fac_gens) {
fac_gen->SetApplication(GetApplication());
Expand All @@ -85,7 +85,7 @@ void JComponentManager::preinitialize_components() {
}
for (auto* unfolder : m_unfolders) {
unfolder->SetApplication(GetApplication());
unfolder->SetLogger(m_logging->get_logger(unfolder->GetLoggerName()));
unfolder->SetLogger(m_params->GetLogger(unfolder->GetLoggerName()));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/libraries/JANA/Services/JComponentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class JComponentManager : public JService {
private:

Service<JParameterManager> m_params {this};
Service<JLoggingService> m_logging {this};

std::string m_current_plugin_name;
std::vector<std::string> m_src_names;
Expand Down
30 changes: 0 additions & 30 deletions src/libraries/JANA/Services/JLoggingService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,8 @@

#include <JANA/Services/JLoggingService.h>

#include <iostream>


template <>
inline void JParameterManager::Parse(const std::string& in, JLogger::Level& out) {
std::string token(in);
std::transform(in.begin(), in.end(), token.begin(), ::tolower);
if (std::strcmp(token.c_str(), "trace") == 0) {
out = JLogger::Level::TRACE;
}
else if (std::strcmp(token.c_str(), "debug") == 0) {
out = JLogger::Level::DEBUG;
}
else if (std::strcmp(token.c_str(), "info") == 0) {
out = JLogger::Level::INFO;
}
else if (std::strcmp(token.c_str(), "warn") == 0) {
out = JLogger::Level::WARN;
}
else if (std::strcmp(token.c_str(), "error") == 0) {
out = JLogger::Level::ERROR;
}
else if (std::strcmp(token.c_str(), "fatal") == 0) {
out = JLogger::Level::FATAL;
}
else if (std::strcmp(token.c_str(), "off") == 0) {
out = JLogger::Level::OFF;
}
else {
throw JException("Unable to parse log level: '%s'. Options are: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF", in.c_str());
}
}

void JLoggingService::acquire_services(JServiceLocator* serviceLocator) {

Expand Down
6 changes: 2 additions & 4 deletions src/libraries/JANA/Services/JParameterManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ using namespace std;

/// @brief Default constructor
JParameterManager::JParameterManager() {
// Set the logger temporarily, until the JLoggingService figures out the correct log level
m_logger.show_classname = true;
m_logger.className = "JParameterManager";
m_logger.level = JLogger::Level::INFO;
// Set the logger temporarily
m_logger = GetLogger("JParameterManager");
}

/// @brief Copy constructor
Expand Down
31 changes: 31 additions & 0 deletions src/libraries/JANA/Services/JParameterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,37 @@ inline void JParameterManager::Parse(const std::string& value, std::vector<T> &v
}
}

/// @brief Specialization for JLogger::Level enum
template <>
inline void JParameterManager::Parse(const std::string& in, JLogger::Level& out) {
std::string token(in);
std::transform(in.begin(), in.end(), token.begin(), ::tolower);
if (std::strcmp(token.c_str(), "trace") == 0) {
out = JLogger::Level::TRACE;
}
else if (std::strcmp(token.c_str(), "debug") == 0) {
out = JLogger::Level::DEBUG;
}
else if (std::strcmp(token.c_str(), "info") == 0) {
out = JLogger::Level::INFO;
}
else if (std::strcmp(token.c_str(), "warn") == 0) {
out = JLogger::Level::WARN;
}
else if (std::strcmp(token.c_str(), "error") == 0) {
out = JLogger::Level::ERROR;
}
else if (std::strcmp(token.c_str(), "fatal") == 0) {
out = JLogger::Level::FATAL;
}
else if (std::strcmp(token.c_str(), "off") == 0) {
out = JLogger::Level::OFF;
}
else {
throw JException("Unable to parse log level: '%s'. Options are: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF", in.c_str());
}
}

#if __cplusplus >= 201703L
/// @brief Basic implementation of Stringify for C++17 and newer. Provides a helpful error message when attempting to stringify a type that doesn't come with a stream operator.
template <typename T>
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/JANA/Topology/JMailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// Subject to the terms in the LICENSE file found in the top-level directory.

#pragma once
#include <queue>
#include <mutex>
#include <JANA/Utils/JCpuInfo.h>
#include <JANA/Services/JLoggingService.h>
#include <JANA/JEvent.h>

#include <mutex>
#include <deque>

/// JMailbox is a threadsafe event queue designed for communication between Arrows.
/// It is different from the standard data structure in the following ways:
/// - pushes and pops return a Status enum, handling the problem of .size() always being stale
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/JANA/Topology/JTopologyBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ void JTopologyBuilder::acquire_services(JServiceLocator *sl) {
"Constrain memory locality. 0=No constraint. 1=Events stay on the same socket. 2=Events stay on the same NUMA domain. 3=Events stay on same core. 4=Events stay on same cpu/hyperthread.")
->SetIsAdvanced(true);

m_arrow_logger = m_logging->get_logger("JArrow");
m_queue_logger = m_logging->get_logger("JQueue");
m_arrow_logger = m_params->GetLogger("JArrow");
m_queue_logger = m_params->GetLogger("JQueue");
};


Expand Down
3 changes: 0 additions & 3 deletions src/libraries/JANA/Topology/JTopologyBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

#include <JANA/Services/JParameterManager.h>
#include <JANA/Services/JComponentManager.h>
#include <JANA/Services/JLoggingService.h>


class JParameterManager;
class JLoggingService;
class JComponentManager;
class JArrow;
class JQueue;
Expand All @@ -29,7 +27,6 @@ class JTopologyBuilder : public JService {
public:
// Services
Service<JParameterManager> m_params {this};
Service<JLoggingService> m_logging {this};
std::shared_ptr<JComponentManager> m_components;

// The topology itself
Expand Down
1 change: 0 additions & 1 deletion src/libraries/JANA/Utils/JCallGraphRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <sys/time.h>
#include <chrono>

#include <JANA/Services/JLoggingService.h>

// Note on tracking how/where Insert() objects came from.
//
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/JANA/Utils/JStringification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void JStringification::GetObjectSummaries(std::map<std::string, JObjectSummary>
}
#endif
}else{
_DBG_<<"No factory found! object_name=" << object_name << std::endl;
LOG <<"No factory found! object_name=" << object_name << LOG_END;
}
}

Expand Down Expand Up @@ -131,4 +131,4 @@ std::string JStringification::GetRootObjectMemberAsString(const TObject *tobj, c
else if( type == "string" ) return GetAddrAsString<std::string>(addr);
return "unknown";
}
#endif // JANA2_HAVE_ROOT
#endif // JANA2_HAVE_ROOT
Loading

0 comments on commit f2dc0d5

Please sign in to comment.