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