From 0284dc2f73276891c1ede8f005e87a94032b4edf Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Fri, 8 Sep 2017 22:05:26 +0000 Subject: [PATCH] Made logging robust to bad messages. Fixed a bunch of bad messages. --- src/lib/logging/MsgPacking.h | 12 +++++++++++- src/lib/quickbus/core/LocalNode.cpp | 2 +- src/lib/quickbus/network/QBConnection.cpp | 2 +- src/lib/quickbus/routing/Router.cpp | 2 +- src/lib/quickbus/rpc/RPCClient.cpp | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib/logging/MsgPacking.h b/src/lib/logging/MsgPacking.h index 405bf09e6..b140b8635 100644 --- a/src/lib/logging/MsgPacking.h +++ b/src/lib/logging/MsgPacking.h @@ -10,7 +10,17 @@ namespace log { template std::string format_tuple(const char*msg_template, Tuple const &t,std::index_sequence) -{return fmt::format(msg_template,std::get(t)...);} +{ + try { + return fmt::format(msg_template,std::get(t)...); + } + catch (fmt::FormatError const &e) + { + return fmt::format("Bad log message template: '{}' Error: '{}'", + msg_template,e.what()); + } + +} template std::string unpack_msg_args(std::array const&buffer, const char*msg_template) diff --git a/src/lib/quickbus/core/LocalNode.cpp b/src/lib/quickbus/core/LocalNode.cpp index 0d95dd721..396abd81b 100644 --- a/src/lib/quickbus/core/LocalNode.cpp +++ b/src/lib/quickbus/core/LocalNode.cpp @@ -104,7 +104,7 @@ void LocalNode::subscribe (NodeID const&nid, TableID const&tid,SubscriptionID co void LocalNode::notify(NodeID const&nid,TableID const&tid,SubscriptionID const&sid, Update const&u) { - LOG(QBus,Diag,"Localnode {} received notify {} from {} for {} (sid: {})", + LOG(QBus,Diag,"Localnode {} received notify from {} for {} (sid: {})", me->my_id.value() ,nid.value(), tid.value(),sid.value()); on_notify(tid,sid,u); diff --git a/src/lib/quickbus/network/QBConnection.cpp b/src/lib/quickbus/network/QBConnection.cpp index 3a780fe6d..585dc7d17 100644 --- a/src/lib/quickbus/network/QBConnection.cpp +++ b/src/lib/quickbus/network/QBConnection.cpp @@ -123,7 +123,7 @@ void QBConnection::check_hbs() if (!is_send_in_flight() && datetime::is_at_least_msecs_old (me->last_sent_ts, me->cfg.hb_period_msecs())) { - LOG(QBus,Diag,"{0} sending HB to {}", me->my_desc ,me->remote_desc ); + LOG(QBus,Diag,"{} sending HB to {}", me->my_desc ,me->remote_desc ); me->pending_send.add_op()->mutable_heartbeat(); try_send_pending(); } diff --git a/src/lib/quickbus/routing/Router.cpp b/src/lib/quickbus/routing/Router.cpp index 8e6f865cb..dd4f3296b 100644 --- a/src/lib/quickbus/routing/Router.cpp +++ b/src/lib/quickbus/routing/Router.cpp @@ -186,7 +186,7 @@ void Router::remove_neighbour(NodeID const&removed_neighbour_id) void Router::advertise(NodeID const& sender,TableID const&tid,Advertisement const&ad) { - LOG(QBus,Diag, "{} received advertisement from nid: { tid: {} ad topic: {}", + LOG(QBus,Diag, "{} received advertisement from nid: {} tid: {} ad topic: {}", id().value() , sender.value() , tid.value() , ad.topic.value()); NoReenter nr(me->inside); diff --git a/src/lib/quickbus/rpc/RPCClient.cpp b/src/lib/quickbus/rpc/RPCClient.cpp index f6d5ad9eb..33d331f18 100644 --- a/src/lib/quickbus/rpc/RPCClient.cpp +++ b/src/lib/quickbus/rpc/RPCClient.cpp @@ -64,7 +64,7 @@ public: private: void sync_send(RPCRequestPtr const &req,OnRPCReply const&on_reply) { - LOG(QBus,Diag, "Trying to sync_send {} bytes {} to {}", + LOG(QBus,Diag, "Trying to sync_send {} bytes to {}", req->value().size() , service_name.value()); bts_assert (on_qb_thread());