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;