Skip to content

Commit

Permalink
Merge pull request #362 from JeffersonLab/nbrei_yaml_logs
Browse files Browse the repository at this point in the history
Replace parameter and component tables with YAML
  • Loading branch information
nathanwbrei authored Sep 16, 2024
2 parents 7d40da3 + 436eede commit 5453e55
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 45 deletions.
15 changes: 14 additions & 1 deletion src/libraries/JANA/Components/JComponentSummary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,23 @@ void PrintComponentTable(std::ostream& os, const JComponentSummary& cs) {
os << comp_table;
}

void PrintComponentYaml(std::ostream& os, const JComponentSummary& cs) {
os << "Component Summary" << std::endl;

for (const auto* comp : cs.GetAllComponents()) {
os << std::endl;
os << " - base: " << "\"" << comp->GetBaseName() << "\"" << std::endl;
os << " type: " << "\"" << comp->GetTypeName() << "\"" << std::endl;
os << " prefix: " << "\"" << comp->GetPrefix() << "\"" << std::endl;
os << " level: " << "\"" << comp->GetLevel() << "\"" << std::endl;
os << " plugin: " << "\"" << comp->GetPluginName() << "\"" << std::endl;
}
}


std::ostream& operator<<(std::ostream& os, JComponentSummary const& cs) {

PrintComponentTable(os,cs);
PrintComponentYaml(os,cs);
return os;
}

Expand Down
1 change: 1 addition & 0 deletions src/libraries/JANA/Components/JComponentSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ std::ostream& operator<<(std::ostream& os, const JComponentSummary& cs);
std::ostream& operator<<(std::ostream& os, JComponentSummary::Collection const&);
std::ostream& operator<<(std::ostream& os, JComponentSummary::Component const&);
void PrintComponentTable(std::ostream& os, const JComponentSummary&);
void PrintComponentYaml(std::ostream& os, const JComponentSummary&);
void PrintCollectionTable(std::ostream& os, const JComponentSummary&);

inline bool operator==(const JComponentSummary::Collection& lhs, const JComponentSummary::Collection& rhs) {
Expand Down
19 changes: 14 additions & 5 deletions src/libraries/JANA/JApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,20 @@ 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;
if (m_logger.level > JLogger::Level::INFO) {
std::ostringstream oss;
oss << "Initializing..." << std::endl << std::endl;
JVersion::PrintVersionDescription(oss);
LOG_WARN(m_logger) << oss.str() << LOG_END;
}
else {
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<jana::services::JWiringService>());
Expand Down
10 changes: 5 additions & 5 deletions src/libraries/JANA/JVersion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void JVersion::PrintSplash(std::ostream& os) {

void JVersion::PrintVersionDescription(std::ostream& os) {

os << "JANA2 version: " << JVersion::GetVersion() << " ";
os << " JANA2 version: " << JVersion::GetVersion() << " ";
if (is_unknown) {
os << " (unknown git status)";
}
Expand All @@ -46,12 +46,12 @@ void JVersion::PrintVersionDescription(std::ostream& os) {
}
os << std::endl;
if (!JVersion::is_unknown) {
os << "Commit hash: " << JVersion::GetCommitHash() << std::endl;
os << "Commit date: " << JVersion::GetCommitDate() << std::endl;
os << " Commit hash: " << JVersion::GetCommitHash() << std::endl;
os << " Commit date: " << JVersion::GetCommitDate() << std::endl;
}
os << "Install prefix: " << JVersion::GetInstallDir() << std::endl;
os << " Install prefix: " << JVersion::GetInstallDir() << std::endl;
if (JVersion::HasPodio() || JVersion::HasROOT() || JVersion::HasXerces()) {
os << "Optional deps: ";
os << " Optional deps: ";
if (JVersion::HasPodio()) os << "Podio ";
if (JVersion::HasROOT()) os << "ROOT ";
if (JVersion::HasXerces()) os << "Xerces ";
Expand Down
68 changes: 34 additions & 34 deletions src/libraries/JANA/Services/JParameterManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,10 @@ void JParameterManager::PrintParameters(int verbosity, int strictness) {
if ((strictness > 0) && (!param->IsDefault()) && (!param->IsUsed())) {
strictness_violation = true;
warnings_present = true;
if (strictness < 2) {
LOG_WARN(m_logger) << "Parameter '" << key << "' appears to be unused. Possible typo?" << LOG_END;
}
else {
LOG_FATAL(m_logger) << "Parameter '" << key << "' appears to be unused. Possible typo?" << LOG_END;
}
LOG_ERROR(m_logger) << "Parameter '" << key << "' appears to be unused. Possible typo?" << LOG_END;
}
if ((!param->IsDefault()) && (param->IsDeprecated())) {
LOG_WARN(m_logger) << "Parameter '" << key << "' has been deprecated and may no longer be supported in future releases." << LOG_END;
LOG_ERROR(m_logger) << "Parameter '" << key << "' has been deprecated and may no longer be supported in future releases." << LOG_END;
warnings_present = true;
}
}
Expand Down Expand Up @@ -196,38 +191,43 @@ void JParameterManager::PrintParameters(int verbosity, int strictness) {
table.AddColumn("Default", JTablePrinter::Justify::Left, 25);
table.AddColumn("Description", JTablePrinter::Justify::Left, 50);

std::ostringstream ss;
for (JParameter* p: params_to_print) {
if (warnings_present) {
std::string warning;
if (p->IsDeprecated()) {
// If deprecated, it no longer matters whether it is advanced or not. If unused, won't show up here anyway.
warning = "Deprecated";
}
else if (!p->IsUsed()) {
// Can't be both deprecated and unused, since JANA only finds out that it is deprecated by trying to use it
// Can't be both advanced and unused, since JANA only finds out that it is advanced by trying to use it
warning = "Unused";
}
else if (p->IsAdvanced()) {
warning = "Advanced";
}

table | p->GetKey()
| warning
| p->GetValue()
| p->GetDefault()
| p->GetDescription();
ss << std::endl;
ss << " - key: \"" << p->GetKey() << "\"" << std::endl;
ss << " value: \"" << p->GetValue() << "\"" << std::endl;
ss << " default: \"" << p->GetDefault() << "\"" << std::endl;
if (!p->GetDescription().empty()) {
ss << " description: \"";
std::istringstream iss(p->GetDescription());
std::string line;
bool is_first_line = true;
while (std::getline(iss, line)) {
if (!is_first_line) {
ss << std::endl << " " << line;
}
else {
ss << line;
}
is_first_line = false;
}
ss << "\"" << std::endl;
}
if (p->IsDeprecated()) {
ss << " warning: \"Deprecated\"" << std::endl;
// If deprecated, it no longer matters whether it is advanced or not. If unused, won't show up here anyway.
}
else {
table | p->GetKey()
| p->GetValue()
| p->GetDefault()
| p->GetDescription();
else if (!p->IsUsed()) {
// Can't be both deprecated and unused, since JANA only finds out that it is deprecated by trying to use it
// Can't be both advanced and unused, since JANA only finds out that it is advanced by trying to use it
ss << " warning: \"Unused\"" << std::endl;
}
else if (p->IsAdvanced()) {
ss << " warning: \"Advanced\"" << std::endl;
}
}
std::ostringstream ss;
table.Render(ss);
LOG_INFO(m_logger) << "Configuration Parameters\n" << ss.str() << LOG_END;
LOG_WARN(m_logger) << "Configuration Parameters\n" << ss.str() << LOG_END;

// Now that we've printed the table, we can throw an exception if we are being super strict
if (strictness_violation && strictness > 1) {
Expand Down

0 comments on commit 5453e55

Please sign in to comment.