21 #include "boost/algorithm/string.hpp" 22 #include "boost/date_time/posix_time/posix_time.hpp" 23 #include "boost/date_time/posix_time/posix_time_io.hpp" 24 #include <boost/filesystem.hpp> 43 if (!boost::filesystem::exists(logFilePath.parent_path()))
45 boost::filesystem::create_directories(logFilePath.parent_path());
48 std::ios_base::iostate exceptionMask =
mLogFile.exceptions() | std::ios::failbit | std::ios::badbit;
54 catch (std::ios_base::failure& e)
56 std::cerr << e.what() <<
"\n";
65 std::cout << coloredMessage << std::endl;
67 std::vector<std::string> lines;
68 boost::split(lines, message, boost::is_any_of(
"\n"));
70 if (lines.size() != 0)
73 std::string indent(infoString.size(),
' ');
75 bool logedInfo =
false;
76 for (
unsigned int i = 0; i < lines.size(); ++i)
78 if (!lines[i].
empty())
82 mLogFile << indent << lines[i] << std::endl;
86 mLogFile << infoString << lines[i] << std::endl;
129 throw std::runtime_error(
"LogHelper was not initialiesed!");
135 std::string levels[] = {
"FATAL",
"ERROR",
"WARNING",
"INFO",
"DEBUG"};
136 return levels[level];
141 const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
142 std::stringstream nowStream;
144 return nowStream.str();
149 unsigned int position =
mBarWidth * progress;
151 for (
unsigned int i = 0; i <
mBarWidth; ++i) {
161 std::cout <<
"] " << int(progress * 100) <<
" %\r";
static unsigned int mBarWidth
static const char * LOG_COLOR_GREEN
void log(const std::string &message, LogLevel logLevel=LOG_INFO, const char *logColor=LOG_COLOR_DEFAULT)
SOCI_EMPTY_DECL empty_backend_factory const empty
static void logLine(LogLevel logLevel=LOG_INFO)
static void displayProgress(double progress)
LogHelper(path logFilePath, LogLevel level)
std::string getTimeString()
boost::shared_ptr< LogHelper > LogHelperPtr
static LogHelperPtr mInstance
static const char * LOG_COLOR_DEFAULT
static void logMessage(const std::string &message, LogLevel logLevel=LOG_INFO, const char *logColor=LOG_COLOR_DEFAULT)
std::string getLogLevelString(LogLevel level)
static const char * LOG_COLOR_YELLOW
static LogHelperPtr getInstance()
static void init(path logFilePath, LogLevel level)
static const char * LOG_COLOR_BLUE
static const char * LOG_COLOR_MAGENTA
static const char * LOG_COLOR_RED
this namespace contains all generally usable classes.