Skip to content

Commit

Permalink
Inject logger into JFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed May 7, 2024
1 parent 371939f commit 11674a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libraries/JANA/JFactoryGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class JFactoryGeneratorT : public JFactoryGenerator {
factory->SetFactoryName(JTypeInfo::demangle<T>());
factory->SetPluginName(GetPluginName());
factory->SetApplication(GetApplication());
factory->SetLogger(GetApplication()->template GetService<JLoggingService>()->get_logger(factory->GetPrefix()));
factory_set->Add(factory);
}
};
Expand Down
19 changes: 19 additions & 0 deletions src/programs/unit_tests/Components/JFactoryTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,22 @@ TEST_CASE("JFactory_Exception") {
REQUIRE(found_throw == true);
}

struct MyLoggedFactory : public JFactoryT<JFactoryTestDummyObject> {
MyLoggedFactory() {
SetPrefix("myfac");
}
void Process(const std::shared_ptr<const JEvent>&) override {
LOG_INFO(GetLogger()) << "Process ran!" << LOG_END;
REQUIRE(GetLogger().level == JLogger::Level::DEBUG);
}
};
TEST_CASE("JFactory_Logger") {
JApplication app;
app.Add(new JEventSource);
app.Add(new JFactoryGeneratorT<MyLoggedFactory>());
app.SetParameterValue("log:debug", "myfac");
app.SetParameterValue("jana:nevents", "1");
app.SetParameterValue("autoactivate", "JFactoryTestDummyObject");
app.Run();
}

0 comments on commit 11674a7

Please sign in to comment.