Ice 3.7 C++11 API Reference
Loading...
Searching...
No Matches
LoggerUtil.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_LOGGER_UTIL_H
6#define ICE_LOGGER_UTIL_H
7
8#include <Ice/Logger.h>
9#include <Ice/CommunicatorF.h>
10#include <Ice/Plugin.h>
11#include <Ice/Exception.h>
12
13namespace Ice
14{
15
21{
22public:
23
25 std::string str() const;
26
28 std::ostringstream& _stream(); // For internal use only. Don't use in your code.
30
31private:
32
33 std::ostringstream _os;
34};
35
37ICE_API LoggerOutputBase& loggerInsert(LoggerOutputBase& out, const IceUtil::Exception& ex);
38
39template<typename T>
40struct IsException
41{
42 static char testex(IceUtil::Exception*);
43 static long testex(...);
44
45 static const bool value = sizeof(testex(static_cast<T*>(0))) == sizeof(char);
46};
47
48template<typename T, bool = false>
49struct LoggerOutputInserter
50{
51 static inline LoggerOutputBase&
52 insert(LoggerOutputBase& out, const T& val)
53 {
54 out._stream() << val;
55 return out;
56 }
57};
58
59// Partial specialization
60template<typename T>
61struct LoggerOutputInserter<T, true>
62{
63 static inline LoggerOutputBase&
64 insert(LoggerOutputBase& out, const T& ex)
65 {
66 return loggerInsert(out, ex);
67 }
68};
69
70template<typename T>
71inline LoggerOutputBase&
72operator<<(LoggerOutputBase& out, const T& val)
73{
74 return LoggerOutputInserter<T, IsException<T>::value>::insert(out, val);
75}
76
77#ifdef ICE_CPP11_MAPPING
78template<typename T, typename ::std::enable_if<::std::is_base_of<::Ice::ObjectPrx, T>::value>::type* = nullptr>
79inline LoggerOutputBase&
80operator<<(LoggerOutputBase& os, const ::std::shared_ptr<T>& p)
81#else
82template<typename T>
83inline LoggerOutputBase&
84operator<<(LoggerOutputBase& os, const ::IceInternal::ProxyHandle<T>& p)
85#endif
86{
87 return os << (p ? p->ice_toString() : "");
88}
89
90inline LoggerOutputBase&
91operator<<(LoggerOutputBase& out, const ::std::exception& ex)
92{
93 out._stream() << ex.what();
94 return out;
95}
96
97ICE_API LoggerOutputBase& operator<<(LoggerOutputBase&, std::ios_base& (*)(std::ios_base&));
99
104template<class L, class LPtr, void (L::*output)(const std::string&)>
106{
107public:
108 inline LoggerOutput(const LPtr& lptr) :
109 _logger(lptr)
110 {}
111
113 {
114 flush();
115 }
116
118 inline void flush()
119 {
120 std::string s = _stream().str();
121 if(!s.empty())
122 {
123 L& ref = *_logger;
124 (ref.*output)(s);
125 }
126 _stream().str("");
127 }
128
129private:
130
131 LPtr _logger;
132};
133
136
139
142
148{
149public:
150 Trace(const LoggerPtr&, const std::string&);
152 void flush();
153
154private:
155
156 LoggerPtr _logger;
157 std::string _category;
158};
159
166{
167public:
168
174 LoggerPlugin(const CommunicatorPtr& communicator, const LoggerPtr& logger);
175
177 virtual void initialize();
178
180 virtual void destroy();
181};
182
183}
184
185#endif
#define ICE_API
Definition Config.h:197
Abstract base class for all Ice exceptions.
Definition Exception.h:22
Definition Config.h:313
Base class for logger output utility classes.
Definition LoggerUtil.h:21
std::string str() const
Obtains the collected output.
Collects output and flushes it via a logger method.
Definition LoggerUtil.h:106
void flush()
Flushes the colleted output to the logger method.
Definition LoggerUtil.h:118
LoggerOutput(const LPtr &lptr)
Definition LoggerUtil.h:108
~LoggerOutput()
Definition LoggerUtil.h:112
LoggerPlugin(const CommunicatorPtr &communicator, const LoggerPtr &logger)
Constructs the plug-in with a target communicator and a logger.
virtual void initialize()
This method is a no-op.
virtual void destroy()
This method is a no-op.
A communicator plug-in.
Definition Plugin.h:78
void flush()
Trace(const LoggerPtr &, const std::string &)
Definition BuiltinSequences.h:56
LoggerOutput< Logger, LoggerPtr, &Logger::print > Print
Flushes output to Logger::print.
Definition LoggerUtil.h:135
LoggerOutput< Logger, LoggerPtr, &Logger::warning > Warning
Flushes output to Logger::warning.
Definition LoggerUtil.h:138
std::ostream & operator<<(std::ostream &out, const ProtocolVersion &version)
Definition Protocol.h:179
LoggerOutput< Logger, LoggerPtr, &Logger::error > Error
Flushes output to Logger::error.
Definition LoggerUtil.h:141