44#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__WIN64__)
50#if defined(CAB_BOOST) && !defined(NO_THREADSAFE_LOGGING)
51#include <boost/thread.hpp>
110template <
typename OutputPolicy>
132 std::ostringstream
os;
142template <
typename OutputPolicy>
145template <
typename OutputPolicy>
148 os << logTimeString() <<
" " << std::setw(6)
149#if defined(CAB_BOOST) && !defined(NO_MT_LOGGING)
150 << boost::this_thread::get_id() <<
" "
152 << std::setw(8) << std::left << UbLogger<OutputPolicy>::logLevelToString(level) <<
": "
158template <
typename OutputPolicy>
162 OutputPolicy::output(os.str());
165template <
typename OutputPolicy>
172template <
typename OutputPolicy>
175 static std::string
const buffer[] = {
"ERROR",
"WARNING",
"INFO",
"DEBUG",
"DEBUG1",
176 "DEBUG2",
"DEBUG3",
"DEBUG4",
"DEBUG5" };
180template <
typename OutputPolicy>
183 if (level ==
"DEBUG5")
185 if (level ==
"DEBUG4")
187 if (level ==
"DEBUG3")
189 if (level ==
"DEBUG2")
191 if (level ==
"DEBUG1")
193 if (level ==
"DEBUG")
197 if (level ==
"WARNING")
199 if (level ==
"ERROR")
203 <<
"UbLogger<OutputPolicy>::logLevelFromString(level) - unknown logging level '" << level
204 <<
"'. Using INFO level as default.";
211#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__WIN64__)
212template <
typename OutputPolicy>
218 return "Error in std::string UbLogger<OutputPolicy>::logTimeString()";
227template <
typename OutputPolicy>
250 static void output(
const std::string &
msg);
253 static void setStream(
const std::string &filename);
259#if defined(CAB_BOOST) && !defined(NO_MT_LOGGING)
260 static boost::mutex
mtx;
266 static std::ostream *
pStream = &std::clog;
272#if defined(CAB_BOOST) && !defined(NO_MT_LOGGING)
273 boost::mutex::scoped_lock
lock(
mtx);
288 std::ofstream *file =
new std::ofstream(filename.c_str());
293 <<
" Output2Stream::setStream(const std::string& filename) could not open file " << filename
294 <<
" -> std::cerr is used instead " << std::endl;
297 std::cout <<
"UbLog writes to " << filename << std::endl;
303#if defined(CAB_BOOST) && !defined(NO_MT_LOGGING)
304 boost::mutex::scoped_lock
lock(
mtx);
309 (*pStream) <<
msg << std::flush;
320#ifndef UBLOG_MAX_LEVEL
321#define UBLOG_MAX_LEVEL logDEBUG5
327#define UBLOG(level, logtext) \
328 if (level <= UBLOG_MAX_LEVEL && level <= UbLog::reportingLevel() && Output2Stream::getStream()) { \
329 UbLog().get(level) << logtext; \
337#define UBLOGML(level, multiline) \
338 if (level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) \
341 std::ostringstream output; \
342 output << multiline; \
343 std::istringstream input(output.str()); \
344 while (!input.eof()) { \
346 getline(input, dummy, '\n'); \
347 UbLog().get(level) << dummy; \
357#define UBLOG2(level, stream, text) \
358 if (level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) \
361 stream << text << std::endl; \
362 UbLog().get(level) << text; \
369#define UBLOG2ML(level, stream, multiline) \
370 if (level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) \
373 stream << multiline << std::endl; \
374 std::ostringstream output; \
375 output << multiline; \
376 std::istringstream input(output.str()); \
377 while (!input.eof()) { \
379 getline(input, dummy, '\n'); \
380 UbLog().get(level) << dummy; \
Implementation of OutputPolicy)
OutputPolicy output_policy
std::shared_ptr< T > SPtr
static std::string logTimeString()
static std::string logLevelToString(const LogLevel &level)
std::ostringstream & get(const LogLevel &level=logINFO)
static void output(const std::string &msg)
static LogLevel & reportingLevel()
static LogLevel logLevelFromString(const std::string &level)
static std::ostream *& getStream()
static void setStream(const std::string &filename)
creates output-file-stream (of file opening fails -> stream is set to std::cerr)