Skip to content

Commit 89c187b

Browse files
committed
logging: add '--quiet/-q' flag to disable stdout
by default, everything gets written to stdout but by specifying '-q' ('--quiet') flag to the executable, stdout is disabled completely
1 parent 267df67 commit 89c187b

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

include/pfasst.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ namespace pfasst
3030
cerr << "PFASST::init() : 'with_mpi' flag used without enabling MPI" << endl;
3131
#endif
3232
}
33+
config::read_commandline(argc, argv);
3334
log::start_log(argc, argv);
3435
if (logs) {
3536
logs();
3637
}
37-
config::read_commandline(argc, argv);
3838
}
3939
} // ::pfasst
4040

include/pfasst/config.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ namespace pfasst
115115
static inline void init()
116116
{
117117
options::add_option("Global", "help,h", "display this help message");
118+
options::add_option("Global", "quiet,q", "don't log to stdout");
118119

119120
options::add_option<double>("Duration", "dt", "time step size");
120121
options::add_option<double>("Duration", "tend", "final time of simulation");

include/pfasst/logging.hpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,26 @@ namespace pfasst
168168
id2print.append(LOGGER_ID_LENGTH - id_length, ' ');
169169
}
170170

171+
el::Configurations* default_conf = \
172+
const_cast<el::Configurations*>(el::Loggers::defaultConfigurations());
173+
171174
el::Logger* logger = el::Loggers::getLogger(id);
172175
el::Configurations* conf = logger->configurations();
173176
conf->setGlobally(el::ConfigurationType::MillisecondsWidth,
174-
PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH);
177+
default_conf->get(el::Level::Info,
178+
el::ConfigurationType::MillisecondsWidth)->value());
179+
conf->setGlobally(el::ConfigurationType::ToStandardOutput,
180+
default_conf->get(el::Level::Info,
181+
el::ConfigurationType::ToStandardOutput)->value());
175182
#ifdef WITH_MPI
176183
int initialized = 0;
177184
MPI_Initialized(&initialized);
178185
assert((bool)initialized);
179186
int rank = 0;
180187
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
181188
conf->setGlobally(el::ConfigurationType::ToFile, "true");
182-
conf->setGlobally(el::ConfigurationType::ToStandardOutput, "false");
183189
conf->setGlobally(el::ConfigurationType::Filename,
184190
string("mpi_run_") + to_string(rank) + string(".log"));
185-
#else
186-
conf->setGlobally(el::ConfigurationType::ToFile, "false");
187-
conf->setGlobally(el::ConfigurationType::ToStandardOutput, "true");
188191
#endif
189192
conf->set(el::Level::Info, el::ConfigurationType::Format,
190193
TIMESTAMP + INFO_COLOR + "[" + id2print + ", " + LEVEL + " " + MESSAGE + OUT::reset);
@@ -209,22 +212,24 @@ namespace pfasst
209212
el::Configurations defaultConf;
210213
defaultConf.setToDefault();
211214

215+
if (!pfasst::config::options::get_instance().get_variables_map().count("quiet")) {
216+
defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
217+
} else {
218+
defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "false");
219+
}
212220
#ifdef WITH_MPI
213221
int initialized = 0;
214222
MPI_Initialized(&initialized);
215223
assert((bool)initialized);
216224
int rank = 0;
217225
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
218226
defaultConf.setGlobally(el::ConfigurationType::ToFile, "true");
219-
defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "false");
220227
defaultConf.setGlobally(el::ConfigurationType::Filename,
221228
string("mpi_run_") + to_string(rank) + string(".log"));
222-
#else
223-
defaultConf.setGlobally(el::ConfigurationType::ToFile, "false");
224-
defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
225229
#endif
226-
defaultConf.setGlobally(el::ConfigurationType::MillisecondsWidth, PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH);
227-
el::Loggers::reconfigureAllLoggers(defaultConf);
230+
defaultConf.setGlobally(el::ConfigurationType::MillisecondsWidth,
231+
PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH);
232+
el::Loggers::setDefaultConfigurations(defaultConf, true);
228233

229234
add_custom_logger("default");
230235
add_custom_logger("Controller");

0 commit comments

Comments
 (0)