throw std::runtime_error("Unhandled protocol for dnstap: " + protocol.toPrettyString());
}
-void remoteLoggerQueueData(RemoteLoggerInterface& r, const std::string& data)
+static void remoteLoggerQueueData(RemoteLoggerInterface& r, const std::string& data)
{
auto ret = r.queueData(data);
case RemoteLoggerInterface::Result::Queued:
break;
case RemoteLoggerInterface::Result::PipeFull: {
- vinfolog("%s: queue full, dropping.", r.name().c_str());
+ vinfolog("%s: %s", r.name(), RemoteLoggerInterface::toErrorString(ret));
break;
}
case RemoteLoggerInterface::Result::TooLarge: {
- warnlog("%s: Not sending too large protobuf message", r.name().c_str());
+ warnlog("%s: %s", r.name(), RemoteLoggerInterface::toErrorString(ret));
break;
}
case RemoteLoggerInterface::Result::OtherError:
- warnlog("%s: submitting to queue failed", r.name().c_str());
+ warnlog("%s: %s", r.name(), RemoteLoggerInterface::toErrorString(ret));
}
}
FrameStreamLogger(int family, const std::string& address, bool connect, const std::unordered_map<string,unsigned>& options = std::unordered_map<string,unsigned>());
~FrameStreamLogger();
[[nodiscard]] RemoteLoggerInterface::Result queueData(const std::string& data) override;
- std::string name() const override
+ const std::string name() const override
{
return "framestream";
}
case RemoteLoggerInterface::Result::Queued:
break;
case RemoteLoggerInterface::Result::PipeFull: {
+ const auto msg = RemoteLoggerInterface::toErrorString(ret);
const auto name = r.name();
- const auto msg = "queue full, dropping";
SLOG(g_log << Logger::Debug << name << ": " << msg <<std::endl,
g_slog->withName(name)->info(Logr::Debug, msg));
break;
}
case RemoteLoggerInterface::Result::TooLarge: {
+ const auto msg = RemoteLoggerInterface::toErrorString(ret);
const auto name = r.name();
- const auto msg = "Not sending too large protobuf message";
SLOG(g_log << Logger::Notice << name << ": " << msg <<endl,
g_slog->withName(name)->info(Logr::Debug, msg));
break;
}
case RemoteLoggerInterface::Result::OtherError: {
+ const auto msg = RemoteLoggerInterface::toErrorString(ret);
const auto name = r.name();
- const auto msg = "submitting to queue failed";
SLOG(g_log << Logger::Warning << name << ": " << msg << std::endl,
g_slog->withName(name)->info(Logr::Warning, msg));
break;
#include "logging.hh"
+// Helper to be defined by main program: queue data and log based on return value of queueData()
+void remoteLoggerQueueData(RemoteLoggerInterface&, const std::string&);
+
extern std::shared_ptr<Logr::Logger> g_slogout;
class LWResException : public PDNSException
return true;
}
+const std::string& RemoteLoggerInterface::toErrorString(Result r)
+{
+ static const std::array<std::string,5> str = {
+ "Queued",
+ "Queue full, dropping",
+ "Not sending too large protobuf message",
+ "Submiting to queue failed",
+ "?"
+ };
+ auto i = static_cast<unsigned int>(r);
+ return str[std::min(i, 4U)];
+}
+
RemoteLogger::RemoteLogger(const ComboAddress& remote, uint16_t timeout, uint64_t maxQueuedBytes, uint8_t reconnectWaitTime, bool asyncConnect): d_remote(remote), d_timeout(timeout), d_reconnectWaitTime(reconnectWaitTime), d_asyncConnect(asyncConnect), d_runtime({CircularWriteBuffer(maxQueuedBytes), nullptr})
{
if (!d_asyncConnect) {
d_thread.join();
}
+
{
public:
enum class Result : uint8_t { Queued, PipeFull, TooLarge, OtherError };
+ static const std::string& toErrorString(Result r);
virtual ~RemoteLoggerInterface() {};
virtual Result queueData(const std::string& data) = 0;
virtual std::string toString() const = 0;
- virtual std::string name() const = 0;
+ virtual const std::string name() const = 0;
bool logQueries(void) const { return d_logQueries; }
bool logResponses(void) const { return d_logResponses; }
void setLogQueries(bool flag) { d_logQueries = flag; }
~RemoteLogger();
[[nodiscard]] Result queueData(const std::string& data) override;
- std::string name() const override
+ const std::string name() const override
{
return "protobuf";
}
std::thread d_thread;
};
-// Helper to be defined by main program: queue data and log based on return value of queueData()
-void remoteLoggerQueueData(RemoteLoggerInterface&, const std::string&);