3#ifndef ICE_LOGGER_UTIL_H
4#define ICE_LOGGER_UTIL_H
6#include "CommunicatorF.h"
20 class ICE_API LoggerOutputBase
23 LoggerOutputBase() =
default;
24 LoggerOutputBase(
const LoggerOutputBase&) =
delete;
26 LoggerOutputBase& operator=(
const LoggerOutputBase&) =
delete;
29 [[nodiscard]] std::string
str()
const;
32 std::ostringstream& _stream();
35 std::ostringstream _os;
41 template<
typename T>
struct IsException
44 static long testex(...) noexcept;
46 static constexpr
bool value = sizeof(testex(static_cast<T*>(
nullptr))) == sizeof(
char);
49 template<typename T,
bool = false> struct LoggerOutputInserter
59 template<
typename T>
struct LoggerOutputInserter<T, true>
61 static inline LoggerOutputBase& insert(LoggerOutputBase& out,
const T& ex) {
return loggerInsert(out, ex); }
64 template<
typename T>
inline LoggerOutputBase&
operator<<(LoggerOutputBase& out,
const T& val)
66 return LoggerOutputInserter<T, IsException<T>::value>::insert(out, val);
69 template<
typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>,
bool> = true>
70 inline LoggerOutputBase&
operator<<(LoggerOutputBase& os,
const std::optional<Prx>& p)
72 return os << (p ? p->ice_toString() :
"");
75 inline LoggerOutputBase&
operator<<(LoggerOutputBase& os,
const ObjectPrx& p) {
return os << p.ice_toString(); }
77 inline LoggerOutputBase&
operator<<(LoggerOutputBase& out,
const std::exception& ex)
79 out._stream() << ex.what();
83 ICE_API LoggerOutputBase&
operator<<(LoggerOutputBase&, std::ios_base& (*)(std::ios_base&));
88 template<
class L,
class LPtr,
void (L::*output)(const std::
string&)>
class LoggerOutput :
public LoggerOutputBase
100 std::string s = _stream().str();
124 class ICE_API
Trace :
public LoggerOutputBase
139 std::string _category;
Abstract base class for all Ice exceptions.
std::string str() const
Gets the collected output.
Base class for logger output utility classes.
void flush()
Flushes the colleted output to the logger method.
LoggerOutput(LPtr logger)
Constructs a LoggerOutput object with the given logger.
Collects output and flushes it via a logger method.
void destroy() override
This method is a no-op.
LoggerPlugin(const CommunicatorPtr &communicator, const LoggerPtr &logger)
Constructs the plug-in with a target communicator and a logger.
void initialize() override
This method is a no-op.
Represents a communicator plug-in.
Trace(LoggerPtr logger, std::string category)
Constructs a Trace object with the given logger and category.
void flush()
Calls Logger::trace with the collected output.
std::ostream & operator<<(std::ostream &os, const SampleEventSeq &types)
Converts the given sample type vector to a string and add it to the stream.
LoggerOutput< Logger, LoggerPtr, &Logger::error > Error
Flushes output to Logger::error.
std::shared_ptr< Communicator > CommunicatorPtr
A shared pointer to a Communicator.
std::shared_ptr< Logger > LoggerPtr
A shared pointer to a Logger.
LoggerOutput< Logger, LoggerPtr, &Logger::warning > Warning
Flushes output to Logger::warning.
LoggerOutput< Logger, LoggerPtr, &Logger::print > Print
Flushes output to Logger::print.