From 56efd9276632d940dbd123ddd4f400e6d4a97442 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Thu, 12 Sep 2024 23:22:23 -0400 Subject: [PATCH 01/13] Make ParameterManager responsible for loggers --- src/libraries/JANA/Services/JParameterManager.cc | 16 ++++++++++++++++ src/libraries/JANA/Services/JParameterManager.h | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libraries/JANA/Services/JParameterManager.cc b/src/libraries/JANA/Services/JParameterManager.cc index f61759693..805ae9490 100644 --- a/src/libraries/JANA/Services/JParameterManager.cc +++ b/src/libraries/JANA/Services/JParameterManager.cc @@ -3,7 +3,9 @@ // Subject to the terms in the LICENSE file found in the top-level directory. #include "JParameterManager.h" +#include "JANA/JLogger.h" +#include #include #include #include @@ -409,3 +411,17 @@ void JParameterManager::FilterParameters(std::map &par parms[key] = value; } } + +JLogger JParameterManager::GetLogger(const std::string& component_prefix) { + + std::ostringstream os; + os << component_prefix << ":loglevel"; + + auto global_log_level = RegisterParameter("jana:global_log_level", JLogger::Level::INFO, "Global log level"); + auto local_log_level = RegisterParameter(os.str(), global_log_level, "Component log level"); + + JLogger logger; + logger.className = component_prefix; + logger.level = local_log_level; + return logger; +} diff --git a/src/libraries/JANA/Services/JParameterManager.h b/src/libraries/JANA/Services/JParameterManager.h index d4ea981be..95b2593bb 100644 --- a/src/libraries/JANA/Services/JParameterManager.h +++ b/src/libraries/JANA/Services/JParameterManager.h @@ -141,6 +141,8 @@ class JParameterManager : public JService { static std::string ToLower(const std::string& name); + JLogger GetLogger(const std::string& prefix); + private: std::map m_parameters; @@ -148,8 +150,6 @@ class JParameterManager : public JService { int m_strictness = 1; int m_verbosity = 1; - JLogger m_logger; - std::mutex m_mutex; }; From f2dc0d5bb884d0007471dc515f5e7717e1081df7 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 13 Sep 2024 11:06:58 -0400 Subject: [PATCH 02/13] Stop using LoggingService --- docs/doxygen/doxygen_index.md | 1 - .../InteractiveStreamingExample.cc | 6 ++-- src/libraries/JANA/CLI/JBenchmarker.cc | 4 +-- .../JANA/Calibrations/JCalibrationManager.h | 3 +- src/libraries/JANA/Components/JOmniFactory.h | 7 ++--- .../JANA/Engine/JArrowProcessingController.cc | 12 +++---- src/libraries/JANA/Engine/JScheduler.cc | 1 - src/libraries/JANA/Engine/JWorker.h | 1 - src/libraries/JANA/JApplication.cc | 5 +-- src/libraries/JANA/JFactoryGenerator.h | 2 +- src/libraries/JANA/JLogger.h | 1 + .../JANA/Services/JComponentManager.cc | 6 ++-- .../JANA/Services/JComponentManager.h | 1 - .../JANA/Services/JLoggingService.cc | 30 ------------------ .../JANA/Services/JParameterManager.cc | 6 ++-- .../JANA/Services/JParameterManager.h | 31 +++++++++++++++++++ src/libraries/JANA/Topology/JMailbox.h | 6 ++-- .../JANA/Topology/JTopologyBuilder.cc | 4 +-- .../JANA/Topology/JTopologyBuilder.h | 3 -- src/libraries/JANA/Utils/JCallGraphRecorder.h | 1 - src/libraries/JANA/Utils/JStringification.cc | 4 +-- src/programs/perf_tests/PerfTests.cc | 6 ++-- .../Topology/TestTopologyComponents.h | 11 ++----- 23 files changed, 67 insertions(+), 85 deletions(-) diff --git a/docs/doxygen/doxygen_index.md b/docs/doxygen/doxygen_index.md index 8760e35cc..23b463b80 100644 --- a/docs/doxygen/doxygen_index.md +++ b/docs/doxygen/doxygen_index.md @@ -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 diff --git a/src/examples/InteractiveStreamingExample/InteractiveStreamingExample.cc b/src/examples/InteractiveStreamingExample/InteractiveStreamingExample.cc index d9235524b..9ed2be6ed 100644 --- a/src/examples/InteractiveStreamingExample/InteractiveStreamingExample.cc +++ b/src/examples/InteractiveStreamingExample/InteractiveStreamingExample.cc @@ -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()->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(); @@ -71,7 +73,7 @@ extern "C" { void InitPlugin(JApplication* app) { InitJANAPlugin(app); - auto logger = app->GetService()->get_logger("streamDet"); + auto logger = app->GetJParameterManager()->GetLogger("streamDet"); app->SetParameterValue("nthreads", 4); app->SetParameterValue("jana:extended_report", true); diff --git a/src/libraries/JANA/CLI/JBenchmarker.cc b/src/libraries/JANA/CLI/JBenchmarker.cc index 6df57d73f..34a2cf2c1 100644 --- a/src/libraries/JANA/CLI/JBenchmarker.cc +++ b/src/libraries/JANA/CLI/JBenchmarker.cc @@ -5,7 +5,6 @@ #include "JBenchmarker.h" #include -#include #include #include @@ -15,10 +14,11 @@ JBenchmarker::JBenchmarker(JApplication* app) : m_app(app) { m_max_threads = JCpuInfo::GetNumCpus(); - m_logger = app->GetService()->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 diff --git a/src/libraries/JANA/Calibrations/JCalibrationManager.h b/src/libraries/JANA/Calibrations/JCalibrationManager.h index b5fe0e144..500494f57 100644 --- a/src/libraries/JANA/Calibrations/JCalibrationManager.h +++ b/src/libraries/JANA/Calibrations/JCalibrationManager.h @@ -7,7 +7,6 @@ #include #include -#include #include #include "JLargeCalibration.h" @@ -30,9 +29,9 @@ class JCalibrationManager : public JService { void acquire_services(JServiceLocator *service_locator) { // Configure our logger - m_logger = service_locator->get()->get_logger("JCalibrationManager"); m_params = service_locator->get(); + 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. diff --git a/src/libraries/JANA/Components/JOmniFactory.h b/src/libraries/JANA/Components/JOmniFactory.h index 81da2ef6f..a00629b5c 100644 --- a/src/libraries/JANA/Components/JOmniFactory.h +++ b/src/libraries/JANA/Components/JOmniFactory.h @@ -10,14 +10,12 @@ * which might be changed by user parameters. */ +#include "JANA/Services/JParameterManager.h" #include #include #include #include -#include -#include - #include #include @@ -271,8 +269,7 @@ class JOmniFactory : public JMultifactory, public jana::components::JHasInputs { } // Obtain logger - //m_logger = m_app->GetService()->logger(m_prefix); - m_logger = m_app->GetService()->get_logger(m_prefix); + m_logger = m_app->GetService()->GetLogger(m_prefix); // Configure logger. Priority = [JParameterManager, system log level] // std::string default_log_level = eicrecon::LogLevelToString(m_logger->level()); diff --git a/src/libraries/JANA/Engine/JArrowProcessingController.cc b/src/libraries/JANA/Engine/JArrowProcessingController.cc index 2d71611b5..f056aba17 100644 --- a/src/libraries/JANA/Engine/JArrowProcessingController.cc +++ b/src/libraries/JANA/Engine/JArrowProcessingController.cc @@ -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 #include #include @@ -14,15 +15,14 @@ using millisecs = std::chrono::duration; using secs = std::chrono::duration; void JArrowProcessingController::acquire_services(JServiceLocator * sl) { - auto ls = sl->get(); - m_logger = ls->get_logger("JArrowProcessingController"); - m_worker_logger = ls->get_logger("JWorker"); - m_scheduler_logger = ls->get_logger("JScheduler"); + + auto params = sl->get(); + m_logger = params->GetLogger("JArrowProcessingController"); + m_worker_logger = params->GetLogger("JWorker"); + m_scheduler_logger = params->GetLogger("JScheduler"); m_topology = sl->get(); - // Obtain timeouts from parameter manager - auto params = sl->get(); 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" diff --git a/src/libraries/JANA/Engine/JScheduler.cc b/src/libraries/JANA/Engine/JScheduler.cc index 4c0786df2..ea1a659b1 100644 --- a/src/libraries/JANA/Engine/JScheduler.cc +++ b/src/libraries/JANA/Engine/JScheduler.cc @@ -7,7 +7,6 @@ #include "JScheduler.h" #include #include -#include JScheduler::JScheduler(std::shared_ptr topology) diff --git a/src/libraries/JANA/Engine/JWorker.h b/src/libraries/JANA/Engine/JWorker.h index fae64290c..3adf6b1d0 100644 --- a/src/libraries/JANA/Engine/JWorker.h +++ b/src/libraries/JANA/Engine/JWorker.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include #include #include diff --git a/src/libraries/JANA/JApplication.cc b/src/libraries/JANA/JApplication.cc index dbcd2b5bb..fa84def8a 100644 --- a/src/libraries/JANA/JApplication.cc +++ b/src/libraries/JANA/JApplication.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -47,7 +46,6 @@ JApplication::JApplication(JParameterManager* params) { ProvideService(m_params); ProvideService(m_component_manager); ProvideService(m_plugin_loader); - ProvideService(std::make_shared()); ProvideService(std::make_shared()); ProvideService(std::make_shared()); @@ -121,13 +119,12 @@ void JApplication::Initialize() { m_services_available = true; // We trigger initialization - auto logging_service = m_service_locator->get(); auto component_manager = m_service_locator->get(); auto plugin_loader = m_service_locator->get(); auto topology_builder = m_service_locator->get(); // 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 diff --git a/src/libraries/JANA/JFactoryGenerator.h b/src/libraries/JANA/JFactoryGenerator.h index 8ac3f0ab6..e774801ee 100644 --- a/src/libraries/JANA/JFactoryGenerator.h +++ b/src/libraries/JANA/JFactoryGenerator.h @@ -60,7 +60,7 @@ class JFactoryGeneratorT : public JFactoryGenerator { factory->SetTypeName(JTypeInfo::demangle()); factory->SetPluginName(GetPluginName()); factory->SetApplication(GetApplication()); - factory->SetLogger(GetApplication()->template GetService()->get_logger(factory->GetPrefix())); + factory->SetLogger(GetApplication()->GetJParameterManager()->GetLogger(factory->GetPrefix())); factory_set->Add(factory); } }; diff --git a/src/libraries/JANA/JLogger.h b/src/libraries/JANA/JLogger.h index 189f5941e..b72f6bcae 100644 --- a/src/libraries/JANA/JLogger.h +++ b/src/libraries/JANA/JLogger.h @@ -8,6 +8,7 @@ #include #include + struct JLogger { enum class Level { TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF }; Level level; diff --git a/src/libraries/JANA/Services/JComponentManager.cc b/src/libraries/JANA/Services/JComponentManager.cc index fb050eec7..a15dcaa8f 100644 --- a/src/libraries/JANA/Services/JComponentManager.cc +++ b/src/libraries/JANA/Services/JComponentManager.cc @@ -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()); @@ -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())); } } diff --git a/src/libraries/JANA/Services/JComponentManager.h b/src/libraries/JANA/Services/JComponentManager.h index 691976999..3f6a501e7 100644 --- a/src/libraries/JANA/Services/JComponentManager.h +++ b/src/libraries/JANA/Services/JComponentManager.h @@ -56,7 +56,6 @@ class JComponentManager : public JService { private: Service m_params {this}; - Service m_logging {this}; std::string m_current_plugin_name; std::vector m_src_names; diff --git a/src/libraries/JANA/Services/JLoggingService.cc b/src/libraries/JANA/Services/JLoggingService.cc index 69645e792..dd8382e38 100644 --- a/src/libraries/JANA/Services/JLoggingService.cc +++ b/src/libraries/JANA/Services/JLoggingService.cc @@ -5,38 +5,8 @@ #include -#include -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) { diff --git a/src/libraries/JANA/Services/JParameterManager.cc b/src/libraries/JANA/Services/JParameterManager.cc index 805ae9490..530b823f8 100644 --- a/src/libraries/JANA/Services/JParameterManager.cc +++ b/src/libraries/JANA/Services/JParameterManager.cc @@ -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 diff --git a/src/libraries/JANA/Services/JParameterManager.h b/src/libraries/JANA/Services/JParameterManager.h index 95b2593bb..f7ed6ced5 100644 --- a/src/libraries/JANA/Services/JParameterManager.h +++ b/src/libraries/JANA/Services/JParameterManager.h @@ -384,6 +384,37 @@ inline void JParameterManager::Parse(const std::string& value, std::vector &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 diff --git a/src/libraries/JANA/Topology/JMailbox.h b/src/libraries/JANA/Topology/JMailbox.h index ef5256c14..49a5a8384 100644 --- a/src/libraries/JANA/Topology/JMailbox.h +++ b/src/libraries/JANA/Topology/JMailbox.h @@ -3,12 +3,12 @@ // Subject to the terms in the LICENSE file found in the top-level directory. #pragma once -#include -#include #include -#include #include +#include +#include + /// 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 diff --git a/src/libraries/JANA/Topology/JTopologyBuilder.cc b/src/libraries/JANA/Topology/JTopologyBuilder.cc index ff685575a..5c5db07ae 100644 --- a/src/libraries/JANA/Topology/JTopologyBuilder.cc +++ b/src/libraries/JANA/Topology/JTopologyBuilder.cc @@ -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"); }; diff --git a/src/libraries/JANA/Topology/JTopologyBuilder.h b/src/libraries/JANA/Topology/JTopologyBuilder.h index a287d4631..c0ed19058 100644 --- a/src/libraries/JANA/Topology/JTopologyBuilder.h +++ b/src/libraries/JANA/Topology/JTopologyBuilder.h @@ -11,11 +11,9 @@ #include #include -#include class JParameterManager; -class JLoggingService; class JComponentManager; class JArrow; class JQueue; @@ -29,7 +27,6 @@ class JTopologyBuilder : public JService { public: // Services Service m_params {this}; - Service m_logging {this}; std::shared_ptr m_components; // The topology itself diff --git a/src/libraries/JANA/Utils/JCallGraphRecorder.h b/src/libraries/JANA/Utils/JCallGraphRecorder.h index 7fbdccc54..a17e98804 100644 --- a/src/libraries/JANA/Utils/JCallGraphRecorder.h +++ b/src/libraries/JANA/Utils/JCallGraphRecorder.h @@ -10,7 +10,6 @@ #include #include -#include // Note on tracking how/where Insert() objects came from. // diff --git a/src/libraries/JANA/Utils/JStringification.cc b/src/libraries/JANA/Utils/JStringification.cc index 364da2fd3..bf0986ab8 100644 --- a/src/libraries/JANA/Utils/JStringification.cc +++ b/src/libraries/JANA/Utils/JStringification.cc @@ -75,7 +75,7 @@ void JStringification::GetObjectSummaries(std::map } #endif }else{ - _DBG_<<"No factory found! object_name=" << object_name << std::endl; + LOG <<"No factory found! object_name=" << object_name << LOG_END; } } @@ -131,4 +131,4 @@ std::string JStringification::GetRootObjectMemberAsString(const TObject *tobj, c else if( type == "string" ) return GetAddrAsString(addr); return "unknown"; } -#endif // JANA2_HAVE_ROOT \ No newline at end of file +#endif // JANA2_HAVE_ROOT diff --git a/src/programs/perf_tests/PerfTests.cc b/src/programs/perf_tests/PerfTests.cc index 974a57731..771374e4d 100644 --- a/src/programs/perf_tests/PerfTests.cc +++ b/src/programs/perf_tests/PerfTests.cc @@ -36,7 +36,7 @@ int main() { params->SetParameter("benchmark:resultsdir", "perftest_fake_halldrecon"); JApplication app(params); - auto logger = app.GetService()->get_logger("PerfTests"); + auto logger = params->GetLogger("PerfTests"); app.AddPlugin("JTest"); LOG_INFO(logger) << "Running JTest tuned to imitate halld_recon" << LOG_END; @@ -75,7 +75,7 @@ int main() { params->SetParameter("benchmark:resultsdir", "perftest_pure_overhead"); JApplication app(params); - auto logger = app.GetService()->get_logger("PerfTests"); + auto logger = params->GetLogger("PerfTests"); app.AddPlugin("JTest"); LOG_INFO(logger) << "Running JTest with all sleeps and computations turned off" << LOG_END; @@ -92,7 +92,7 @@ int main() { auto params = new JParameterManager; params->SetParameter("log:off", "JApplication,JPluginLoader,JArrowProcessingController,JArrow"); // Log levels get set as soon as JApp gets constructed XD JApplication app(params); - auto logger = app.GetService()->get_logger("PerfTests"); + auto logger = params->GetLogger("PerfTests"); // TODO: Add Podio sources, processors, and factories just like JTest LOG_INFO(logger) << "Running PODIO stress test" << LOG_END; JBenchmarker benchmarker(&app); diff --git a/src/programs/unit_tests/Topology/TestTopologyComponents.h b/src/programs/unit_tests/Topology/TestTopologyComponents.h index e4eaec88c..c0a6f827f 100644 --- a/src/programs/unit_tests/Topology/TestTopologyComponents.h +++ b/src/programs/unit_tests/Topology/TestTopologyComponents.h @@ -4,11 +4,7 @@ #pragma once -#include - -#include #include -#include #include "MapArrow.h" @@ -17,7 +13,6 @@ struct RandIntSource : public JPipelineArrow { size_t emit_limit = 20; // How many to emit size_t emit_count = 0; // How many emitted so far int emit_sum = 0; // Sum of all ints emitted so far - JLogger logger; RandIntSource(std::string name, JPool* pool, JMailbox* output_queue) : JPipelineArrow(name, false, true, false, nullptr, output_queue, pool) {} @@ -32,18 +27,18 @@ struct RandIntSource : public JPipelineArrow { *item = 7; emit_sum += *item; emit_count += 1; - LOG_DEBUG(logger) << "RandIntSource emitted event " << emit_count << " with value " << *item << LOG_END; + LOG_DEBUG(JArrow::m_logger) << "RandIntSource emitted event " << emit_count << " with value " << *item << LOG_END; success = true; status = (emit_count == emit_limit) ? JArrowMetrics::Status::Finished : JArrowMetrics::Status::KeepGoing; // This design lets us declare Finished immediately on the last event, instead of after } void initialize() override { - LOG_INFO(logger) << "RandIntSource.initialize() called!" << LOG_END; + LOG_INFO(JArrow::m_logger) << "RandIntSource.initialize() called!" << LOG_END; }; void finalize() override { - LOG_INFO(logger) << "RandIntSource.finalize() called!" << LOG_END; + LOG_INFO(JArrow::m_logger) << "RandIntSource.finalize() called!" << LOG_END; } }; From 7f0bca8dc0822889dc1180462a169b3e51ac25f9 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 13 Sep 2024 12:30:37 -0400 Subject: [PATCH 03/13] Remove LoggingService We may bring this back in some (heavily modified) form when we figure out issue #250 --- src/libraries/JANA/CMakeLists.txt | 1 - .../JANA/Services/JLoggingService.cc | 88 ------------------- src/libraries/JANA/Services/JLoggingService.h | 48 ---------- 3 files changed, 137 deletions(-) delete mode 100644 src/libraries/JANA/Services/JLoggingService.cc delete mode 100644 src/libraries/JANA/Services/JLoggingService.h diff --git a/src/libraries/JANA/CMakeLists.txt b/src/libraries/JANA/CMakeLists.txt index 1ca7a8800..ffb7ea743 100644 --- a/src/libraries/JANA/CMakeLists.txt +++ b/src/libraries/JANA/CMakeLists.txt @@ -22,7 +22,6 @@ set(JANA2_SOURCES Topology/JTopologyBuilder.cc Services/JComponentManager.cc - Services/JLoggingService.cc Services/JParameterManager.cc Services/JPluginLoader.cc Services/JWiringService.cc diff --git a/src/libraries/JANA/Services/JLoggingService.cc b/src/libraries/JANA/Services/JLoggingService.cc deleted file mode 100644 index dd8382e38..000000000 --- a/src/libraries/JANA/Services/JLoggingService.cc +++ /dev/null @@ -1,88 +0,0 @@ - -// Copyright 2020, Jefferson Science Associates, LLC. -// Subject to the terms in the LICENSE file found in the top-level directory. - - -#include - - - - -void JLoggingService::acquire_services(JServiceLocator* serviceLocator) { - - auto params = serviceLocator->get(); - params->SetDefaultParameter("log:global", m_global_log_level, "Default log level"); - - std::vector groups; - params->SetDefaultParameter("log:off", groups, "Comma-separated list of loggers that should be turned off completely"); - for (auto& s : groups) { - m_local_log_levels[s] = JLogger::Level::OFF; - } - groups.clear(); - params->SetDefaultParameter("log:fatal", groups, "Comma-separated list of loggers that should only print FATAL"); - for (auto& s : groups) { - m_local_log_levels[s] = JLogger::Level::FATAL; - } - groups.clear(); - params->SetDefaultParameter("log:error", groups, "Comma-separated list of loggers that should only print ERROR or higher"); - for (auto& s : groups) { - m_local_log_levels[s] = JLogger::Level::ERROR; - } - groups.clear(); - params->SetDefaultParameter("log:warn", groups, "Comma-separated list of loggers that should only print WARN or higher"); - for (auto& s : groups) { - m_local_log_levels[s] = JLogger::Level::WARN; - } - groups.clear(); - params->SetDefaultParameter("log:info", groups, "Comma-separated list of loggers that should only print INFO or higher"); - for (auto& s : groups) { - m_local_log_levels[s] = JLogger::Level::INFO; - } - groups.clear(); - params->SetDefaultParameter("log:debug", groups, "Comma-separated list of loggers that should only print DEBUG or higher"); - for (auto& s : groups) { - m_local_log_levels[s] = JLogger::Level::DEBUG; - } - groups.clear(); - params->SetDefaultParameter("log:trace", groups, "Comma-separated list of loggers that should print everything"); - for (auto& s : groups) { - m_local_log_levels[s] = JLogger::Level::TRACE; - } - // Set the log level on the parameter manager, resolving the chicken-and-egg problem. - params->SetLogger(get_logger("JParameterManager")); -} - - -void JLoggingService::set_level(JLogger::Level level) { - m_global_log_level = level; -} - - -void JLoggingService::set_level(std::string className, JLogger::Level level) { - m_local_log_levels[className] = level; -} - - -JLogger JLoggingService::get_logger() { - return JLogger(m_global_log_level); -} - - -JLogger JLoggingService::get_logger(std::string className) { - - JLogger logger; - logger.show_classname = true; - logger.className = className; - - auto search = m_local_log_levels.find(className); - if (search != m_local_log_levels.end()) { - logger.level = search->second; - } else { - logger.level = m_global_log_level; - } - return logger; -} - - - - diff --git a/src/libraries/JANA/Services/JLoggingService.h b/src/libraries/JANA/Services/JLoggingService.h deleted file mode 100644 index 692d5b890..000000000 --- a/src/libraries/JANA/Services/JLoggingService.h +++ /dev/null @@ -1,48 +0,0 @@ - -// Copyright 2020, Jefferson Science Associates, LLC. -// Subject to the terms in the LICENSE file found in the top-level directory. - -#pragma once - -#include -#include -#include - - -// Convenience macros for temporary debugging statements. -#ifndef _DBG__ -#define _DBG__ std::cerr<<__FILE__<<":"<<__LINE__< m_local_log_levels; - -public: - - void acquire_services(JServiceLocator* serviceLocator) override; - - void set_level(JLogger::Level level); - - void set_level(std::string className, JLogger::Level level); - - JLogger get_logger(); - - JLogger get_logger(std::string className); - -}; - - - From c1c509c839aeed63ff9b2c961149b11c884ad106 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 13 Sep 2024 12:30:51 -0400 Subject: [PATCH 04/13] Update documentation about how to set log levels --- docs/howto/other-howtos.md | 33 +++++++++---------- docs/jana1to2/parameter-changes.md | 6 ++-- .../JANA/Services/JParameterManager.cc | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/docs/howto/other-howtos.md b/docs/howto/other-howtos.md index 27e39283a..96cd6dce3 100644 --- a/docs/howto/other-howtos.md +++ b/docs/howto/other-howtos.md @@ -68,22 +68,22 @@ The following configuration options are used most commonly: | Name | Type | Description | |:-----|:-----|:------------| -nthreads | int | Size of thread team (Defaults to the number of cores on your machine) -plugins | string | Comma-separated list of plugin filenames. JANA will look for these on the `$JANA_PLUGIN_PATH` -plugins_to_ignore | string | This removes plugins which had been specified in `plugins`. -event_source_type | string | Manually override JANA's decision about which JEventSource to use -jana:nevents | int | Limit the number of events each source may emit -jana:nskip | int | Skip processing the first n events from each event source -jana:extended_report | bool | The amount of status information to show while running -jana:status_fname | string | Named pipe for retrieving status information remotely - - -JANA has its own logger. You can control the verbosity of different components using -the parameters `log:off`, `log:fatal`, `log:error`, `log:warn`, `log:info`, `log:debug`, and `log:trace`. -The following example shows how you would increase the verbosity of JPluginLoader and JComponentManager: -``` -jana -Pplugins=JTest -Plog:debug=JPluginLoader,JComponentManager -``` +| nthreads | int | Size of thread team (Defaults to the number of cores on your machine) | +| plugins | string | Comma-separated list of plugin filenames. JANA will look for these on the `$JANA_PLUGIN_PATH` | +| plugins_to_ignore | string | This removes plugins which had been specified in `plugins`. | +| event_source_type | string | Manually override JANA's decision about which JEventSource to use | +| jana:nevents | int | Limit the number of events each source may emit | +| jana:nskip | int | Skip processing the first n events from each event source | +| jana:extended_report | bool | The amount of status information to show while running | +| jana:status_fname | string | Named pipe for retrieving status information remotely | +| jana:loglevel | string | Set the log level (trace,debug,info,warn,error,fatal,off) for loggers internal to JANA | +| jana:global_loglevel | string | Set the default log level (trace,debug,info,warn,error,fatal,off) for all loggers | + +JANA automatically provides each component with its own logger. You can control the logging verbosity of individual components +just like any other parameter. For instance, if your component prefixes its parameters with `BCAL:tracking`, +you can set its log level to `DEBUG` by setting `BCAL:tracking:loglevel=debug`. You can set the parameter prefix by calling `SetPrefix()`, +and if you need the logger name to differ from the parameter prefix for any reason, you can override it by calling `SetLoggerName()`. + The `JTest` plugin lets you test JANA's performance for different workloads. It simulates a typical reconstruction pipeline with four stages: parsing, disentangling, tracking, and plotting. Parsing and plotting are sequential, whereas disentangling and tracking are parallel. Each stage reads all of the data written during the previous stage. The time spent and bytes written (and random variation thereof) are set using the following parameters: @@ -123,7 +123,6 @@ The following parameters are more advanced, but may come in handy when doing per | Name | Type | Default | Description | |:-----|:-----|:------------|:--------| -jana:engine | int | 0 | Which parallelism engine to use. 0: JArrowProcessingController. 1: JDebugProcessingController. jana:event_pool_size | int | nthreads | The number of events which may be in-flight at once jana:limit_total_events_in_flight | bool | 1 | Whether the number of in-flight events should be limited jana:affinity | int | 0 | Thread pinning strategy. 0: None. 1: Minimize number of memory localities. 2: Minimize number of hyperthreads. diff --git a/docs/jana1to2/parameter-changes.md b/docs/jana1to2/parameter-changes.md index 80d1f6a26..c11083e52 100644 --- a/docs/jana1to2/parameter-changes.md +++ b/docs/jana1to2/parameter-changes.md @@ -10,9 +10,9 @@ The following table compares commonly used JANA parameters between JANA1 and JAN |-----------------------|------------------------|------------------------------|--------------------------------------------------| | **PLUGINS** | `- ` | `-` | `-` | | **EVENTS_TO_KEEP** | `EVENTS_TO_KEEP` | `jana:nevents` | `-` | -| **EVENTS_TO_SKIP** | `EVENTS_TO_SKIP` | `jana:nskips` | `-` | +| **EVENTS_TO_SKIP** | `EVENTS_TO_SKIP` | `jana:nskip` | `-` | | **NTHREADS** | `-` | `-` | `-` | -| **JANA:BATCH_MODE** | `JANA:BATCH_MODE` | `log:global` | `TRACE`, `DEBUG`, `INFO`, `WARN`, `FATAL`, `OFF` | +| **JANA:BATCH_MODE** | `JANA:BATCH_MODE` | `jana:global_loglevel` | `TRACE`, `DEBUG`, `INFO`, `WARN`, `FATAL`, `OFF` | | **JANA_CALIB_CONTEXT**| `JANA_CALIB_CONTEXT` | `jana:calib_context` | `-` | ## Changes in `halld_recon` Parameters @@ -22,4 +22,4 @@ The following table compares commonly used JANA parameters between JANA1 and JAN - **JANA1:** The `-b` option was used for printing event status bits in `hd_dump`. - **JANA2:** The `-b` option is used for benchmarking in JANA2. Thus, `hd_dump` parameter for event status bits (`-b`) has been changed to `-B`. Update your usage accordingly. -For additional assistance or questions, please contact [rasool@jlab.org](mailto:rasool@jlab.org). \ No newline at end of file +For additional assistance or questions, please contact [rasool@jlab.org](mailto:rasool@jlab.org). diff --git a/src/libraries/JANA/Services/JParameterManager.cc b/src/libraries/JANA/Services/JParameterManager.cc index 530b823f8..e5d22e6e5 100644 --- a/src/libraries/JANA/Services/JParameterManager.cc +++ b/src/libraries/JANA/Services/JParameterManager.cc @@ -415,7 +415,7 @@ JLogger JParameterManager::GetLogger(const std::string& component_prefix) { std::ostringstream os; os << component_prefix << ":loglevel"; - auto global_log_level = RegisterParameter("jana:global_log_level", JLogger::Level::INFO, "Global log level"); + auto global_log_level = RegisterParameter("jana:global_loglevel", JLogger::Level::INFO, "Global log level"); auto local_log_level = RegisterParameter(os.str(), global_log_level, "Component log level"); JLogger logger; From 9ae82a6f0b8504b5b73a07c01b5ed1071080a409 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 13 Sep 2024 14:01:40 -0400 Subject: [PATCH 05/13] JService injects JLogger --- src/libraries/JANA/JService.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libraries/JANA/JService.cc b/src/libraries/JANA/JService.cc index 0a66f258c..339ac1b96 100644 --- a/src/libraries/JANA/JService.cc +++ b/src/libraries/JANA/JService.cc @@ -9,14 +9,19 @@ void JService::DoInit(JServiceLocator* sl) { std::lock_guard lock(m_mutex); if (this->m_status != Status::Uninitialized) return; + auto m_logger_classname = (m_prefix.empty()) ? m_type_name : m_prefix; + auto params = m_app->GetJParameterManager(); + m_logger = params->GetLogger(m_logger_classname); + for (auto* parameter : m_parameters) { - parameter->Configure(*(m_app->GetJParameterManager()), m_prefix); + parameter->Configure(*params, m_prefix); } for (auto* service : m_services) { - service->Init(GetApplication()); // TODO: This badly needs to be renamed. Maybe Fetch? + service->Init(GetApplication()); // TODO: Rename Service::Init to Fetch } + CallWithJExceptionWrapper("JService::acquire_services", [&](){ this->acquire_services(sl); }); CallWithJExceptionWrapper("JService::Init", [&](){ this->Init(); }); From 966880a12f5e3421534e72dc24dee93e79e029eb Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 13 Sep 2024 14:09:41 -0400 Subject: [PATCH 06/13] Rename JComponent::Service::Init() to Fetch() This clears up a _very_ confusing misnaming --- src/libraries/JANA/Components/JComponent.h | 2 +- src/libraries/JANA/Components/JComponentFwd.h | 2 +- src/libraries/JANA/Components/JOmniFactory.h | 2 +- src/libraries/JANA/JEventProcessor.h | 2 +- src/libraries/JANA/JEventUnfolder.h | 2 +- src/libraries/JANA/JService.cc | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libraries/JANA/Components/JComponent.h b/src/libraries/JANA/Components/JComponent.h index 371ebaf5a..2e92d3b18 100644 --- a/src/libraries/JANA/Components/JComponent.h +++ b/src/libraries/JANA/Components/JComponent.h @@ -108,7 +108,7 @@ class JComponent::Service : public JComponent::ServiceBase { protected: - void Init(JApplication* app) { + void Fetch(JApplication* app) { m_data = app->GetService(); } }; diff --git a/src/libraries/JANA/Components/JComponentFwd.h b/src/libraries/JANA/Components/JComponentFwd.h index 6dca0272b..eba5c4fdd 100644 --- a/src/libraries/JANA/Components/JComponentFwd.h +++ b/src/libraries/JANA/Components/JComponentFwd.h @@ -119,7 +119,7 @@ struct JComponent { class Parameter; struct ServiceBase { - virtual void Init(JApplication* app) = 0; + virtual void Fetch(JApplication* app) = 0; }; template diff --git a/src/libraries/JANA/Components/JOmniFactory.h b/src/libraries/JANA/Components/JOmniFactory.h index a00629b5c..8f7093c45 100644 --- a/src/libraries/JANA/Components/JOmniFactory.h +++ b/src/libraries/JANA/Components/JOmniFactory.h @@ -282,7 +282,7 @@ class JOmniFactory : public JMultifactory, public jana::components::JHasInputs { parameter->Configure(*(m_app->GetJParameterManager()), m_prefix); } for (auto* service : m_services) { - service->Init(m_app); + service->Fetch(m_app); } static_cast(this)->Configure(); } diff --git a/src/libraries/JANA/JEventProcessor.h b/src/libraries/JANA/JEventProcessor.h index b170e9267..46b0c35a7 100644 --- a/src/libraries/JANA/JEventProcessor.h +++ b/src/libraries/JANA/JEventProcessor.h @@ -38,7 +38,7 @@ class JEventProcessor : public jana::components::JComponent, parameter->Configure(*(m_app->GetJParameterManager()), m_prefix); } for (auto* service : m_services) { - service->Init(m_app); + service->Fetch(m_app); } CallWithJExceptionWrapper("JEventProcessor::Init", [&](){ Init(); }); m_status = Status::Initialized; diff --git a/src/libraries/JANA/JEventUnfolder.h b/src/libraries/JANA/JEventUnfolder.h index f6e8834eb..b57fa8b06 100644 --- a/src/libraries/JANA/JEventUnfolder.h +++ b/src/libraries/JANA/JEventUnfolder.h @@ -67,7 +67,7 @@ class JEventUnfolder : public jana::components::JComponent, parameter->Configure(*(m_app->GetJParameterManager()), m_prefix); } for (auto* service : m_services) { - service->Init(m_app); + service->Fetch(m_app); } if (m_status == Status::Uninitialized) { CallWithJExceptionWrapper("JEventUnfolder::Init", [&](){ diff --git a/src/libraries/JANA/JService.cc b/src/libraries/JANA/JService.cc index 339ac1b96..995d7797c 100644 --- a/src/libraries/JANA/JService.cc +++ b/src/libraries/JANA/JService.cc @@ -18,7 +18,7 @@ void JService::DoInit(JServiceLocator* sl) { } for (auto* service : m_services) { - service->Init(GetApplication()); // TODO: Rename Service::Init to Fetch + service->Fetch(m_app); } From 42e7bb96da9be7bd42f1ba01874907640cca92ea Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 13 Sep 2024 15:49:01 -0400 Subject: [PATCH 07/13] Break JParameterManager's dep on itself --- src/libraries/JANA/Services/JParameterManager.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libraries/JANA/Services/JParameterManager.cc b/src/libraries/JANA/Services/JParameterManager.cc index e5d22e6e5..c85d3baf9 100644 --- a/src/libraries/JANA/Services/JParameterManager.cc +++ b/src/libraries/JANA/Services/JParameterManager.cc @@ -19,6 +19,10 @@ using namespace std; JParameterManager::JParameterManager() { // Set the logger temporarily m_logger = GetLogger("JParameterManager"); + + // Short-circuit JParameterManager::DoInit() + // Otherwise there is a cycle when initializing JParameterManager and JLoggingService + this->m_status = Status::Initialized; } /// @brief Copy constructor From 4eaf52dbe6f15aad3a55a5860b88800e0a3ecbb3 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 13 Sep 2024 16:26:42 -0400 Subject: [PATCH 08/13] Improve LoggerName logic --- src/libraries/JANA/Components/JComponentFwd.h | 10 +++++++++- src/libraries/JANA/JService.cc | 3 +-- .../JANA/Services/JParameterManager.cc | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/libraries/JANA/Components/JComponentFwd.h b/src/libraries/JANA/Components/JComponentFwd.h index eba5c4fdd..2471932d2 100644 --- a/src/libraries/JANA/Components/JComponentFwd.h +++ b/src/libraries/JANA/Components/JComponentFwd.h @@ -34,6 +34,7 @@ struct JComponent { CallbackStyle m_callback_style = CallbackStyle::LegacyMode; std::string m_prefix; std::string m_plugin_name; + std::string m_logger_name; std::string m_type_name; Status m_status = Status::Uninitialized; mutable std::mutex m_mutex; @@ -72,10 +73,17 @@ struct JComponent { JEventLevel GetLevel() const { return m_level; } - std::string GetLoggerName() const { return m_prefix.empty() ? m_type_name : m_prefix; } + std::string GetLoggerName() const { + if (!m_logger_name.empty()) return m_logger_name; + if (!m_prefix.empty()) return m_prefix; + if (!m_type_name.empty()) return m_type_name; + return ""; + } std::string GetPluginName() const { return m_plugin_name; } + void SetLoggerName(std::string logger_name) { m_logger_name = std::move(logger_name); } + void SetPluginName(std::string plugin_name) { m_plugin_name = std::move(plugin_name); }; std::string GetTypeName() const { return m_type_name; } diff --git a/src/libraries/JANA/JService.cc b/src/libraries/JANA/JService.cc index 995d7797c..0a6327fd9 100644 --- a/src/libraries/JANA/JService.cc +++ b/src/libraries/JANA/JService.cc @@ -9,9 +9,8 @@ void JService::DoInit(JServiceLocator* sl) { std::lock_guard lock(m_mutex); if (this->m_status != Status::Uninitialized) return; - auto m_logger_classname = (m_prefix.empty()) ? m_type_name : m_prefix; auto params = m_app->GetJParameterManager(); - m_logger = params->GetLogger(m_logger_classname); + m_logger = params->GetLogger(GetLoggerName()); for (auto* parameter : m_parameters) { parameter->Configure(*params, m_prefix); diff --git a/src/libraries/JANA/Services/JParameterManager.cc b/src/libraries/JANA/Services/JParameterManager.cc index c85d3baf9..951eb0c6c 100644 --- a/src/libraries/JANA/Services/JParameterManager.cc +++ b/src/libraries/JANA/Services/JParameterManager.cc @@ -416,14 +416,20 @@ void JParameterManager::FilterParameters(std::map &par JLogger JParameterManager::GetLogger(const std::string& component_prefix) { - std::ostringstream os; - os << component_prefix << ":loglevel"; + JLogger logger; + logger.className = component_prefix; auto global_log_level = RegisterParameter("jana:global_loglevel", JLogger::Level::INFO, "Global log level"); - auto local_log_level = RegisterParameter(os.str(), global_log_level, "Component log level"); - JLogger logger; - logger.className = component_prefix; - logger.level = local_log_level; + if (component_prefix.empty()) { + logger.level = global_log_level; + } + else { + std::ostringstream os; + os << component_prefix << ":loglevel"; + logger.level = RegisterParameter(os.str(), global_log_level, "Component log level"); + } return logger; } + + From 88279e9a2106989e1a3f0cff19dbb7ed21b77ee8 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Sat, 14 Sep 2024 23:32:09 -0400 Subject: [PATCH 09/13] All internal loggers use "jana" `logger_name` --- src/libraries/JANA/CLI/JSignalHandler.cc | 5 ++++ .../JANA/Calibrations/JCalibrationManager.h | 14 ++++++----- .../JANA/Engine/JArrowProcessingController.cc | 24 ++++++++----------- .../JANA/Engine/JArrowProcessingController.h | 8 +++---- src/libraries/JANA/JApplication.cc | 2 +- .../JANA/Services/JComponentManager.cc | 4 +++- .../JANA/Services/JParameterManager.cc | 7 +----- src/libraries/JANA/Services/JPluginLoader.h | 4 +++- .../JANA/Topology/JTopologyBuilder.cc | 13 +++++----- .../JANA/Topology/JTopologyBuilder.h | 6 +---- 10 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/libraries/JANA/CLI/JSignalHandler.cc b/src/libraries/JANA/CLI/JSignalHandler.cc index b664c8075..14c2c5d4e 100644 --- a/src/libraries/JANA/CLI/JSignalHandler.cc +++ b/src/libraries/JANA/CLI/JSignalHandler.cc @@ -141,6 +141,11 @@ void register_handlers(JApplication* app) { assert (app != nullptr); g_app = app; g_logger = &default_cout_logger; + *g_logger = app->GetJParameterManager()->GetLogger("jana"); + // Note that this updates the static default_cout_logger to match the user-provided jana:loglevel. + // It would be nice to do this in a less unexpected place, and hopefully that will naturally + // emerge from future refactorings. + g_app->GetJParameterManager()->SetDefaultParameter("jana:status_fname", g_path_to_named_pipe, "Filename of named pipe for retrieving instantaneous status info"); create_named_pipe(g_path_to_named_pipe); diff --git a/src/libraries/JANA/Calibrations/JCalibrationManager.h b/src/libraries/JANA/Calibrations/JCalibrationManager.h index 500494f57..e45255c1a 100644 --- a/src/libraries/JANA/Calibrations/JCalibrationManager.h +++ b/src/libraries/JANA/Calibrations/JCalibrationManager.h @@ -6,9 +6,10 @@ #include #include -#include +#include #include +#include "JANA/Services/JParameterManager.h" #include "JLargeCalibration.h" class JCalibrationManager : public JService { @@ -21,17 +22,17 @@ class JCalibrationManager : public JService { pthread_mutex_t m_resource_manager_mutex; std::shared_ptr m_params; - JLogger m_logger; + std::string m_url = "file://./"; std::string m_context = "default"; public: - void acquire_services(JServiceLocator *service_locator) { - // Configure our logger + JCalibrationManager() { + SetPrefix("jana"); + } - m_params = service_locator->get(); - m_logger = m_params->GetLogger("JCalibrationManager"); + void acquire_services(JServiceLocator* sl) { // Url and context may be passed in either as environment variables // or configuration parameters. Default values are used if neither is available. @@ -39,6 +40,7 @@ class JCalibrationManager : public JService { if (getenv("JANA_CALIB_URL") != nullptr) m_url = getenv("JANA_CALIB_URL"); if (getenv("JANA_CALIB_CONTEXT") != nullptr) m_context = getenv("JANA_CALIB_CONTEXT"); + m_params = sl->get(); m_params->SetDefaultParameter("JANA:CALIB_URL", m_url, "URL used to access calibration constants"); m_params->SetDefaultParameter("JANA:CALIB_CONTEXT", m_context, "Calibration context to pass on to concrete JCalibration derived class"); diff --git a/src/libraries/JANA/Engine/JArrowProcessingController.cc b/src/libraries/JANA/Engine/JArrowProcessingController.cc index f056aba17..6c475563d 100644 --- a/src/libraries/JANA/Engine/JArrowProcessingController.cc +++ b/src/libraries/JANA/Engine/JArrowProcessingController.cc @@ -17,10 +17,6 @@ using secs = std::chrono::duration; void JArrowProcessingController::acquire_services(JServiceLocator * sl) { auto params = sl->get(); - m_logger = params->GetLogger("JArrowProcessingController"); - m_worker_logger = params->GetLogger("JWorker"); - m_scheduler_logger = params->GetLogger("JScheduler"); - m_topology = sl->get(); 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."); @@ -31,8 +27,8 @@ void JArrowProcessingController::acquire_services(JServiceLocator * sl) { void JArrowProcessingController::initialize() { m_scheduler = new JScheduler(m_topology); - m_scheduler->logger = m_scheduler_logger; - LOG_INFO(m_logger) << m_topology->mapping << LOG_END; + m_scheduler->logger = GetLogger(); + LOG_INFO(GetLogger()) << m_topology->mapping << LOG_END; m_scheduler->initialize_topology(); @@ -48,7 +44,7 @@ void JArrowProcessingController::initialize() { /// /// @param [in] nthreads The number of worker threads to start void JArrowProcessingController::run(size_t nthreads) { - LOG_INFO(m_logger) << "run(): Launching " << nthreads << " workers" << LOG_END; + LOG_INFO(GetLogger()) << "run(): Launching " << nthreads << " workers" << LOG_END; // run_topology needs to happen _before_ threads are started so that threads don't quit due to lack of assignments m_scheduler->run_topology(nthreads); @@ -59,7 +55,7 @@ void JArrowProcessingController::run(size_t nthreads) { size_t next_cpu_id = m_topology->mapping.get_cpu_id(next_worker_id); size_t next_loc_id = m_topology->mapping.get_loc_id(next_worker_id); auto worker = new JWorker(this, m_scheduler, next_worker_id, next_cpu_id, next_loc_id, pin_to_cpu); - worker->logger = m_worker_logger; + worker->logger = GetLogger(); m_workers.push_back(worker); next_worker_id++; } @@ -73,14 +69,14 @@ void JArrowProcessingController::run(size_t nthreads) { void JArrowProcessingController::scale(size_t nthreads) { - LOG_INFO(m_logger) << "scale(): Stopping all running workers" << LOG_END; + LOG_INFO(GetLogger()) << "scale(): Stopping all running workers" << LOG_END; m_scheduler->request_topology_pause(); for (JWorker* worker : m_workers) { worker->wait_for_stop(); } m_scheduler->achieve_topology_pause(); - LOG_INFO(m_logger) << "scale(): All workers are stopped" << LOG_END; + LOG_INFO(GetLogger()) << "scale(): All workers are stopped" << LOG_END; bool pin_to_cpu = (m_topology->mapping.get_affinity() != JProcessorMapping::AffinityStrategy::None); size_t next_worker_id = m_workers.size(); @@ -90,12 +86,12 @@ void JArrowProcessingController::scale(size_t nthreads) { size_t next_loc_id = m_topology->mapping.get_loc_id(next_worker_id); auto worker = new JWorker(this, m_scheduler, next_worker_id, next_cpu_id, next_loc_id, pin_to_cpu); - worker->logger = m_worker_logger; + worker->logger = GetLogger(); m_workers.push_back(worker); next_worker_id++; } - LOG_INFO(m_logger) << "scale(): Restarting " << nthreads << " workers" << LOG_END; + LOG_INFO(GetLogger()) << "scale(): Restarting " << nthreads << " workers" << LOG_END; // topology->run needs to happen _before_ threads are started so that threads don't quit due to lack of assignments m_scheduler->run_topology(nthreads); @@ -232,12 +228,12 @@ JArrowMetrics::Status JArrowProcessingController::execute_arrow(int arrow_index) void JArrowProcessingController::print_report() { auto metrics = measure_performance(); - LOG_INFO(m_logger) << "Running" << *metrics << LOG_END; + LOG_INFO(GetLogger()) << "Running" << *metrics << LOG_END; } void JArrowProcessingController::print_final_report() { auto metrics = measure_performance(); - LOG_INFO(m_logger) << "Final Report" << *metrics << LOG_END; + LOG_INFO(GetLogger()) << "Final Report" << *metrics << LOG_END; } std::unique_ptr JArrowProcessingController::measure_performance() { diff --git a/src/libraries/JANA/Engine/JArrowProcessingController.h b/src/libraries/JANA/Engine/JArrowProcessingController.h index 05ef6fb22..1fb81e755 100644 --- a/src/libraries/JANA/Engine/JArrowProcessingController.h +++ b/src/libraries/JANA/Engine/JArrowProcessingController.h @@ -7,12 +7,16 @@ #include #include #include +#include #include class JArrowProcessingController : public JService { public: + JArrowProcessingController() { + SetPrefix("jana"); + } ~JArrowProcessingController() override; void acquire_services(JServiceLocator *) override; @@ -53,9 +57,5 @@ class JArrowProcessingController : public JService { JScheduler* m_scheduler = nullptr; std::vector m_workers; - JLogger m_logger; - JLogger m_worker_logger; - JLogger m_scheduler_logger; - }; diff --git a/src/libraries/JANA/JApplication.cc b/src/libraries/JANA/JApplication.cc index fa84def8a..ab4d58d17 100644 --- a/src/libraries/JANA/JApplication.cc +++ b/src/libraries/JANA/JApplication.cc @@ -124,7 +124,7 @@ void JApplication::Initialize() { auto topology_builder = m_service_locator->get(); // Set logger on JApplication itself - m_logger = m_params->GetLogger("JApplication"); + m_logger = m_params->GetLogger("jana"); m_logger.show_classname = false; // Set up wiring diff --git a/src/libraries/JANA/Services/JComponentManager.cc b/src/libraries/JANA/Services/JComponentManager.cc index a15dcaa8f..686263262 100644 --- a/src/libraries/JANA/Services/JComponentManager.cc +++ b/src/libraries/JANA/Services/JComponentManager.cc @@ -10,7 +10,9 @@ #include #include -JComponentManager::JComponentManager() {} +JComponentManager::JComponentManager() { + SetPrefix("jana"); +} JComponentManager::~JComponentManager() { diff --git a/src/libraries/JANA/Services/JParameterManager.cc b/src/libraries/JANA/Services/JParameterManager.cc index 951eb0c6c..f6c5fdc01 100644 --- a/src/libraries/JANA/Services/JParameterManager.cc +++ b/src/libraries/JANA/Services/JParameterManager.cc @@ -17,12 +17,7 @@ using namespace std; /// @brief Default constructor JParameterManager::JParameterManager() { - // Set the logger temporarily - m_logger = GetLogger("JParameterManager"); - - // Short-circuit JParameterManager::DoInit() - // Otherwise there is a cycle when initializing JParameterManager and JLoggingService - this->m_status = Status::Initialized; + SetLoggerName("jana"); } /// @brief Copy constructor diff --git a/src/libraries/JANA/Services/JPluginLoader.h b/src/libraries/JANA/Services/JPluginLoader.h index 3707292dd..6a090c872 100644 --- a/src/libraries/JANA/Services/JPluginLoader.h +++ b/src/libraries/JANA/Services/JPluginLoader.h @@ -36,7 +36,9 @@ class JPluginLoader : public JService { public: - JPluginLoader() = default; + JPluginLoader() { + SetPrefix("jana"); + } ~JPluginLoader() override = default; void Init() override; diff --git a/src/libraries/JANA/Topology/JTopologyBuilder.cc b/src/libraries/JANA/Topology/JTopologyBuilder.cc index 5c5db07ae..9ad69bfea 100644 --- a/src/libraries/JANA/Topology/JTopologyBuilder.cc +++ b/src/libraries/JANA/Topology/JTopologyBuilder.cc @@ -16,6 +16,10 @@ using Event = std::shared_ptr; using EventQueue = JMailbox; +JTopologyBuilder::JTopologyBuilder() { + SetPrefix("jana"); +} + JTopologyBuilder::~JTopologyBuilder() { for (auto arrow : arrows) { delete arrow; @@ -105,12 +109,12 @@ void JTopologyBuilder::create_topology() { } int id=0; for (auto* queue : queues) { - queue->set_logger(m_queue_logger); + queue->set_logger(GetLogger()); queue->set_id(id); id += 1; } for (auto* arrow : arrows) { - arrow->set_logger(m_arrow_logger); + arrow->set_logger(GetLogger()); } } @@ -153,9 +157,6 @@ void JTopologyBuilder::acquire_services(JServiceLocator *sl) { m_params->SetDefaultParameter("jana:locality", m_locality, "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_params->GetLogger("JArrow"); - m_queue_logger = m_params->GetLogger("JQueue"); }; @@ -214,7 +215,7 @@ void JTopologyBuilder::attach_lower_level(JEventLevel current_level, JUnfoldArro auto* proc_arrow = new JEventProcessorArrow(ss.str()+"Tap", q1, q2, nullptr); arrows.push_back(proc_arrow); proc_arrow->set_chunksize(m_event_processor_chunksize); - proc_arrow->set_logger(m_arrow_logger); + proc_arrow->set_logger(GetLogger()); if (found_sink) { proc_arrow->set_is_sink(false); } diff --git a/src/libraries/JANA/Topology/JTopologyBuilder.h b/src/libraries/JANA/Topology/JTopologyBuilder.h index c0ed19058..e1b546709 100644 --- a/src/libraries/JANA/Topology/JTopologyBuilder.h +++ b/src/libraries/JANA/Topology/JTopologyBuilder.h @@ -51,13 +51,9 @@ class JTopologyBuilder : public JService { JPerfMetrics metrics; JProcessorMapping mapping; - JLogger m_arrow_logger; - JLogger m_queue_logger; - public: - JTopologyBuilder() = default; - + JTopologyBuilder(); ~JTopologyBuilder() override; void acquire_services(JServiceLocator *sl) override; From 5b6e9a5acd99988a2427136df91e306e3d69df3c Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Sun, 15 Sep 2024 00:01:31 -0400 Subject: [PATCH 10/13] Move essential log messages up to WARN level This lets users enjoy a much quieter JANA by setting `-Pjana:loglevel=warn`. --- src/libraries/JANA/CLI/JSignalHandler.cc | 10 +++--- .../JANA/Engine/JArrowProcessingController.cc | 8 +++-- src/libraries/JANA/JApplication.cc | 36 +++++++++---------- .../JANA/Services/JParameterManager.cc | 2 +- src/libraries/JANA/Services/JPluginLoader.cc | 2 +- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/libraries/JANA/CLI/JSignalHandler.cc b/src/libraries/JANA/CLI/JSignalHandler.cc index 14c2c5d4e..dec44a793 100644 --- a/src/libraries/JANA/CLI/JSignalHandler.cc +++ b/src/libraries/JANA/CLI/JSignalHandler.cc @@ -26,7 +26,7 @@ std::atomic_int g_thread_report_count; void create_named_pipe(const std::string& path_to_named_pipe) { - LOG_INFO(*g_logger) << "Creating pipe named \"" << g_path_to_named_pipe + LOG_WARN(*g_logger) << "Creating pipe named \"" << g_path_to_named_pipe << "\" for status info." << LOG_END; mkfifo(path_to_named_pipe.c_str(), 0666); @@ -41,7 +41,7 @@ void send_to_named_pipe(const std::string& path_to_named_pipe, const std::string close(fd); } else { - LOG_WARN(*g_logger) << "Unable to open named pipe '" << g_path_to_named_pipe << "' for writing. \n" + LOG_ERROR(*g_logger) << "Unable to open named pipe '" << g_path_to_named_pipe << "' for writing. \n" << " You can use a different named pipe for status info by setting the parameter `jana:status_fname`.\n" << " The status report will still show up in the log." << LOG_END; } @@ -131,7 +131,7 @@ void handle_usr2(int) { void handle_sigsegv(int /*signal_number*/, siginfo_t* /*signal_info*/, void* /*context*/) { LOG_FATAL(*g_logger) << "Segfault detected! Printing backtraces and exiting." << LOG_END; auto report = produce_overall_report(); - LOG_INFO(*g_logger) << report << LOG_END; + LOG_FATAL(*g_logger) << report << LOG_END; exit(static_cast(JApplication::ExitCode::Segfault)); } @@ -159,10 +159,10 @@ void register_handlers(JApplication* app) { sigemptyset(&sSignalAction.sa_mask); sigaction(SIGSEGV, &sSignalAction, nullptr); - LOG_INFO(*g_logger) << "Setting signal handler USR1. Use to write status info to the named pipe." << LOG_END; + LOG_WARN(*g_logger) << "Setting signal handler USR1. Use to write status info to the named pipe." << LOG_END; signal(SIGUSR1, handle_usr1); signal(SIGUSR2, handle_usr2); - LOG_INFO(*g_logger) << "Setting signal handler SIGINT (Ctrl-C). Use a single SIGINT to enter the Inspector, or multiple SIGINTs for an immediate shutdown." << LOG_END; + LOG_WARN(*g_logger) << "Setting signal handler SIGINT (Ctrl-C). Use a single SIGINT to enter the Inspector, or multiple SIGINTs for an immediate shutdown." << LOG_END; signal(SIGINT, handle_sigint); } diff --git a/src/libraries/JANA/Engine/JArrowProcessingController.cc b/src/libraries/JANA/Engine/JArrowProcessingController.cc index 6c475563d..ce38f6ea7 100644 --- a/src/libraries/JANA/Engine/JArrowProcessingController.cc +++ b/src/libraries/JANA/Engine/JArrowProcessingController.cc @@ -2,9 +2,9 @@ // 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 #include +#include #include #include #include @@ -233,7 +233,11 @@ void JArrowProcessingController::print_report() { void JArrowProcessingController::print_final_report() { auto metrics = measure_performance(); - LOG_INFO(GetLogger()) << "Final Report" << *metrics << LOG_END; + + + LOG_INFO(GetLogger()) << "Detailed report" << *metrics << LOG_END; + LOG_WARN(GetLogger()) << "Final report: " << metrics->total_events_completed << " events processed at " + << JTypeInfo::to_string_with_si_prefix(metrics->avg_throughput_hz) << "Hz" << LOG_END; } std::unique_ptr JArrowProcessingController::measure_performance() { diff --git a/src/libraries/JANA/JApplication.cc b/src/libraries/JANA/JApplication.cc index ab4d58d17..54649e645 100644 --- a/src/libraries/JANA/JApplication.cc +++ b/src/libraries/JANA/JApplication.cc @@ -3,18 +3,15 @@ // Subject to the terms in the LICENSE file found in the top-level directory. #include - #include - -#include -#include +#include +#include #include +#include #include -#include -#include #include -#include -#include +#include +#include #include #include @@ -108,17 +105,12 @@ void JApplication::Initialize() { // Only run this once if (m_initialized) return; - std::ostringstream oss; - oss << "Initializing..." << std::endl; - JVersion::PrintSplash(oss); - JVersion::PrintVersionDescription(oss); - LOG_INFO(m_logger) << oss.str() << LOG_END; - // Now that all parameters, components, plugin names, etc have been set, // we can expose our builtin services to the user via GetService() m_services_available = true; - + // We trigger initialization + m_service_locator->get(); auto component_manager = m_service_locator->get(); auto plugin_loader = m_service_locator->get(); auto topology_builder = m_service_locator->get(); @@ -127,6 +119,12 @@ void JApplication::Initialize() { m_logger = m_params->GetLogger("jana"); m_logger.show_classname = false; + std::ostringstream oss; + oss << "Initializing..." << std::endl; + JVersion::PrintSplash(oss); + JVersion::PrintVersionDescription(oss); + LOG_WARN(m_logger) << oss.str() << LOG_END; + // Set up wiring ProvideService(std::make_shared()); @@ -191,7 +189,7 @@ void JApplication::Run(bool wait_until_finished) { m_params->PrintParameters(); LOG_INFO(m_logger) << GetComponentSummary() << LOG_END; - LOG_INFO(m_logger) << "Starting processing with " << m_desired_nthreads << " threads requested..." << LOG_END; + LOG_WARN(m_logger) << "Starting processing with " << m_desired_nthreads << " threads requested..." << LOG_END; m_processing_controller->run(m_desired_nthreads); if (!wait_until_finished) { @@ -258,7 +256,7 @@ void JApplication::Run(bool wait_until_finished) { m_processing_controller->wait_until_stopped(); } - LOG_INFO(m_logger) << "Event processing ended." << LOG_END; + LOG_WARN(m_logger) << "Event processing ended." << LOG_END; PrintFinalReport(); // Test for exception one more time, in case it shut down the topology before the supervisor could detect it @@ -272,7 +270,7 @@ void JApplication::Run(bool wait_until_finished) { void JApplication::Scale(int nthreads) { - LOG_INFO(m_logger) << "Scaling to " << nthreads << " threads" << LOG_END; + LOG_WARN(m_logger) << "Scaling to " << nthreads << " threads" << LOG_END; m_processing_controller->scale(nthreads); } @@ -393,7 +391,7 @@ void JApplication::PrintStatus() { else { std::lock_guard lock(m_status_mutex); update_status(); - LOG_INFO(m_logger) << "Status: " << m_perf_summary->total_events_completed << " events processed " + LOG_WARN(m_logger) << "Status: " << m_perf_summary->total_events_completed << " events processed at " << JTypeInfo::to_string_with_si_prefix(m_perf_summary->latest_throughput_hz) << "Hz (" << JTypeInfo::to_string_with_si_prefix(m_perf_summary->avg_throughput_hz) << "Hz avg)" << LOG_END; } diff --git a/src/libraries/JANA/Services/JParameterManager.cc b/src/libraries/JANA/Services/JParameterManager.cc index f6c5fdc01..3ca41539f 100644 --- a/src/libraries/JANA/Services/JParameterManager.cc +++ b/src/libraries/JANA/Services/JParameterManager.cc @@ -152,7 +152,7 @@ void JParameterManager::PrintParameters(int verbosity, int strictness) { } } if ((!param->IsDefault()) && (param->IsDeprecated())) { - LOG_WARN(m_logger) << "Parameter '" << key << "' has been deprecated and will no longer be supported in the next release." << LOG_END; + LOG_WARN(m_logger) << "Parameter '" << key << "' has been deprecated and may no longer be supported in future releases." << LOG_END; warnings_present = true; } } diff --git a/src/libraries/JANA/Services/JPluginLoader.cc b/src/libraries/JANA/Services/JPluginLoader.cc index 5ab20ae2c..f3f7bd918 100644 --- a/src/libraries/JANA/Services/JPluginLoader.cc +++ b/src/libraries/JANA/Services/JPluginLoader.cc @@ -189,7 +189,7 @@ void JPluginLoader::attach_plugin(std::string name, std::string path) { } // Run InitPlugin() and wrap exceptions as needed - LOG_INFO(m_logger) << "Initializing plugin \"" << name << "\" at path \"" << path << "\"" << LOG_END; + LOG_WARN(m_logger) << "Loading plugin '" << name << "' from '" << path << "'" << LOG_END; try { (*initialize_proc)(GetApplication()); From b44bce34a9419096be53dadb69b2e7e69b43a49f Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Sun, 15 Sep 2024 00:04:10 -0400 Subject: [PATCH 11/13] Tests use new `jana:loglevel` param --- src/examples/SubeventCUDAExample/SubeventCUDAExample.cu | 1 - src/examples/SubeventExample/SubeventExample.cc | 2 +- .../UnitTestingExample/SimpleClusterFactoryTests.cc | 3 +-- src/programs/perf_tests/PerfTests.cc | 8 +++++--- .../Components/JEventProcessorSequentialTests.cc | 6 ++---- .../unit_tests/Components/JEventProcessorTests.cc | 3 +-- src/programs/unit_tests/Components/JEventSourceTests.cc | 3 +-- src/programs/unit_tests/Components/JFactoryTests.cc | 3 ++- src/programs/unit_tests/Components/NEventNSkipTests.cc | 1 - src/programs/unit_tests/Components/UserExceptionTests.cc | 2 +- src/programs/unit_tests/Engine/ScaleTests.cc | 9 +++------ src/programs/unit_tests/Engine/TerminationTests.cc | 3 +-- .../unit_tests/Topology/MultiLevelTopologyTests.cc | 2 +- src/programs/unit_tests/Topology/SubeventTests.cc | 1 - 14 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/examples/SubeventCUDAExample/SubeventCUDAExample.cu b/src/examples/SubeventCUDAExample/SubeventCUDAExample.cu index 1bc4287d0..16ea6eee5 100644 --- a/src/examples/SubeventCUDAExample/SubeventCUDAExample.cu +++ b/src/examples/SubeventCUDAExample/SubeventCUDAExample.cu @@ -133,7 +133,6 @@ int main() { auto merge_arrow = new JMergeArrow("merge", &processor, &subevents_out, &events_out); JApplication app; - app.SetParameterValue("log:info", "JWorker,JScheduler,JArrowProcessingController,JEventProcessorArrow"); app.SetTimeoutEnabled(false); app.SetTicker(false); diff --git a/src/examples/SubeventExample/SubeventExample.cc b/src/examples/SubeventExample/SubeventExample.cc index 71f5f6b25..634b4ae9f 100644 --- a/src/examples/SubeventExample/SubeventExample.cc +++ b/src/examples/SubeventExample/SubeventExample.cc @@ -86,7 +86,7 @@ struct SimpleProcessor : public JEventProcessor { int main() { JApplication app; - app.SetParameterValue("log:info", "JWorker,JScheduler,JArrowProcessingController,JEventProcessorArrow"); + app.SetParameterValue("jana:loglevel", "info"); app.SetTimeoutEnabled(false); app.SetTicker(false); diff --git a/src/examples/UnitTestingExample/SimpleClusterFactoryTests.cc b/src/examples/UnitTestingExample/SimpleClusterFactoryTests.cc index d7ca22701..154338a90 100644 --- a/src/examples/UnitTestingExample/SimpleClusterFactoryTests.cc +++ b/src/examples/UnitTestingExample/SimpleClusterFactoryTests.cc @@ -13,8 +13,7 @@ TEST_CASE("SimpleClusterFactoryTests") { // We need to fire up the JApplication so that our Factory can access all of its JServices. // However, for unit testing, we don't need (or want!) to set up an event source or actually call JApplication::Run(). JApplication app; - app.SetParameterValue("log:debug", "SimpleClusterFactory"); - app.SetParameterValue("log:off", "JApplication,JParameterManager,JArrowProcessingController,JArrow"); + app.SetParameterValue("jana:loglevel", "off"); // Add any plugins you need here // app.AddPlugin("myPlugin"); app.Initialize(); // Load the plugins diff --git a/src/programs/perf_tests/PerfTests.cc b/src/programs/perf_tests/PerfTests.cc index 771374e4d..4395a12af 100644 --- a/src/programs/perf_tests/PerfTests.cc +++ b/src/programs/perf_tests/PerfTests.cc @@ -27,7 +27,8 @@ int main() { // entangled "block of 40": dis * 40 auto params = new JParameterManager; - params->SetParameter("log:off", "JApplication,JPluginLoader,JArrowProcessingController,JArrow,JParameterManager"); + params->SetParameter("jana:loglevel", "off"); + // Log levels get set as soon as JApp gets constructed params->SetParameter("jtest:write_csv", false); params->SetParameter("jtest:parser_ms", 2); @@ -48,7 +49,8 @@ int main() { { auto params = new JParameterManager; - params->SetParameter("log:off", "JApplication,JPluginLoader,JArrowProcessingController,JArrow,JParameterManager"); + params->SetParameter("jana:loglevel", "off"); + // Log levels get set as soon as JApp gets constructed params->SetParameter("jtest:write_csv", false); @@ -90,7 +92,7 @@ int main() { ExampleHitCollection c; auto params = new JParameterManager; - params->SetParameter("log:off", "JApplication,JPluginLoader,JArrowProcessingController,JArrow"); // Log levels get set as soon as JApp gets constructed XD + params->SetParameter("jana:loglevel", "off"); JApplication app(params); auto logger = params->GetLogger("PerfTests"); // TODO: Add Podio sources, processors, and factories just like JTest diff --git a/src/programs/unit_tests/Components/JEventProcessorSequentialTests.cc b/src/programs/unit_tests/Components/JEventProcessorSequentialTests.cc index 31aaebb16..e43edd642 100644 --- a/src/programs/unit_tests/Components/JEventProcessorSequentialTests.cc +++ b/src/programs/unit_tests/Components/JEventProcessorSequentialTests.cc @@ -51,8 +51,7 @@ TEST_CASE("JEventProcessorSequentialRootTests") { app.SetParameterValue("jana:nevents", 4); app.SetParameterValue("jana:event_source_chunksize", 1); app.SetParameterValue("jana:event_processor_chunksize", 1); - app.SetParameterValue("log:global", "OFF"); - app.SetParameterValue("log:warn", "JScheduler,JArrow,JArrowProcessingController"); + app.SetParameterValue("jana:loglevel", "warn"); auto proc = new MyRootProcessor; app.Add(proc); app.Run(true); @@ -138,8 +137,7 @@ TEST_CASE("JEventProcessorSequentialTests") { app.SetParameterValue("jana:nevents", 4); app.SetParameterValue("jana:event_source_chunksize", 1); app.SetParameterValue("jana:event_processor_chunksize", 1); - app.SetParameterValue("log:global", "OFF"); - app.SetParameterValue("log:warn", "JScheduler,JArrow,JArrowProcessingController"); + app.SetParameterValue("jana:loglevel", "warn"); auto proc = new MySeqProcessor; app.Add(proc); app.Run(true); diff --git a/src/programs/unit_tests/Components/JEventProcessorTests.cc b/src/programs/unit_tests/Components/JEventProcessorTests.cc index 71d836602..d0ea3ef97 100644 --- a/src/programs/unit_tests/Components/JEventProcessorTests.cc +++ b/src/programs/unit_tests/Components/JEventProcessorTests.cc @@ -41,8 +41,7 @@ TEST_CASE("JEventProcessor_ExpertMode_ProcessCount") { { JApplication app; - app.SetParameterValue("log:global", "off"); - app.SetParameterValue("log:info", "MyEventProcessor"); + app.SetParameterValue("jana:loglevel", "off"); app.SetParameterValue("jana:nevents", 5); app.Add(new JEventSource); diff --git a/src/programs/unit_tests/Components/JEventSourceTests.cc b/src/programs/unit_tests/Components/JEventSourceTests.cc index 2ef433887..3b7c653d1 100644 --- a/src/programs/unit_tests/Components/JEventSourceTests.cc +++ b/src/programs/unit_tests/Components/JEventSourceTests.cc @@ -36,8 +36,7 @@ TEST_CASE("JEventSource_ExpertMode_EmitCount") { sut->SetTypeName("MyEventSource"); JApplication app; - app.SetParameterValue("log:global", "off"); - app.SetParameterValue("log:info", "MyEventSource"); + app.SetParameterValue("jana:loglevel", "off"); app.Add(sut); SECTION("ShutsSelfOff") { diff --git a/src/programs/unit_tests/Components/JFactoryTests.cc b/src/programs/unit_tests/Components/JFactoryTests.cc index 436edbc79..23a620833 100644 --- a/src/programs/unit_tests/Components/JFactoryTests.cc +++ b/src/programs/unit_tests/Components/JFactoryTests.cc @@ -262,7 +262,8 @@ TEST_CASE("JFactory_Logger") { JApplication app; app.Add(new JEventSource); app.Add(new JFactoryGeneratorT()); - app.SetParameterValue("log:debug", "myfac"); + app.SetParameterValue("jana:loglevel", "off"); + app.SetParameterValue("myfac:loglevel", "debug"); app.SetParameterValue("jana:nevents", "1"); app.SetParameterValue("autoactivate", "JFactoryTestDummyObject"); app.Run(); diff --git a/src/programs/unit_tests/Components/NEventNSkipTests.cc b/src/programs/unit_tests/Components/NEventNSkipTests.cc index 03ebbc690..983d66719 100644 --- a/src/programs/unit_tests/Components/NEventNSkipTests.cc +++ b/src/programs/unit_tests/Components/NEventNSkipTests.cc @@ -83,7 +83,6 @@ TEST_CASE("NEventNSkipTests") { TEST_CASE("JEventSourceArrow with multiple JEventSources") { JApplication app; - app.SetParameterValue("log:info","JArrow,JArrowProcessingController"); auto source1 = new NEventNSkipBoundedSource(); auto source2 = new NEventNSkipBoundedSource(); auto source3 = new NEventNSkipBoundedSource(); diff --git a/src/programs/unit_tests/Components/UserExceptionTests.cc b/src/programs/unit_tests/Components/UserExceptionTests.cc index 4593ef781..2ed1fe541 100644 --- a/src/programs/unit_tests/Components/UserExceptionTests.cc +++ b/src/programs/unit_tests/Components/UserExceptionTests.cc @@ -10,7 +10,7 @@ TEST_CASE("UserExceptionTests") { JApplication app; - app.SetParameterValue("log:debug","JApplication,JScheduler,JArrowProcessingController,JWorker,JArrow"); + app.SetParameterValue("jana:loglevel","debug"); app.SetParameterValue("jana:extended_report", 0); SECTION("JEventSource::Open() excepts") { diff --git a/src/programs/unit_tests/Engine/ScaleTests.cc b/src/programs/unit_tests/Engine/ScaleTests.cc index e30962d67..47443a8eb 100644 --- a/src/programs/unit_tests/Engine/ScaleTests.cc +++ b/src/programs/unit_tests/Engine/ScaleTests.cc @@ -10,8 +10,7 @@ TEST_CASE("NThreads") { JApplication app; app.SetParameterValue("jana:nevents",3); - app.SetParameterValue("log:global", "OFF"); - app.SetParameterValue("log:warn", "JScheduler,JArrow,JWorker,JArrowProcessingController"); + app.SetParameterValue("jana:loglevel","warn"); app.Add(new scaletest::DummySource); SECTION("If nthreads not provided, default to 1") { @@ -39,8 +38,7 @@ TEST_CASE("NThreads") { TEST_CASE("ScaleNWorkerUpdate") { JApplication app; app.SetParameterValue("nthreads",4); - app.SetParameterValue("log:global", "OFF"); - app.SetParameterValue("log:warn", "JScheduler,JArrow,JWorker,JArrowProcessingController"); + app.SetParameterValue("jana:loglevel","warn"); app.Add(new scaletest::DummySource); app.Add(new scaletest::DummyProcessor); app.Run(false); @@ -65,8 +63,7 @@ TEST_CASE("ScaleNWorkerUpdate") { TEST_CASE("ScaleThroughputImprovement", "[.][performance]") { JApplication app; - app.SetParameterValue("log:global", "INFO"); - // app.SetParameterValue("log:warn", "JScheduler,JArrow,JWorker,JArrowProcessingController"); + app.SetParameterValue("jana:global_loglevel", "INFO"); app.SetTicker(false); app.Add(new scaletest::DummySource); app.Add(new scaletest::DummyProcessor); diff --git a/src/programs/unit_tests/Engine/TerminationTests.cc b/src/programs/unit_tests/Engine/TerminationTests.cc index 4e939f92b..312f91223 100644 --- a/src/programs/unit_tests/Engine/TerminationTests.cc +++ b/src/programs/unit_tests/Engine/TerminationTests.cc @@ -13,10 +13,9 @@ TEST_CASE("TerminationTests") { JApplication app; - app.SetParameterValue("log:global", "OFF"); + app.SetParameterValue("jana:loglevel", "warn"); auto processor = new CountingProcessor(); app.Add(processor); - app.SetParameterValue("jana:extended_report", 0); SECTION("Manual termination") { diff --git a/src/programs/unit_tests/Topology/MultiLevelTopologyTests.cc b/src/programs/unit_tests/Topology/MultiLevelTopologyTests.cc index c9bf633c6..c380c03c7 100644 --- a/src/programs/unit_tests/Topology/MultiLevelTopologyTests.cc +++ b/src/programs/unit_tests/Topology/MultiLevelTopologyTests.cc @@ -436,7 +436,7 @@ TEST_CASE("MultiLevelTopologyBuilderTests") { TEST_CASE("TimeslicesTests") { JApplication app; - app.SetParameterValue("log:info", "JScheduler,JArrow,JArrowProcessingController"); + app.SetParameterValue("jana:loglevel", "info"); app.SetParameterValue("jana:nevents", "5"); app.Add(new MyTimesliceSource); diff --git a/src/programs/unit_tests/Topology/SubeventTests.cc b/src/programs/unit_tests/Topology/SubeventTests.cc index b4b5c8b9a..c372bf85a 100644 --- a/src/programs/unit_tests/Topology/SubeventTests.cc +++ b/src/programs/unit_tests/Topology/SubeventTests.cc @@ -95,7 +95,6 @@ TEST_CASE("Basic subevent arrow functionality") { SECTION("Execute subevent arrows end-to-end") { JApplication app; - app.SetParameterValue("log:info", "JWorker,JScheduler,JArrow,JArrowProcessingController,JEventProcessorArrow"); app.SetTimeoutEnabled(false); app.SetTicker(false); From 739cec2b196dc2962c519b650a48ae29128e470e Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Sun, 15 Sep 2024 00:59:13 -0400 Subject: [PATCH 12/13] Bring back _DBG_{_} macros --- src/libraries/JANA/Compatibility/JStreamLog.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libraries/JANA/Compatibility/JStreamLog.h b/src/libraries/JANA/Compatibility/JStreamLog.h index 2d9bc7eb7..a84be9fdf 100644 --- a/src/libraries/JANA/Compatibility/JStreamLog.h +++ b/src/libraries/JANA/Compatibility/JStreamLog.h @@ -62,3 +62,7 @@ extern JStreamLog jout; extern JStreamLog jerr; #define jendl std::endl +#define _DBG_ std::cerr<<__FILE__<<":"<<__LINE__<<" " +#define _DBG__ std::cerr<<__FILE__<<":"<<__LINE__< Date: Sun, 15 Sep 2024 10:30:07 -0400 Subject: [PATCH 13/13] Fix failing test case --- src/libraries/JANA/JService.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libraries/JANA/JService.cc b/src/libraries/JANA/JService.cc index 0a6327fd9..60635b262 100644 --- a/src/libraries/JANA/JService.cc +++ b/src/libraries/JANA/JService.cc @@ -9,17 +9,19 @@ void JService::DoInit(JServiceLocator* sl) { std::lock_guard lock(m_mutex); if (this->m_status != Status::Uninitialized) return; - auto params = m_app->GetJParameterManager(); - m_logger = params->GetLogger(GetLoggerName()); + if (m_app != nullptr) { - for (auto* parameter : m_parameters) { - parameter->Configure(*params, m_prefix); - } + auto params = m_app->GetJParameterManager(); + m_logger = params->GetLogger(GetLoggerName()); - for (auto* service : m_services) { - service->Fetch(m_app); - } + for (auto* parameter : m_parameters) { + parameter->Configure(*params, m_prefix); + } + for (auto* service : m_services) { + service->Fetch(m_app); + } + } CallWithJExceptionWrapper("JService::acquire_services", [&](){ this->acquire_services(sl); }); CallWithJExceptionWrapper("JService::Init", [&](){ this->Init(); });