- Timestamp:
- Nov 29, 2013, 6:39:11 PM (11 years ago)
- Location:
- trunk/src/PacpusLib
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/PacpusLib/CMakeLists.txt
r185 r239 34 34 set(PROJECT_HDRS 35 35 ${EXPORT_HDR} 36 37 ColorSeverityFormatter.hpp 36 38 37 39 ${PACPUS_INCLUDE_DIR}/Pacpus/kernel/cstdint.h -
trunk/src/PacpusLib/Log.cpp
r236 r239 7 7 #include <Pacpus/kernel/Log.h> 8 8 9 #ifdef PACPUS_USE_LOG 9 #if defined(PACPUS_USE_LOG) 10 11 #if defined(PACPUS_LOG_COLORED_OUTPUT) 12 # include "ColorSeverityFormatter.hpp" 13 #endif 10 14 11 15 #include <boost/log/detail/date_time_format_parser.hpp> … … 27 31 #include <QString> 28 32 29 // could use Boost.Predef with Boost >= 1.55 30 #if defined(WIN32) || defined(_WINDOWS) 31 # define PACPUS_OS_WINDOWS 1 32 #elif defined(__unix) || defined(__unix__) 33 # define PACPUS_OS_UNIX 1 34 # if defined(__linux) || defined(__linux__) 35 # define PACPUS_OS_LINUX 1 36 # endif 37 #elif defined(__APPLE__) || defined(__MACH__) || defined(Macintosh) || defined(macintosh) 38 # define PACPUS_OS_MACOS 1 39 #else 40 // unknown system 41 #endif 42 43 #if PACPUS_LOG_COLORED_OUTPUT && PACPUS_OS_WINDOWS 44 # include <Windows.h> 45 #endif 46 47 template< typename CharT, typename TraitsT > 48 std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, QString const& s) 33 // specialization for char 34 template <> 35 PACPUSLIB_API std::basic_ostream<char>& operator<< (std::basic_ostream<char>& strm, QString const& s) 49 36 { 50 37 strm << s.toStdString(); … … 52 39 } 53 40 54 // explicit instantiation 55 template 56 PACPUSLIB_API std::basic_ostream<char>& operator<< (std::basic_ostream<char>& strm, QString const& s); 41 // specialization for wchar_t 42 template <> 43 PACPUSLIB_API std::basic_ostream<wchar_t>& operator<< (std::basic_ostream<wchar_t>& strm, QString const& s) 44 { 45 strm << s.toStdWString(); 46 return strm; 47 } 57 48 58 49 namespace pacpus … … 60 51 61 52 BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", ::pacpus::SeverityLevel) 62 63 enum Color {64 COLOR_DEFAULT,65 COLOR_BLACK,66 COLOR_RED,67 COLOR_GREEN,68 COLOR_YELLOW,69 COLOR_BLUE,70 COLOR_MAGENTA,71 COLOR_CYAN,72 COLOR_WHITE73 };74 75 //Color getColor(boost::log::trivial::severity_type const& sev)76 //{77 // using namespace boost::log::trivial;78 79 // if (sev >= error) {80 // return COLOR_RED;81 // } else if (sev == warning) {82 // return COLOR_YELLOW;83 // } else if (sev == info) {84 // return COLOR_GREEN;85 // } else {86 // return COLOR_DEFAULT;87 // }88 //}89 90 #if PACPUS_OS_WINDOWS //&& !PACPUS_OS_WINDOWS_MOBILE91 92 // Returns the character attribute for the given color.93 WORD getColorAttribute(Color color)94 {95 switch (color) {96 case COLOR_BLACK: return 0;97 case COLOR_RED: return FOREGROUND_RED;98 case COLOR_GREEN: return FOREGROUND_GREEN;99 case COLOR_YELLOW: return FOREGROUND_RED | FOREGROUND_GREEN;100 case COLOR_BLUE: return FOREGROUND_BLUE;101 case COLOR_MAGENTA: return FOREGROUND_RED | FOREGROUND_BLUE;102 case COLOR_CYAN: return FOREGROUND_GREEN | FOREGROUND_BLUE;103 case COLOR_WHITE: return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;104 default: return 0;105 }106 }107 108 #else109 110 /// @returns the ANSI color code for the given color. COLOR_DEFAULT is111 /// an invalid input.112 const char* getAnsiColorCode(Color color)113 {114 const char* kEscapeSequence = "\033[";115 // const char* kBackground = "";116 const char* kFontRegular = "0;";117 // const char* kFontBold = "1;";118 // const char* kFontWeak = "2;";119 // const char* kFontStrong = "3;";120 // const char* kFontUnderline = "4;";121 122 std::stringstream ss;123 ss << kEscapeSequence << kFontRegular;124 125 switch (color) {126 case COLOR_BLACK: ss << "30"; break;127 case COLOR_RED: ss << "31"; break;128 case COLOR_GREEN: ss << "32"; break;129 case COLOR_YELLOW: ss << "33"; break;130 case COLOR_BLUE: ss << "34"; break;131 case COLOR_MAGENTA: ss << "35"; break;132 case COLOR_CYAN: ss << "36"; break;133 case COLOR_WHITE: ss << "37"; break;134 default: return "";135 };136 137 const char* kPostfix = "m";138 ss << kPostfix;139 140 return ss.str().c_str();141 }142 143 const char* getAnsiColorCodeRestoreDefault()144 {145 return "\033[0m";146 }147 148 #endif // PACPUS_OS_WINDOWS && !PACPUS_OS_WINDOWS_MOBILE149 53 150 54 void init_log_factories() … … 217 121 << std::setfill('0') << std::setw(6) << expr::attr< unsigned int >("LineID") 218 122 //<< " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", date_time::iso_extended_format) << "]" 219 << " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", "%Y-%m-%d %T.%f") << "]"123 << " [" << boost::log::expressions::format_date_time< posix_time::ptime >("TimeStamp", "%Y-%m-%d %T.%f") << "]" 220 124 //<< " [" << std::setw(20) << expr::attr<std::string>("Scope") << ">" 221 125 << " <" << severity << ">" … … 228 132 //////////////////////////////////////////////////////////////////////////////// 229 133 // CONSOLE 230 #if PACPUS_LOG_COLORED_OUTPUT 231 Color color = COLOR_GREEN;// = getColor(expr::attr<logging::trivial::severity_level>(logging::trivial::severity.get_name())); 232 #endif 233 234 #if BOOST_VERSION >= 105500 235 #else 134 // Create a backend and attach a couple of streams to it 135 #if ! (BOOST_VERSION >= 105500) 236 136 using logging::empty_deleter; 237 137 #endif 238 239 // Create a backend and attach a couple of streams to it240 138 boost::shared_ptr< sinks::text_ostream_backend > backend = 241 139 make_shared< sinks::text_ostream_backend >(); … … 259 157 ( 260 158 expr::stream 261 #if PACPUS_LOG_COLORED_OUTPUT && PACPUS_OS_LINUX262 // << getAnsiColorCode(color)159 #if defined(PACPUS_LOG_COLORED_OUTPUT) 160 << formatSeverityWithColors< SeverityLevel >("Severity") 263 161 #endif 264 162 << std::setfill('0') << std::setw(6) << expr::attr< unsigned int >("LineID") … … 269 167 << " " 270 168 << expr::smessage 271 #if PACPUS_LOG_COLORED_OUTPUT && PACPUS_OS_LINUX272 << getAnsiColorCodeRestoreDefault() // Resets the terminal to default.169 #if defined(PACPUS_LOG_COLORED_OUTPUT) 170 << formatSeverityWithColors< SeverityLevel >("Severity", /*restoreDefault=*/ true) // Resets the terminal to default. 273 171 #endif 274 172 );
Note:
See TracChangeset
for help on using the changeset viewer.