Skip to content

Commit

Permalink
just format-cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeichlersmith committed Sep 16, 2024
1 parent f74e635 commit 127ef4b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
5 changes: 3 additions & 2 deletions Framework/include/Framework/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void close();
class Formatter {
int event_number_{0};
Formatter() = default;

public:
/// delete the copy constructor
Formatter(Formatter const&) = delete;
Expand All @@ -109,11 +110,11 @@ class Formatter {
/**
* format the passed record view into the output stream
*
* The format is
* The format is
*
* [ channel ] severity : message
*/
void operator()(const log::record_view &view, log::formatting_ostream &os);
void operator()(const log::record_view& view, log::formatting_ostream& os);
};

} // namespace logging
Expand Down
37 changes: 19 additions & 18 deletions Framework/src/Framework/Logger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ level convertLevel(int iLvl) {
return level(iLvl);
}

logger makeLogger(const std::string &name) {
logger makeLogger(const std::string& name) {
logger lg(log::keywords::channel = name); // already has severity built in
return boost::move(lg);
}


/**
* Our filter implementation aligning with Boost.Log
*
Expand All @@ -47,9 +46,10 @@ logger makeLogger(const std::string &name) {
class Filter {
level fallback_level_;
std::unordered_map<std::string, level> custom_levels_;

public:
Filter(level fallback, std::unordered_map<std::string, level> custom)
: fallback_level_{fallback}, custom_levels_{custom} {}
: fallback_level_{fallback}, custom_levels_{custom} {}
Filter(level fallback) : Filter(fallback, {}) {}
bool operator()(log::attribute_value_set const& attrs) {
const std::string& channel{*log::extract<std::string>(attrs["Channel"])};
Expand All @@ -62,7 +62,6 @@ class Filter {
}
};


void open(const framework::config::Parameters& p) {
// some helpful types
typedef sinks::text_ostream_backend ourSinkBack_t;
Expand All @@ -72,12 +71,13 @@ void open(const framework::config::Parameters& p) {
std::string filePath{p.getParameter<std::string>("filePath", "")};

level termLevel{convertLevel(p.getParameter<int>("termLevel", 4))};
const auto& logRules{p.getParameter<std::vector<framework::config::Parameters>>(
"logRules", {})};
const auto& logRules{
p.getParameter<std::vector<framework::config::Parameters>>("logRules",
{})};
std::unordered_map<std::string, level> custom_levels;
for (const auto& logRule : logRules) {
custom_levels[logRule.getParameter<std::string>("name")] =
convertLevel(logRule.getParameter<int>("level"));
custom_levels[logRule.getParameter<std::string>("name")] =
convertLevel(logRule.getParameter<int>("level"));
}

// allow our logs to access common attributes, the ones availabe are
Expand All @@ -102,9 +102,10 @@ void open(const framework::config::Parameters& p) {

// this is where the logging level is set
fileSink->set_filter(Filter(fileLevel, custom_levels));
fileSink->set_formatter([](const log::record_view &view, log::formatting_ostream &os) {
Formatter::get()(view, os);
});
fileSink->set_formatter(
[](const log::record_view& view, log::formatting_ostream& os) {
Formatter::get()(view, os);
});
core->add_sink(fileSink);
} // file set to pass something

Expand All @@ -124,9 +125,10 @@ void open(const framework::config::Parameters& p) {
// translate integer level to enum
termSink->set_filter(Filter(termLevel, custom_levels));
// need to wrap formatter in lambda to enforce singleton formatter
termSink->set_formatter([](const log::record_view &view, log::formatting_ostream &os) {
Formatter::get()(view, os);
});
termSink->set_formatter(
[](const log::record_view& view, log::formatting_ostream& os) {
Formatter::get()(view, os);
});
core->add_sink(termSink);

return;
Expand All @@ -145,11 +147,10 @@ Formatter& Formatter::get() {
return the_formatter;
}

void Formatter::set(int n) {
Formatter::get().event_number_ = n;
}
void Formatter::set(int n) { Formatter::get().event_number_ = n; }

void Formatter::operator()(const log::record_view &view, log::formatting_ostream &os) {
void Formatter::operator()(const log::record_view& view,
log::formatting_ostream& os) {
os << "[ " << log::extract<std::string>("Channel", view) << " ] "
<< event_number_ << " ";
/**
Expand Down
3 changes: 2 additions & 1 deletion Framework/src/Framework/Process.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Process::Process(const framework::config::Parameters &configuration)
eventHeader_ = 0;

// set up the logging for this run
logging::open(configuration.getParameter<framework::config::Parameters>("logger", {}));
logging::open(
configuration.getParameter<framework::config::Parameters>("logger", {}));

auto run{configuration.getParameter<int>("run", -1)};
if (run > 0) runForGeneration_ = run;
Expand Down

0 comments on commit 127ef4b

Please sign in to comment.