00001 #ifndef _BOOST_RPC_LOG_HPP_
00002 #define _BOOST_RPC_LOG_HPP_
00003 #include <boost/format.hpp>
00004 #include <iostream>
00005
00006 #ifndef __func__
00007 #define __func__ __FUNCTION__
00008 #endif
00009
00010 #ifndef WIN32
00011 #define COLOR_CONSOLE 1
00012 #endif
00013 #include <boost/cmt/log/console_defines.h>
00014
00015 namespace boost { namespace cmt { namespace detail {
00016 inline std::string short_name( const std::string& file_name ) { return file_name.substr( file_name.rfind( '/' ) + 1 ); }
00017
00018 inline void log( std::ostream& os, const char* color, const char* file, uint32_t line, const char* method, const char* text )
00019 {
00020 os<<color<<short_name(file)<<":"<<line<<" "<<method<<"] "<<text<< CONSOLE_DEFAULT << std::endl;
00021 }
00022 template<typename P1>
00023 inline void log( std::ostream& os, const char* color, const char* file, uint32_t line, const char* method, const std::string& format, const P1& p1 )
00024 {
00025 os<<color<<short_name(file)<<":"<<line<<" "<<method<<"] "<< (boost::format(format) %p1) << CONSOLE_DEFAULT << std::endl;
00026 }
00027 template<typename P1, typename P2>
00028 inline void log( std::ostream& os, const char* color, const char* file, uint32_t line, const char* method, const std::string& format, const P1& p1, const P2& p2 )
00029 {
00030 os<<color<<short_name(file)<<":"<<line<<" "<<method<<"] "<< boost::format(format) %p1 %p2 << CONSOLE_DEFAULT << std::endl;
00031 }
00032 template<typename P1, typename P2, typename P3>
00033 inline void log( std::ostream& os, const char* color, const char* file, uint32_t line, const char* method, const std::string& format, const P1& p1, const P2& p2, const P3& p3 )
00034 {
00035 os<<color<<short_name(file)<<":"<<line<<" "<<method<<"] "<< (boost::format(format) %p1 %p2 %p3) << CONSOLE_DEFAULT << std::endl;
00036 }
00037 template<typename P1, typename P2, typename P3, typename P4>
00038 inline void log( std::ostream& os, const char* color, const char* file, uint32_t line, const char* method, const std::string& format, const P1& p1, const P2& p2, const P3& p3, const P4& p4 )
00039 {
00040 os<<color<<short_name(file)<<":"<<line<<" "<<method<<"] "<< (boost::format(format) %p1 %p2 %p3 %p4) << CONSOLE_DEFAULT << std::endl;
00041 }
00042 template<typename P1, typename P2, typename P3, typename P4, typename P5>
00043 inline void log( std::ostream& os, const char* color, const char* file, uint32_t line, const char* method, const std::string& format, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5 )
00044 {
00045 os<<color<<short_name(file)<<":"<<line<<" "<<method<<"] "<< (boost::format(format) %p1 %p2 %p3 %p4 %p5) << CONSOLE_DEFAULT << std::endl;
00046 }
00047 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00048 inline void log( std::ostream& os, const char* color, const char* file, uint32_t line, const char* method, const std::string& format, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6 )
00049 {
00050 os<<color<<short_name(file)<<":"<<line<<" "<<method<<"] "<< (boost::format(format) %p1 %p2 %p3 %p4 %p5 %p6) << CONSOLE_DEFAULT << std::endl;
00051 }
00052
00053 } } }
00054
00055 #define dlog(...) do {try { boost::cmt::detail::log( std::cerr, CONSOLE_DEFAULT, __FILE__, __LINE__, __func__, __VA_ARGS__ ); } \
00056 catch (...){ boost::cmt::detail::log( std::cerr, CONSOLE_RED, __FILE__, __LINE__, __func__, "Invalid logs"); } \
00057 }while(false)
00058
00059 #define slog(...) do {try {boost::cmt::detail::log( std::cerr, CONSOLE_DEFAULT, __FILE__, __LINE__, __func__, __VA_ARGS__ ); }\
00060 catch (...){ boost::cmt::detail::log( std::cerr, CONSOLE_RED, __FILE__, __LINE__, __func__, "Invalid logs"); } \
00061 }while(false)
00062
00063 #define elog(...) do {try {boost::cmt::detail::log( std::cerr, CONSOLE_RED, __FILE__, __LINE__, __func__, __VA_ARGS__ ); }\
00064 catch (...){ boost::cmt::detail::log( std::cerr, CONSOLE_RED, __FILE__, __LINE__, __func__, "Invalid logs"); } \
00065 }while(false)
00066
00067 #define wlog(...) do {try {boost::cmt::detail::log( std::cerr, CONSOLE_BROWN, __FILE__, __LINE__, __func__, __VA_ARGS__ ); }\
00068 catch (...){ boost::cmt::detail::log( std::cerr, CONSOLE_RED, __FILE__, __LINE__, __func__, "Invalid logs"); } \
00069 }while(false)
00070
00071 #endif