diff options
author | Bernard Normier <bernard@zeroc.com> | 2014-10-29 20:38:19 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2014-10-29 20:38:19 +0000 |
commit | f29afb0ca26a0d4964a19d8fd5104cf5f0db81a3 (patch) | |
tree | e6a10ffa1f36d5d0726ff69bd6a91260e21d0259 /cpp/include/Ice/LoggerUtil.h | |
parent | Fixed (ICE-5800) - Slice build dependencies don't work properly in source tree (diff) | |
download | ice-f29afb0ca26a0d4964a19d8fd5104cf5f0db81a3.tar.bz2 ice-f29afb0ca26a0d4964a19d8fd5104cf5f0db81a3.tar.xz ice-f29afb0ca26a0d4964a19d8fd5104cf5f0db81a3.zip |
Fixed ICE-5796: LoggerUtil now deals properly with exceptions (print their stack traces when available)
Diffstat (limited to 'cpp/include/Ice/LoggerUtil.h')
-rw-r--r-- | cpp/include/Ice/LoggerUtil.h | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/cpp/include/Ice/LoggerUtil.h b/cpp/include/Ice/LoggerUtil.h index c5576e1e0b2..1414bb37f03 100644 --- a/cpp/include/Ice/LoggerUtil.h +++ b/cpp/include/Ice/LoggerUtil.h @@ -13,6 +13,7 @@ #include <Ice/Logger.h> #include <Ice/CommunicatorF.h> #include <Ice/Plugin.h> +#include <Ice/Exception.h> namespace Ice { @@ -30,24 +31,61 @@ private: std::ostringstream _str; }; +ICE_API LoggerOutputBase& loggerInsert(LoggerOutputBase& out, const IceUtil::Exception& ex); + +template<typename T> +struct IsException +{ + static char test(IceUtil::Exception*); + static long test(...); + + static const bool value = sizeof(test(static_cast<T*>(0))) == sizeof(char); +}; + +template<typename T, bool = false> +struct LoggerOutputInserter +{ + static inline LoggerOutputBase& + insert(LoggerOutputBase& out, const T& val) + { + out.__str() << val; + return out; + } +}; + +// Partial specialization +template<typename T> +struct LoggerOutputInserter<T, true> +{ + static inline LoggerOutputBase& + insert(LoggerOutputBase& out, const T& ex) + { + return loggerInsert(out, ex); + } +}; + template<typename T> inline LoggerOutputBase& operator<<(LoggerOutputBase& out, const T& val) { - out.__str() << val; - return out; + return LoggerOutputInserter<T, IsException<T>::value>::insert(out, val); } -template<class Y> -LoggerOutputBase& -operator<<(LoggerOutputBase& os, ::IceInternal::ProxyHandle<Y> p) +template<typename T> +inline LoggerOutputBase& +operator<<(LoggerOutputBase& os, const ::IceInternal::ProxyHandle<T>& p) { return os << (p ? p->ice_toString() : ""); } -ICE_API LoggerOutputBase& operator<<(LoggerOutputBase&, std::ios_base& (*)(std::ios_base&)); -ICE_API LoggerOutputBase& operator<<(LoggerOutputBase&, const ::std::exception& ex); +inline LoggerOutputBase& +operator<<(LoggerOutputBase& out, const ::std::exception& ex) +{ + out.__str() << ex.what(); + return out; +} +ICE_API LoggerOutputBase& operator<<(LoggerOutputBase&, std::ios_base& (*)(std::ios_base&)); template<class L, class LPtr, void (L::*output)(const std::string&)> class LoggerOutput : public LoggerOutputBase |