Index: trunk/src/PacpusLib/Log.cpp
===================================================================
--- trunk/src/PacpusLib/Log.cpp	(revision 236)
+++ trunk/src/PacpusLib/Log.cpp	(revision 239)
@@ -7,5 +7,9 @@
 #include <Pacpus/kernel/Log.h>
 
-#ifdef PACPUS_USE_LOG
+#if defined(PACPUS_USE_LOG)
+
+#if defined(PACPUS_LOG_COLORED_OUTPUT)
+#   include "ColorSeverityFormatter.hpp"
+#endif
 
 #include <boost/log/detail/date_time_format_parser.hpp>
@@ -27,24 +31,7 @@
 #include <QString>
 
-// could use Boost.Predef with Boost >= 1.55
-#if defined(WIN32) || defined(_WINDOWS)
-#   define PACPUS_OS_WINDOWS 1
-#elif defined(__unix) || defined(__unix__)
-#   define PACPUS_OS_UNIX 1
-#   if defined(__linux) || defined(__linux__)
-#       define PACPUS_OS_LINUX 1
-#   endif
-#elif defined(__APPLE__) || defined(__MACH__) || defined(Macintosh) || defined(macintosh)
-#   define PACPUS_OS_MACOS 1
-#else
-//  unknown system
-#endif
-
-#if PACPUS_LOG_COLORED_OUTPUT && PACPUS_OS_WINDOWS
-#   include <Windows.h>
-#endif
-
-template< typename CharT, typename TraitsT >
-std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, QString const& s)
+// specialization for char
+template <>
+PACPUSLIB_API std::basic_ostream<char>& operator<< (std::basic_ostream<char>& strm, QString const& s)
 {
     strm << s.toStdString();
@@ -52,7 +39,11 @@
 }
 
-// explicit instantiation
-template
-PACPUSLIB_API std::basic_ostream<char>& operator<< (std::basic_ostream<char>& strm, QString const& s);
+// specialization for wchar_t
+template <>
+PACPUSLIB_API std::basic_ostream<wchar_t>& operator<< (std::basic_ostream<wchar_t>& strm, QString const& s)
+{
+    strm << s.toStdWString();
+    return strm;
+}
 
 namespace pacpus
@@ -60,91 +51,4 @@
 
 BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", ::pacpus::SeverityLevel)
-
-enum Color {
-  COLOR_DEFAULT,
-  COLOR_BLACK,
-  COLOR_RED,
-  COLOR_GREEN,
-  COLOR_YELLOW,
-  COLOR_BLUE,
-  COLOR_MAGENTA,
-  COLOR_CYAN,
-  COLOR_WHITE
-};
-
-//Color getColor(boost::log::trivial::severity_type const& sev)
-//{
-//    using namespace boost::log::trivial;
-
-//    if (sev >= error) {
-//        return COLOR_RED;
-//    } else if (sev == warning) {
-//        return COLOR_YELLOW;
-//    } else if (sev == info) {
-//        return COLOR_GREEN;
-//    } else {
-//        return COLOR_DEFAULT;
-//    }
-//}
-
-#if PACPUS_OS_WINDOWS //&& !PACPUS_OS_WINDOWS_MOBILE
-
-// Returns the character attribute for the given color.
-WORD getColorAttribute(Color color)
-{
-    switch (color) {
-    case COLOR_BLACK:   return 0;
-    case COLOR_RED:     return FOREGROUND_RED;
-    case COLOR_GREEN:   return FOREGROUND_GREEN;
-    case COLOR_YELLOW:  return FOREGROUND_RED | FOREGROUND_GREEN;
-    case COLOR_BLUE:    return FOREGROUND_BLUE;
-    case COLOR_MAGENTA: return FOREGROUND_RED | FOREGROUND_BLUE;
-    case COLOR_CYAN:    return FOREGROUND_GREEN | FOREGROUND_BLUE;
-    case COLOR_WHITE:   return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
-    default:            return 0;
-    }
-}
-
-#else
-
-/// @returns the ANSI color code for the given color. COLOR_DEFAULT is
-/// an invalid input.
-const char* getAnsiColorCode(Color color)
-{
-    const char* kEscapeSequence = "\033[";
-//    const char* kBackground = "";
-    const char* kFontRegular = "0;";
-//    const char* kFontBold = "1;";
-//    const char* kFontWeak = "2;";
-//    const char* kFontStrong = "3;";
-//    const char* kFontUnderline = "4;";
-
-    std::stringstream ss;
-    ss << kEscapeSequence << kFontRegular;
-
-    switch (color) {
-    case COLOR_BLACK:   ss << "30"; break;
-    case COLOR_RED:     ss << "31"; break;
-    case COLOR_GREEN:   ss << "32"; break;
-    case COLOR_YELLOW:  ss << "33"; break;
-    case COLOR_BLUE:    ss << "34"; break;
-    case COLOR_MAGENTA: ss << "35"; break;
-    case COLOR_CYAN:    ss << "36"; break;
-    case COLOR_WHITE:   ss << "37"; break;
-    default:            return "";
-    };
-
-    const char* kPostfix = "m";
-    ss << kPostfix;
-
-    return ss.str().c_str();
-}
-
-const char* getAnsiColorCodeRestoreDefault()
-{
-    return "\033[0m";
-}
-
-#endif // PACPUS_OS_WINDOWS && !PACPUS_OS_WINDOWS_MOBILE
 
 void init_log_factories()
@@ -217,5 +121,5 @@
                 << std::setfill('0') << std::setw(6) << expr::attr< unsigned int >("LineID")
                 //<< " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", date_time::iso_extended_format) << "]"
-                << " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", "%Y-%m-%d %T.%f") << "]"
+                << " [" << boost::log::expressions::format_date_time< posix_time::ptime >("TimeStamp", "%Y-%m-%d %T.%f") << "]"
                 //<< " [" << std::setw(20) << expr::attr<std::string>("Scope") << ">"
                 << " <" << severity << ">"
@@ -228,14 +132,8 @@
     ////////////////////////////////////////////////////////////////////////////////
     // CONSOLE
-#if PACPUS_LOG_COLORED_OUTPUT
-    Color color = COLOR_GREEN;// = getColor(expr::attr<logging::trivial::severity_level>(logging::trivial::severity.get_name()));
-#endif
-
-#if BOOST_VERSION >= 105500
-#else
+    // Create a backend and attach a couple of streams to it
+#if ! (BOOST_VERSION >= 105500)
     using logging::empty_deleter;
 #endif
-
-    // Create a backend and attach a couple of streams to it
     boost::shared_ptr< sinks::text_ostream_backend > backend =
         make_shared< sinks::text_ostream_backend >();
@@ -259,6 +157,6 @@
     (
         expr::stream
-#if PACPUS_LOG_COLORED_OUTPUT && PACPUS_OS_LINUX
-//            << getAnsiColorCode(color)
+#if defined(PACPUS_LOG_COLORED_OUTPUT)
+            << formatSeverityWithColors< SeverityLevel >("Severity")
 #endif
             << std::setfill('0') << std::setw(6) << expr::attr< unsigned int >("LineID")
@@ -269,6 +167,6 @@
             << " "
             << expr::smessage
-#if PACPUS_LOG_COLORED_OUTPUT && PACPUS_OS_LINUX
-            << getAnsiColorCodeRestoreDefault() // Resets the terminal to default.
+#if defined(PACPUS_LOG_COLORED_OUTPUT)
+            << formatSeverityWithColors< SeverityLevel >("Severity", /*restoreDefault=*/ true) // Resets the terminal to default.
 #endif
     );
