Changeset 236 in pacpusframework
- Timestamp:
- Nov 28, 2013, 5:07:16 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CMakeLists.txt
r187 r236 34 34 set(PACPUS_SOURCE_DIR ${PACPUS_ROOT_DIR}/src) 35 35 set(IS_BUILDING_PACPUS TRUE) 36 37 set(PACPUS_DEFINITIONS "") 36 38 37 39 ################################################################################ -
trunk/cmake/PacpusConfiguration.cmake
r187 r236 19 19 # Global configuration 20 20 # ======================================== 21 set(PACPUS_USE_LOG TRUE CACHE BOOL "Logging using log4cxx, the library is required") 21 set(PACPUS_USE_LOG TRUE CACHE BOOL "Logging using Boost.Log, the library is required") 22 set(PACPUS_LOG_COLORED_OUTPUT FALSE CACHE BOOL "Logging in color.") 22 23 set(PACPUS_INSTALL_3RD FALSE CACHE BOOL "Installation of the 3rd party") 23 24 set(PACPUS_BUILD_DOC FALSE CACHE BOOL "Whether build the documentation - requires Doxygen") … … 32 33 endif() 33 34 endif(PACPUS_USE_SOLUTION_FOLDERS) 35 36 if(PACPUS_LOG_COLORED_OUTPUT) 37 list(APPEND PACPUS_DEFINITIONS " -DPACPUS_LOG_COLORED_OUTPUT=1 ") 38 endif() -
trunk/cmake/PacpusDependencies.cmake
r234 r236 10 10 ################################################################################ 11 11 # OUTPUT 12 set(PACPUS_DEFINITIONS "")13 12 set(PACPUS_DEPENDENCIES_INC "") 14 13 set(PACPUS_DEPENDENCIES_LIB "") … … 120 119 log 121 120 log_setup 121 system 122 122 ) 123 123 include_directories(${Boost_INCLUDE_DIRS}) -
trunk/cmake/PacpusUtilities.cmake
r235 r236 345 345 TARGETS ${ARGV} 346 346 RUNTIME DESTINATION ${PACPUS_INSTALL_DIR}/bin 347 LIBRARY DESTINATION ${PACPUS_INSTALL_DIR}/ lib347 LIBRARY DESTINATION ${PACPUS_INSTALL_DIR}/bin 348 348 ARCHIVE DESTINATION ${PACPUS_INSTALL_DIR}/lib 349 349 ) -
trunk/include/Pacpus/kernel/Log.h
r196 r236 17 17 #include <Pacpus/kernel/PacpusLibConfig.h> 18 18 19 namespace pacpus { 19 namespace pacpus 20 { 20 21 21 22 /// Static log facility initializer … … 34 35 35 36 #if defined(PACPUS_USE_LOG) 37 # include <boost/log/common.hpp> 36 38 # include <boost/log/attributes/named_scope.hpp> 37 # include <boost/log/trivial.hpp> 39 # include <boost/log/core.hpp> 40 # include <boost/log/sources/record_ostream.hpp> 41 # include <boost/log/sources/severity_logger.hpp> 38 42 # include <iosfwd> 43 44 namespace pacpus 45 { 46 /// Trivial severity levels 47 /*PACPUSLIB_API*/ enum SeverityLevel 48 { 49 trace, 50 debug, 51 info, 52 warning, 53 error, 54 fatal 55 }; 56 57 BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(gLogger, ::boost::log::sources::severity_logger_mt< ::pacpus::SeverityLevel>) 58 59 } // namespace pacpus 39 60 40 61 class QString; … … 45 66 # define PACPUS_LOG_FUNCTION() BOOST_LOG_FUNCTION() 46 67 # define PACPUS_LOG_NAMED_SCOPE(name) BOOST_LOG_NAMED_SCOPE(name) 47 # define PACPUS_LOG(level, message) BOOST_LOG_ TRIVIAL(level) << message68 # define PACPUS_LOG(level, message) BOOST_LOG_SEV( ::pacpus::gLogger::get(), level) << message 48 69 #else 49 70 /// @param name Name of the logger, displayed when logging a message. … … 55 76 56 77 /// Logs a message at TRACE level using default logger 57 #define LOG_TRACE(message) PACPUS_LOG( trace, message)78 #define LOG_TRACE(message) PACPUS_LOG( ::pacpus::trace, message) 58 79 /// Logs a message at DEBUG level using default logger 59 #define LOG_DEBUG(message) PACPUS_LOG( debug, message)80 #define LOG_DEBUG(message) PACPUS_LOG( ::pacpus::debug, message) 60 81 /// Logs a message at INFO level using default logger 61 #define LOG_INFO(message) PACPUS_LOG( info, message)82 #define LOG_INFO(message) PACPUS_LOG( ::pacpus::info, message) 62 83 /// Logs a message at WARN level using default logger 63 #define LOG_WARN(message) PACPUS_LOG( warning, message)84 #define LOG_WARN(message) PACPUS_LOG( ::pacpus::warning, message) 64 85 /// Logs a message at ERROR level using default logger 65 #define LOG_ERROR(message) PACPUS_LOG( error, message)86 #define LOG_ERROR(message) PACPUS_LOG( ::pacpus::error, message) 66 87 /// Logs a message at FATAL level using default logger 67 #define LOG_FATAL(message) PACPUS_LOG( fatal, message)88 #define LOG_FATAL(message) PACPUS_LOG( ::pacpus::fatal, message) 68 89 69 90 #endif // DEF_PACPUS_LOG_H -
trunk/src/PacpusLib/Log.cpp
r231 r236 11 11 #include <boost/log/detail/date_time_format_parser.hpp> 12 12 #include <boost/log/expressions.hpp> 13 #include <boost/log/expressions/formatters/if.hpp> 13 14 #include <boost/log/sinks/text_file_backend.hpp> 14 15 #include <boost/log/sinks/text_ostream_backend.hpp> 15 16 #include <boost/log/sources/severity_logger.hpp> 16 #include <boost/log/sources/record_ostream.hpp>17 17 #include <boost/log/support/date_time.hpp> 18 18 #include <boost/log/utility/setup/common_attributes.hpp> 19 19 #include <boost/log/utility/setup/file.hpp> 20 20 #include <boost/log/utility/setup/formatter_parser.hpp> 21 #include <boost/utility/empty_deleter.hpp> 21 #if BOOST_VERSION >= 105500 // header exists from 1.55 22 # include <boost/utility/empty_deleter.hpp> 23 #else 24 # include <boost/log/utility/empty_deleter.hpp> 25 #endif 22 26 #include <ostream> 23 27 #include <QString> 28 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 24 46 25 47 template< typename CharT, typename TraitsT > … … 36 58 namespace pacpus 37 59 { 38 60 61 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_WHITE 73 }; 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_MOBILE 91 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 #else 109 110 /// @returns the ANSI color code for the given color. COLOR_DEFAULT is 111 /// 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_MOBILE 149 39 150 void init_log_factories() 40 151 { … … 78 189 "ThreadID", 79 190 attrs::current_thread_id()); 191 //logging::core::get()->add_global_attribute( 192 // "Scope", 193 // attrs::named_scope()); 80 194 81 195 logging::core::get()->set_filter … … 83 197 #ifdef NDEBUG 84 198 // release 85 logging::trivial::severity >= logging::trivial::debug199 severity >= debug 86 200 #else 87 201 // debug 88 logging::trivial::severity >= logging::trivial::trace 89 #endif 90 ); 91 92 // Add a file log 202 severity >= trace 203 #endif 204 ); 205 206 //////////////////////////////////////////////////////////////////////////////// 207 // FILE 93 208 logging::add_file_log 94 209 ( … … 103 218 //<< " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", date_time::iso_extended_format) << "]" 104 219 << " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", "%Y-%m-%d %T.%f") << "]" 105 << " <" << logging::trivial::severity << ">" 220 //<< " [" << std::setw(20) << expr::attr<std::string>("Scope") << ">" 221 << " <" << severity << ">" 106 222 << " <" << expr::attr< attrs::current_process_id::value_type >("ProcessID") 107 223 << ":" << expr::attr< attrs::current_thread_id::value_type >("ThreadID") << ">" … … 109 225 ) 110 226 ); 227 228 //////////////////////////////////////////////////////////////////////////////// 229 // 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 236 using logging::empty_deleter; 237 #endif 111 238 112 239 // Create a backend and attach a couple of streams to it 113 shared_ptr< sinks::text_ostream_backend > backend = make_shared< sinks::text_ostream_backend >(); 240 boost::shared_ptr< sinks::text_ostream_backend > backend = 241 make_shared< sinks::text_ostream_backend >(); 114 242 backend->add_stream( 115 243 shared_ptr< std::ostream >(&std::clog, empty_deleter()) … … 125 253 sink->set_filter 126 254 ( 127 logging::trivial::severity >= logging::trivial::info255 severity >= info 128 256 ); 129 257 … … 131 259 ( 132 260 expr::stream 261 #if PACPUS_LOG_COLORED_OUTPUT && PACPUS_OS_LINUX 262 // << getAnsiColorCode(color) 263 #endif 133 264 << std::setfill('0') << std::setw(6) << expr::attr< unsigned int >("LineID") 134 265 //<< " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", date_time::iso_extended_format) << "] " 135 266 << " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", "%Y-%m-%d %T.%f") << "] " 136 << "<" << logging::trivial::severity << ">" 267 //<< " [" << std::setw(20) << expr::attr<std::string>("Scope") << ">" 268 << "<" << severity << ">" 137 269 << " " 138 270 << expr::smessage 271 #if PACPUS_LOG_COLORED_OUTPUT && PACPUS_OS_LINUX 272 << getAnsiColorCodeRestoreDefault() // Resets the terminal to default. 273 #endif 139 274 ); 140 275
Note:
See TracChangeset
for help on using the changeset viewer.