Browse Source

Replace cout macros with l3pp

Former-commit-id: 0cde42558d
tempestpy_adaptions
hbruintjes 9 years ago
parent
commit
d9cb1a79f8
  1. 7
      src/cli/cli.cpp
  2. 43
      src/utility/initialize.cpp
  3. 7
      src/utility/initialize.h
  4. 23
      src/utility/logging.h
  5. 135
      src/utility/macros.h

7
src/cli/cli.cpp

@ -186,14 +186,13 @@ namespace storm {
}
if (storm::settings::getModule<storm::settings::modules::GeneralSettings>().isVerboseSet()) {
STORM_GLOBAL_LOGLEVEL_INFO();
storm::utility::setLogLevel(l3pp::LogLevel::INFO);
}
if (storm::settings::getModule<storm::settings::modules::DebugSettings>().isDebugSet()) {
STORM_GLOBAL_LOGLEVEL_DEBUG();
storm::utility::setLogLevel(l3pp::LogLevel::DEBUG);
}
if (storm::settings::getModule<storm::settings::modules::DebugSettings>().isTraceSet()) {
STORM_GLOBAL_LOGLEVEL_TRACE();
storm::utility::setLogLevel(l3pp::LogLevel::TRACE);
}
if (storm::settings::getModule<storm::settings::modules::DebugSettings>().isLogfileSet()) {
storm::utility::initializeFileLogging();

43
src/utility/initialize.cpp

@ -1,30 +1,55 @@
#include "initialize.h"
#include "src/utility/macros.h"
#include "src/settings/SettingsManager.h"
#include "src/settings/modules/DebugSettings.h"
int storm_runtime_loglevel = STORM_LOGLEVEL_WARN;
#include <iostream>
#include <fstream>
namespace storm {
namespace utility {
void initializeLogger() {
// Intentionally left empty.
l3pp::Logger::initialize();
// By default output to std::cout
l3pp::SinkPtr sink = l3pp::StreamSink::create(std::cout);
l3pp::Logger::getRootLogger()->addSink(sink);
// Default to warn, set by user to something else
l3pp::Logger::getRootLogger()->setLevel(l3pp::LogLevel::WARN);
l3pp::FormatterPtr fptr = l3pp::makeTemplateFormatter(
l3pp::FieldStr<l3pp::Field::LogLevel, 5, l3pp::Justification::LEFT>(),
' (', l3pp::FieldStr<l3pp::Field::FileName>, ':', l3pp::FieldStr<l3pp::Field::Line>, '): ',
l3pp::FieldStr<l3pp::Field::Message>(), '\n'
);
sink->setFormatter(fptr);
}
void setUp() {
initializeLogger();
std::cout.precision(10);
}
void cleanUp() {
// Intentionally left empty.
}
void setLogLevel(l3pp::LogLevel level) {
l3pp::Logger::getRootLogger()->setLevel(level);
if (level <= l3pp::LogLevel::DEBUG) {
#if STORM_LOG_DISABLE_DEBUG
std::cout << "***** warning ***** requested loglevel is not compiled\n";
#endif
}
}
void initializeFileLogging() {
// FIXME.
if (storm::settings::getModule<storm::settings::modules::DebugSettings>().isLogfileSet()) {
std::string logFileName = storm::settings::getModule<storm::settings::modules::DebugSettings>().getLogfilename();
l3pp::SinkPtr sink = l3pp::FileSink::create(logFileName);
l3pp::Logger::getRootLogger()->addSink(sink);
}
}
}
}

7
src/utility/initialize.h

@ -1,6 +1,8 @@
#ifndef STORM_UTILITY_INITIALIZE_H
#define STORM_UTILITY_INITIALIZE_H
#include "src/utility/logging.h"
namespace storm {
namespace utility {
/*!
@ -17,6 +19,11 @@ namespace storm {
*/
void cleanUp();
/*!
* Set the global log level
*/
void setLogLevel(l3pp::LogLevel level);
/*!
* Sets up the logging to file.
*/

23
src/utility/logging.h

@ -0,0 +1,23 @@
#ifndef STORM_UTILITY_LOGGING_H_
#define STORM_UTILITY_LOGGING_H_
#include <l3pp/logging.h>
#if !defined(STORM_LOG_DISABLE_DEBUG) && !defined(STORM_LOG_DISABLE_TRACE)
#define STORM_LOG_TRACE(message) L3PP_LOG_TRACE(l3pp::Logging::getRootLogger(), message)
#else
#define STORM_LOG_TRACE(message) (void)(0)
#endif
#if !defined(STORM_LOG_DISABLE_DEBUG)
#define STORM_LOG_DEBUG(message) L3PP_LOG_DEBUG(l3pp::Logging::getRootLogger(), message)
#else
#define STORM_LOG_DEBUG(message) (void)(0)
#endif
// Define STORM_LOG_WARN, STORM_LOG_ERROR and STORM_LOG_INFO to log the given message with the corresponding log levels.
#define STORM_LOG_INFO(message) L3PP_LOG_INFO(l3pp::Logging::getRootLogger(), message)
#define STORM_LOG_WARN(message) L3PP_LOG_WARN(l3pp::Logging::getRootLogger(), message)
#define STORM_LOG_ERROR(message) L3PP_LOG_ERROR(l3pp::Logging::getRootLogger(), message)
#endif /* STORM_UTILITY_LOGGING_H_ */

135
src/utility/macros.h

@ -1,128 +1,47 @@
#ifndef STORM_UTILITY_MACROS_H_
#define STORM_UTILITY_MACROS_H_
#include <cassert>
#include <string.h>
#include "storm-config.h"
#include "src/utility/logging.h"
#include <iostream>
#include <sstream>
extern int storm_runtime_loglevel;
#define STORM_LOGLEVEL_ERROR 0
#define STORM_LOGLEVEL_WARN 1
#define STORM_LOGLEVEL_INFO 2
#define STORM_LOGLEVEL_DEBUG 3
#define STORM_LOGLEVEL_TRACE 4
#ifdef STORM_LOG_DISABLE_DEBUG
#define STORM_LOG_DISABLE_TRACE
#endif
#define __SHORT_FORM_OF_FILE__ \
(strrchr(__FILE__,'/') \
? strrchr(__FILE__,'/')+1 \
: __FILE__ \
)
#ifndef STORM_LOG_DISABLE_DEBUG
#define STORM_LOG_DEBUG(message) \
do { \
if(storm_runtime_loglevel >= STORM_LOGLEVEL_DEBUG) { \
std::stringstream __ss; \
__ss << message; \
std::cout << "DEBUG (" << __SHORT_FORM_OF_FILE__ << ":" << __LINE__ << "): " << __ss.str() << std::endl; \
} \
} while (false)
#else
#define STORM_LOG_DEBUG(message) \
do { \
} while (false)
#endif
#ifndef STORM_LOG_DISABLE_TRACE
#define STORM_LOG_TRACE(message) \
do { \
if(storm_runtime_loglevel >= STORM_LOGLEVEL_TRACE) { \
std::stringstream __ss; \
__ss << message; \
std::cout << "TRACE (" << __SHORT_FORM_OF_FILE__ << ":" << __LINE__ << "): " << __ss.str() << std::endl; \
} \
} while(false)
#else
#define STORM_LOG_TRACE(message) \
do { \
} while (false)
#endif
#include <cassert>
// Define STORM_LOG_ASSERT which is only checked when NDEBUG is not set.
#ifndef NDEBUG
#define STORM_LOG_ASSERT(cond, message) \
do { \
if (!(cond)) { \
std::cout << "ASSERT FAILED (" << __SHORT_FORM_OF_FILE__ << ":" << __LINE__ << "): " << message << std::endl; \
assert(cond); \
} \
} while (false)
if (!(cond)) { \
STORM_LOG_ERROR(message); \
assert(cond); \
} \
} while (false)
#else
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_ASSERT(cond, message)
#endif
// Define STORM_LOG_THROW to always throw the exception with the given message if the condition fails to hold.
#define STORM_LOG_THROW(cond, exception, message) \
do { \
if (!(cond)) { \
std::cout << "ERROR (" << __SHORT_FORM_OF_FILE__ << ":" << __LINE__ << "): " << message << std::endl; \
STORM_LOG_ERROR(message); \
throw exception() << message; \
} \
} while (false)
// Define STORM_LOG_WARN, STORM_LOG_ERROR and STORM_LOG_INFO to log the given message with the corresponding log levels.
#define STORM_LOG_WARN(message) \
do { \
if(storm_runtime_loglevel >= STORM_LOGLEVEL_WARN) { \
std::stringstream __ss; \
__ss << message; \
std::cout << "WARN (" << __SHORT_FORM_OF_FILE__ << ":" << __LINE__ << "): " << __ss.str() << std::endl; \
} \
} while (false)
} while (false)
#define STORM_LOG_WARN_COND(cond, message) \
do { \
if (!(cond)) { \
STORM_LOG_WARN(message); \
STORM_LOG_WARN(message); \
} \
} while (false)
#define STORM_LOG_INFO(message) \
do { \
if(storm_runtime_loglevel >= STORM_LOGLEVEL_INFO) { \
std::stringstream __ss; \
__ss << message; \
std::cout << "INFO (" << __SHORT_FORM_OF_FILE__ << ":" << __LINE__ << "): " << __ss.str() << std::endl; \
} \
} while (false)
} while (false)
#define STORM_LOG_INFO_COND(cond, message) \
do { \
if (!(cond)) { \
STORM_LOG_INFO(message); \
} \
} while (false)
#define STORM_LOG_ERROR(message) \
do { \
if(storm_runtime_loglevel >= STORM_LOGLEVEL_ERROR) { \
std::stringstream __ss; \
__ss << message; \
std::cout << "ERROR (" << __SHORT_FORM_OF_FILE__ << ":" << __LINE__ << "): " << __ss.str() << std::endl; \
} \
} while (false) \
} while (false)
#define STORM_LOG_ERROR_COND(cond, message) \
do { \
@ -131,32 +50,6 @@ do { \
} \
} while (false) \
#define STORM_GLOBAL_LOGLEVEL_INFO() \
do { \
storm_runtime_loglevel = STORM_LOGLEVEL_INFO; \
} while (false)
#ifndef STORM_LOG_DISABLE_DEBUG
#define STORM_GLOBAL_LOGLEVEL_DEBUG() \
do { \
storm_runtime_loglevel = STORM_LOGLEVEL_DEBUG; \
} while(false)
#else
#define STORM_GLOBAL_LOGLEVEL_DEBUG() \
std::cout << "***** warning ***** loglevel debug is not compiled\n"
#endif
#ifndef STORM_LOG_DISABLE_TRACE
#define STORM_GLOBAL_LOGLEVEL_TRACE() \
do { \
storm_runtime_loglevel = STORM_LOGLEVEL_TRACE; \
} while(false)
#else
#define STORM_GLOBAL_LOGLEVEL_TRACE() \
std::cout << "***** warning ***** loglevel trace is not compiled\n"
#endif
/*!
* Define the macros that print information and optionally also log it.
*/

Loading…
Cancel
Save