From febe7a2d5842c072e880652e426051ec755d226d Mon Sep 17 00:00:00 2001 From: gereon Date: Sun, 2 Dec 2012 10:30:48 +0100 Subject: [PATCH] adding handling for --verbose if --verbose is set, log to file and to console, otherwise only to file. --- src/mrmc.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/mrmc.cpp b/src/mrmc.cpp index 963b157d1..67c772157 100644 --- a/src/mrmc.cpp +++ b/src/mrmc.cpp @@ -37,22 +37,23 @@ log4cplus::Logger logger; /*! * Initializes the logging framework. */ -void setUpLogging() { +void setUpFileLogging() { log4cplus::SharedAppenderPtr fileLogAppender(new log4cplus::FileAppender("mrmc.log")); fileLogAppender->setName("mainFileAppender"); - fileLogAppender->setLayout(std::auto_ptr(new log4cplus::PatternLayout("%-5p - %D{%H:%M} (%r ms) - %F:%L : %m%n"))); + fileLogAppender->setLayout(std::auto_ptr(new log4cplus::PatternLayout("%-5p - %D{%H:%M:%S} (%r ms) - %F:%L : %m%n"))); logger = log4cplus::Logger::getInstance("mainLogger"); logger.addAppender(fileLogAppender); +} - // Uncomment these lines to enable console logging output - // log4cplus::SharedAppenderPtr consoleLogAppender(new log4cplus::ConsoleAppender()); - // consoleLogAppender->setName("mainConsoleAppender"); - // consoleLogAppender->setLayout(std::auto_ptr(new log4cplus::PatternLayout("%-5p - %D{%H:%M:%s} (%r ms) - %F:%L : %m%n"))); - // logger.addAppender(consoleLogAppender); +void setUpConsoleLogging() { + log4cplus::SharedAppenderPtr consoleLogAppender(new log4cplus::ConsoleAppender()); + consoleLogAppender->setName("mainConsoleAppender"); + consoleLogAppender->setLayout(std::auto_ptr(new log4cplus::PatternLayout("%-5p - %D{%H:%M:%S} - %b:%L : %m%n"))); + logger.addAppender(consoleLogAppender); } int main(const int argc, const char* argv[]) { - setUpLogging(); + setUpFileLogging(); mrmc::settings::Settings* s = NULL; @@ -82,6 +83,12 @@ int main(const int argc, const char* argv[]) { std::cout << mrmc::settings::helpConfigfile << std::endl; return 0; } + + if (s->isSet("verbose")) + { + setUpConsoleLogging(); + LOG4CPLUS_INFO(logger, "Enable verbose mode, log output gets printed to console."); + } mrmc::storage::SquareSparseMatrix* probMatrix = mrmc::parser::readTraFile(s->getString("trafile").c_str()); mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::readLabFile(probMatrix->getRowCount(), s->getString("labfile").c_str());