199 namespace bl = boost::log;
200 bl::register_formatter_factory(
"TimeStamp", boost::make_shared<timestamp_formatter_factory>());
201 bl::register_formatter_factory(
"ColorizedSeverity", boost::make_shared<colorized_severity_formatter_factory>());
202 bl::register_formatter_factory(
"Severity", boost::make_shared<severity_formatter_factory>());
203 bl::register_simple_filter_factory<bl::trivial::severity_level, char>(
"Severity");
207 bl::expressions::stream
208 <<
"(" << bl::expressions::attr<int>(
"Rank") <<
") "
209 << bl::expressions::format_date_time<boost::posix_time::ptime>(
"TimeStamp",
"%H:%M:%S") <<
" "
210 << bl::expressions::attr<std::string>(
"File") <<
":"
211 << bl::expressions::attr<int>(
"Line")
212 <<
" [" << bl::expressions::attr<std::string>(
"Module") <<
"] in "
213 << bl::expressions::attr<std::string>(
"Function") <<
": "
214 << bl::expressions::message;
217 using sink_ptr =
typename boost::shared_ptr<boost::log::sinks::sink>;
220 for (
auto &sink : activeSinks) {
221 boost::log::core::get()->remove_sink(sink);
231 if (
auto noconfigs =
std::none_of(configs.
begin(), configs.
end(), [](
const auto &config) { return config.enabled; });
232 !enabled && noconfigs) {
233 auto sink = boost::make_shared<NullSink>();
234 boost::log::core::get()->add_sink(sink);
240 if (configs.
empty()) {
245 for (
const auto &config : configs) {
246 if (!config.enabled) {
251 boost::shared_ptr<StreamBackend> backend;
252 if (config.type ==
"file")
253 backend = boost::make_shared<StreamBackend>(boost::shared_ptr<std::ostream>(
new std::ofstream(config.output)));
254 if (config.type ==
"stream") {
255 if (config.output ==
"stdout")
256 backend = boost::make_shared<StreamBackend>(boost::shared_ptr<std::ostream>(&
std::cout, boost::null_deleter()));
257 if (config.output ==
"stderr")
258 backend = boost::make_shared<StreamBackend>(boost::shared_ptr<std::ostream>(&
std::cerr, boost::null_deleter()));
260 PRECICE_ASSERT(backend !=
nullptr,
"The logging backend was not initialized properly. Check your log config.");
261 backend->auto_flush(
true);
264 auto sink = boost::make_shared<boost::log::sinks::synchronous_sink<StreamBackend>>(backend);
265 sink->set_formatter(boost::log::parse_formatter(config.format));
267 if (config.filter.empty()) {
268 sink->set_filter(boost::log::expressions::attr<bool>(
"preCICE") ==
true);
271 sink->set_filter(boost::log::parse_filter(
"%preCICE% & ( " + config.filter +
" )"));
274 boost::log::core::get()->add_sink(sink);