face: Introduce Face-specific logging macros

Change-Id: I169065de664d4c4394ccd08673bbe1f881c4d7e0
Refs: #2450
diff --git a/daemon/face/datagram-face.hpp b/daemon/face/datagram-face.hpp
index 339831c..4fb075e 100644
--- a/daemon/face/datagram-face.hpp
+++ b/daemon/face/datagram-face.hpp
@@ -28,7 +28,6 @@
 
 #include "face.hpp"
 #include "core/global-io.hpp"
-#include "core/logger.hpp"
 
 namespace nfd {
 
@@ -51,8 +50,6 @@
                const shared_ptr<typename protocol::socket>& socket,
                bool isOnDemand);
 
-  ~DatagramFace() DECL_OVERRIDE;
-
   // from Face
   void
   sendInterest(const Interest& interest) DECL_OVERRIDE;
@@ -68,15 +65,6 @@
                   size_t nBytesReceived,
                   const boost::system::error_code& error);
 
-  /**
-   * \brief Set m_hasBeenUsedRecently to false
-   */
-  void
-  resetRecentUsage();
-
-  bool
-  hasBeenUsedRecently() const;
-
   void
   setOnDemand(bool isOnDemand);
 
@@ -99,12 +87,23 @@
   void
   closeSocket();
 
+  bool
+  hasBeenUsedRecently() const;
+
+  /**
+   * \brief Set m_hasBeenUsedRecently to false
+   */
+  void
+  resetRecentUsage();
+
 protected:
   shared_ptr<typename protocol::socket> m_socket;
-  uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
-  bool m_hasBeenUsedRecently;
 
   NFD_LOG_INCLASS_DECLARE();
+
+private:
+  uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
+  bool m_hasBeenUsedRecently;
 };
 
 
@@ -116,6 +115,8 @@
   : Face(remoteUri, localUri)
   , m_socket(socket)
 {
+  NFD_LOG_FACE_INFO("Creating face");
+
   setOnDemand(isOnDemand);
 
   m_socket->async_receive(boost::asio::buffer(m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE), 0,
@@ -123,33 +124,29 @@
 }
 
 template<class T, class U>
-inline
-DatagramFace<T, U>::~DatagramFace()
-{
-}
-
-template<class T, class U>
 inline void
 DatagramFace<T, U>::sendInterest(const Interest& interest)
 {
+  NFD_LOG_FACE_TRACE(__func__);
+
   this->emitSignal(onSendInterest, interest);
+
   const Block& payload = interest.wireEncode();
   m_socket->async_send(boost::asio::buffer(payload.wire(), payload.size()),
                        bind(&DatagramFace<T, U>::handleSend, this, _1, _2, payload));
-
-  // anything else should be done here?
 }
 
 template<class T, class U>
 inline void
 DatagramFace<T, U>::sendData(const Data& data)
 {
+  NFD_LOG_FACE_TRACE(__func__);
+
   this->emitSignal(onSendData, data);
+
   const Block& payload = data.wireEncode();
   m_socket->async_send(boost::asio::buffer(payload.wire(), payload.size()),
                        bind(&DatagramFace<T, U>::handleSend, this, _1, _2, payload));
-
-  // anything else should be done here?
 }
 
 template<class T, class U>
@@ -159,18 +156,17 @@
   if (!m_socket->is_open())
     return;
 
-  NFD_LOG_INFO("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-               << "] Closing face");
+  NFD_LOG_FACE_INFO("Closing face");
 
   closeSocket();
-  fail("Face closed");
+  this->fail("Face closed");
 }
 
 template<class T, class U>
 inline void
 DatagramFace<T, U>::processErrorCode(const boost::system::error_code& error)
 {
-  if (error == boost::asio::error::operation_aborted) // when socket is closed by someone
+  if (error == boost::asio::error::operation_aborted) // when cancel() is called
     return;
 
   // this should be unnecessary, but just in case
@@ -180,16 +176,14 @@
   }
 
   if (error != boost::asio::error::eof)
-    NFD_LOG_WARN("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                 << "] Send or receive operation failed, closing face: "
-                 << error.message());
+    NFD_LOG_FACE_WARN("Send or receive operation failed: " << error.message());
 
   closeSocket();
 
   if (error == boost::asio::error::eof)
     this->fail("Tunnel closed");
   else
-    this->fail("Send or receive operation failed: " + error.message());
+    this->fail(error.message());
 }
 
 template<class T, class U>
@@ -202,8 +196,7 @@
   if (error)
     return processErrorCode(error);
 
-  NFD_LOG_TRACE("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                << "] Successfully sent: " << nBytesSent << " bytes");
+  NFD_LOG_FACE_TRACE("Successfully sent: " << nBytesSent << " bytes");
   this->getMutableCounters().getNOutBytes() += nBytesSent;
 }
 
@@ -228,34 +221,28 @@
   if (error || nBytesReceived == 0)
     return processErrorCode(error);
 
-  NFD_LOG_TRACE("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                << "] Received: " << nBytesReceived << " bytes");
+  NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
   this->getMutableCounters().getNInBytes() += nBytesReceived;
 
   Block element;
   bool isOk = Block::fromBuffer(buffer, nBytesReceived, element);
   if (!isOk)
     {
-      NFD_LOG_WARN("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                   << "] Failed to parse incoming packet");
+      NFD_LOG_FACE_WARN("Failed to parse incoming packet");
       // This message won't extend the face lifetime
       return;
     }
 
   if (element.size() != nBytesReceived)
     {
-      NFD_LOG_WARN("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                   << "] Received datagram size and decoded "
-                   << "element size don't match");
+      NFD_LOG_FACE_WARN("Received datagram size and decoded element size don't match");
       // This message won't extend the face lifetime
       return;
     }
 
   if (!this->decodeAndDispatchInput(element))
     {
-      NFD_LOG_WARN("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                   << "] Received unrecognized block of type ["
-                   << element.type() << "]");
+      NFD_LOG_FACE_WARN("Received unrecognized TLV block of type " << element.type());
       // This message won't extend the face lifetime
       return;
     }
@@ -267,12 +254,15 @@
 inline void
 DatagramFace<T, U>::keepFaceAliveUntilAllHandlersExecuted(const shared_ptr<Face>& face)
 {
+  NFD_LOG_FACE_TRACE(__func__);
 }
 
 template<class T, class U>
 inline void
 DatagramFace<T, U>::closeSocket()
 {
+  NFD_LOG_FACE_TRACE(__func__);
+
   // use the non-throwing variants and ignore errors, if any
   boost::system::error_code error;
   m_socket->shutdown(protocol::socket::shutdown_both, error);
@@ -293,19 +283,19 @@
 }
 
 template<class T, class U>
-inline void
-DatagramFace<T, U>::resetRecentUsage()
-{
-  m_hasBeenUsedRecently = false;
-}
-
-template<class T, class U>
 inline bool
 DatagramFace<T, U>::hasBeenUsedRecently() const
 {
   return m_hasBeenUsedRecently;
 }
 
+template<class T, class U>
+inline void
+DatagramFace<T, U>::resetRecentUsage()
+{
+  m_hasBeenUsedRecently = false;
+}
+
 } // namespace nfd
 
 #endif // NFD_DAEMON_FACE_DATAGRAM_FACE_HPP
diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp
index 4994926..9ba95e0 100644
--- a/daemon/face/ethernet-face.cpp
+++ b/daemon/face/ethernet-face.cpp
@@ -25,7 +25,6 @@
 
 #include "ethernet-face.hpp"
 #include "core/global-io.hpp"
-#include "core/logger.hpp"
 
 #include <pcap/pcap.h>
 
@@ -79,8 +78,7 @@
   , m_nDropped(0)
 #endif
 {
-  NFD_LOG_INFO("Creating ethernet face on " << m_interfaceName << ": "
-               << m_srcAddress << " <--> " << m_destAddress);
+  NFD_LOG_FACE_INFO("Creating face on " << m_interfaceName << "/" << m_srcAddress);
   pcapInit();
 
   int fd = pcap_get_selectable_fd(m_pcap.get());
@@ -93,8 +91,7 @@
   m_socket->assign(::dup(fd));
 
   m_interfaceMtu = getInterfaceMtu();
-  NFD_LOG_DEBUG("[id:" << getId() << ",endpoint:" << m_interfaceName
-                << "] Interface MTU is: " << m_interfaceMtu);
+  NFD_LOG_FACE_DEBUG("Interface MTU is: " << m_interfaceMtu);
 
   m_slicer.reset(new ndnlp::Slicer(m_interfaceMtu));
 
@@ -108,8 +105,7 @@
 
   if (!m_destAddress.isBroadcast() && !joinMulticastGroup())
     {
-      NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-                   << "] Falling back to promiscuous mode");
+      NFD_LOG_FACE_WARN("Falling back to promiscuous mode");
       pcap_set_promisc(m_pcap.get(), 1);
     }
 
@@ -126,7 +122,10 @@
 void
 EthernetFace::sendInterest(const Interest& interest)
 {
+  NFD_LOG_FACE_TRACE(__func__);
+
   this->emitSignal(onSendInterest, interest);
+
   ndnlp::PacketArray pa = m_slicer->slice(interest.wireEncode());
   for (const auto& packet : *pa) {
     sendPacket(packet);
@@ -136,7 +135,10 @@
 void
 EthernetFace::sendData(const Data& data)
 {
+  NFD_LOG_FACE_TRACE(__func__);
+
   this->emitSignal(onSendData, data);
+
   ndnlp::PacketArray pa = m_slicer->slice(data.wireEncode());
   for (const auto& packet : *pa) {
     sendPacket(packet);
@@ -149,8 +151,7 @@
   if (!m_pcap)
     return;
 
-  NFD_LOG_INFO("[id:" << getId() << ",endpoint:" << m_interfaceName
-               << "] Closing face");
+  NFD_LOG_FACE_INFO("Closing face");
 
   boost::system::error_code error;
   m_socket->cancel(error); // ignore errors
@@ -184,8 +185,7 @@
 
   if (pcap_setdirection(m_pcap.get(), PCAP_D_IN) < 0)
     // no need to throw on failure, BPF will filter unwanted packets anyway
-    NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-                 << "] pcap_setdirection failed: " << pcap_geterr(m_pcap.get()));
+    NFD_LOG_FACE_WARN("pcap_setdirection failed: " << pcap_geterr(m_pcap.get()));
 }
 
 void
@@ -215,8 +215,7 @@
                    PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) == 0)
     return true; // success
 
-  NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-               << "] setsockopt(PACKET_ADD_MEMBERSHIP) failed: " << std::strerror(errno));
+  NFD_LOG_FACE_WARN("setsockopt(PACKET_ADD_MEMBERSHIP) failed: " << std::strerror(errno));
 #endif
 
 #if defined(SIOCADDMULTI)
@@ -262,8 +261,7 @@
   if (::ioctl(fd, SIOCADDMULTI, &ifr) == 0)
     return true; // success
 
-  NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-               << "] ioctl(SIOCADDMULTI) failed: " << std::strerror(errno));
+  NFD_LOG_FACE_WARN("ioctl(SIOCADDMULTI) failed: " << std::strerror(errno));
 #endif
 
   return false;
@@ -274,8 +272,7 @@
 {
   if (!m_pcap)
     {
-      NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-                   << "] Trying to send on closed face");
+      NFD_LOG_FACE_WARN("Trying to send on closed face");
       return fail("Face closed");
     }
 
@@ -309,8 +306,7 @@
       return fail("Failed to inject frame");
     }
 
-  NFD_LOG_TRACE("[id:" << getId() << ",endpoint:" << m_interfaceName
-                << "] Successfully sent: " << block.size() << " bytes");
+  NFD_LOG_FACE_TRACE("Successfully sent: " << block.size() << " bytes");
   this->getMutableCounters().getNOutBytes() += block.size();
 }
 
@@ -332,7 +328,7 @@
     }
   else if (ret == 0)
     {
-      NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName << "] Read timeout");
+      NFD_LOG_FACE_WARN("Read timeout");
     }
   else
     {
@@ -344,14 +340,12 @@
   ret = pcap_stats(m_pcap.get(), &ps);
   if (ret < 0)
     {
-      NFD_LOG_DEBUG("[id:" << getId() << ",endpoint:" << m_interfaceName
-                    << "] pcap_stats failed: " << pcap_geterr(m_pcap.get()));
+      NFD_LOG_FACE_DEBUG("pcap_stats failed: " << pcap_geterr(m_pcap.get()));
     }
   else if (ret == 0)
     {
       if (ps.ps_drop - m_nDropped > 0)
-        NFD_LOG_DEBUG("[id:" << getId() << ",endpoint:" << m_interfaceName
-                      << "] Detected " << ps.ps_drop - m_nDropped << " dropped packet(s)");
+        NFD_LOG_FACE_DEBUG("Detected " << ps.ps_drop - m_nDropped << " dropped packet(s)");
       m_nDropped = ps.ps_drop;
     }
 #endif
@@ -368,8 +362,7 @@
   size_t length = header->caplen;
   if (length < ethernet::HDR_LEN + ethernet::MIN_DATA_LEN)
     {
-      NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-                   << "] Received frame is too short (" << length << " bytes)");
+      NFD_LOG_FACE_WARN("Received frame is too short (" << length << " bytes)");
       return;
     }
 
@@ -392,15 +385,12 @@
   bool isOk = Block::fromBuffer(packet, length, fragment);
   if (!isOk)
     {
-      NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-                   << "] Block received from " << sourceAddress.toString()
-                   << " is invalid or too large to process");
+      NFD_LOG_FACE_WARN("Block received from " << sourceAddress.toString()
+                        << " is invalid or too large to process");
       return;
     }
 
-  NFD_LOG_TRACE("[id:" << getId() << ",endpoint:" << m_interfaceName
-                << "] Received: " << fragment.size() << " bytes from "
-                << sourceAddress.toString());
+  NFD_LOG_FACE_TRACE("Received: " << fragment.size() << " bytes from " << sourceAddress.toString());
   this->getMutableCounters().getNInBytes() += fragment.size();
 
   Reassembler& reassembler = m_reassemblers[sourceAddress];
@@ -410,12 +400,10 @@
       reassembler.pms.reset(new ndnlp::PartialMessageStore);
       reassembler.pms->onReceive.connect(
         [this, sourceAddress] (const Block& block) {
-          NFD_LOG_TRACE("[id:" << getId() << ",endpoint:" << m_interfaceName
-                        << "] All fragments received from " << sourceAddress.toString());
+          NFD_LOG_FACE_TRACE("All fragments received from " << sourceAddress.toString());
           if (!decodeAndDispatchInput(block))
-            NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-                         << "] Received unrecognized TLV block of type " << block.type()
-                         << " from " << sourceAddress.toString());
+            NFD_LOG_FACE_WARN("Received unrecognized TLV block of type " << block.type()
+                              << " from " << sourceAddress.toString());
         });
     }
 
@@ -429,9 +417,8 @@
     reassembler.pms->receiveNdnlpData(fragment);
   }
   catch (const ndnlp::ParseError& e) {
-    NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-                 << "] Received invalid NDNLP fragment from "
-                 << sourceAddress.toString() << " : " << e.what());
+    NFD_LOG_FACE_WARN("Received invalid NDNLP fragment from "
+                      << sourceAddress.toString() << " : " << e.what());
   }
 }
 
@@ -446,12 +433,11 @@
   if (error == boost::asio::error::eof)
     {
       msg = "Face closed";
-      NFD_LOG_DEBUG("[id:" << getId() << ",endpoint:" << m_interfaceName << "] " << msg);
     }
   else
     {
       msg = "Receive operation failed: " + error.message();
-      NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName << "] " << msg);
+      NFD_LOG_FACE_WARN(msg);
     }
   fail(msg);
 }
@@ -475,8 +461,7 @@
   if (::ioctl(fd, SIOCGIFMTU, &ifr) == 0)
     return static_cast<size_t>(ifr.ifr_mtu);
 
-  NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
-               << "] Failed to get interface MTU: " << std::strerror(errno));
+  NFD_LOG_FACE_WARN("Failed to get interface MTU: " << std::strerror(errno));
 #endif
 
   return ethernet::MAX_DATA_LEN;
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index e45fb1b..2b107a7 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -25,6 +25,8 @@
 
 #include "face.hpp"
 
+#include <ndn-cxx/management/nfd-face-event-notification.hpp>
+
 namespace nfd {
 
 Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal)
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index 2883770..142d14f 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -27,11 +27,11 @@
 #define NFD_DAEMON_FACE_FACE_HPP
 
 #include "common.hpp"
+#include "core/logger.hpp"
 #include "face-counters.hpp"
 
 #include <ndn-cxx/util/face-uri.hpp>
 #include <ndn-cxx/management/nfd-face-status.hpp>
-#include <ndn-cxx/management/nfd-face-event-notification.hpp>
 
 namespace nfd {
 
@@ -252,6 +252,39 @@
   return m_isOnDemand;
 }
 
+
+/** \defgroup FaceLogging Face logging macros
+ *
+ * These macros augment the log message with some face-specific information,
+ * such as the face ID, that are useful to distinguish which face produced the
+ * message. It is strongly recommended to use these macros instead of the
+ * generic ones for all logging inside Face subclasses.
+ * @{
+ */
+
+#define NFD_LOG_FACE(level, msg)                        \
+  NFD_LOG_##level("[id=" << this->getId() <<            \
+                  ",local=" << this->getLocalUri() <<   \
+                  ",remote=" << this->getRemoteUri() << \
+                  "] " << msg)
+
+/** \brief Log a message at TRACE level */
+#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
+
+/** \brief Log a message at DEBUG level */
+#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
+
+/** \brief Log a message at INFO level */
+#define NFD_LOG_FACE_INFO(msg)  NFD_LOG_FACE(INFO,  msg)
+
+/** \brief Log a message at WARN level */
+#define NFD_LOG_FACE_WARN(msg)  NFD_LOG_FACE(WARN,  msg)
+
+/** \brief Log a message at ERROR level */
+#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
+
+/** @} */
+
 } // namespace nfd
 
 #endif // NFD_DAEMON_FACE_FACE_HPP
diff --git a/daemon/face/multicast-udp-face.cpp b/daemon/face/multicast-udp-face.cpp
index aa1005e..9eb38c3 100644
--- a/daemon/face/multicast-udp-face.cpp
+++ b/daemon/face/multicast-udp-face.cpp
@@ -41,7 +41,7 @@
   , m_multicastGroup(multicastEndpoint)
   , m_sendSocket(sendSocket)
 {
-  NFD_LOG_INFO("Creating multicast UDP face for group " << m_multicastGroup);
+  NFD_LOG_FACE_INFO("Creating face");
 }
 
 const MulticastUdpFace::protocol::endpoint&
@@ -61,20 +61,22 @@
 void
 MulticastUdpFace::sendInterest(const Interest& interest)
 {
+  NFD_LOG_FACE_TRACE(__func__);
+
   this->emitSignal(onSendInterest, interest);
 
-  NFD_LOG_DEBUG("Sending interest");
   sendBlock(interest.wireEncode());
 }
 
 void
 MulticastUdpFace::sendData(const Data& data)
 {
-  /// \todo After this method implements duplicate suppression, onSendData signal should
-  ///       be emitted only when data is actually sent out
+  NFD_LOG_FACE_TRACE(__func__);
+
+  /// \todo After this face implements duplicate suppression, onSendData should
+  ///       be emitted only when data is actually sent out. See also #2555
   this->emitSignal(onSendData, data);
 
-  NFD_LOG_DEBUG("Sending data");
   sendBlock(data.wireEncode());
 }
 
diff --git a/daemon/face/stream-face.hpp b/daemon/face/stream-face.hpp
index 255e8ee..0383d4c 100644
--- a/daemon/face/stream-face.hpp
+++ b/daemon/face/stream-face.hpp
@@ -29,7 +29,6 @@
 #include "face.hpp"
 #include "local-face.hpp"
 #include "core/global-io.hpp"
-#include "core/logger.hpp"
 
 namespace nfd {
 
@@ -49,8 +48,6 @@
              const shared_ptr<typename protocol::socket>& socket,
              bool isOnDemand);
 
-  ~StreamFace() DECL_OVERRIDE;
-
   // from FaceBase
   void
   sendInterest(const Interest& interest) DECL_OVERRIDE;
@@ -85,6 +82,8 @@
 protected:
   shared_ptr<typename protocol::socket> m_socket;
 
+  NFD_LOG_INCLASS_DECLARE();
+
 private:
   uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
   size_t m_inputBufferSize;
@@ -92,8 +91,6 @@
 
   friend struct StreamFaceSenderImpl<Protocol, FaceBase, Interest>;
   friend struct StreamFaceSenderImpl<Protocol, FaceBase, Data>;
-
-  NFD_LOG_INCLASS_DECLARE();
 };
 
 // All inherited classes must use
@@ -111,7 +108,7 @@
 struct StreamFaceValidator
 {
   static void
-  validateSocket(typename Protocol::socket& socket)
+  validateSocket(const typename Protocol::socket& socket)
   {
   }
 };
@@ -126,18 +123,15 @@
   , m_socket(socket)
   , m_inputBufferSize(0)
 {
+  NFD_LOG_FACE_INFO("Creating face");
+
   FaceBase::setOnDemand(isOnDemand);
   StreamFaceValidator<T, FaceBase>::validateSocket(*socket);
+
   m_socket->async_receive(boost::asio::buffer(m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE), 0,
                           bind(&StreamFace<T, FaceBase>::handleReceive, this, _1, _2));
 }
 
-template<class T, class U>
-inline
-StreamFace<T, U>::~StreamFace()
-{
-}
-
 
 template<class Protocol, class FaceBase, class Packet>
 struct StreamFaceSenderImpl
@@ -178,6 +172,7 @@
 inline void
 StreamFace<T, U>::sendInterest(const Interest& interest)
 {
+  NFD_LOG_FACE_TRACE(__func__);
   this->emitSignal(onSendInterest, interest);
   StreamFaceSenderImpl<T, U, Interest>::send(*this, interest);
 }
@@ -186,6 +181,7 @@
 inline void
 StreamFace<T, U>::sendData(const Data& data)
 {
+  NFD_LOG_FACE_TRACE(__func__);
   this->emitSignal(onSendData, data);
   StreamFaceSenderImpl<T, U, Data>::send(*this, data);
 }
@@ -197,8 +193,7 @@
   if (!m_socket->is_open())
     return;
 
-  NFD_LOG_INFO("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-               << "] Closing face");
+  NFD_LOG_FACE_INFO("Closing face");
 
   shutdownSocket();
   this->fail("Face closed");
@@ -219,20 +214,14 @@
     }
 
   if (error != boost::asio::error::eof)
-    NFD_LOG_WARN("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                 << "] Send or receive operation failed, closing face: "
-                 << error.message());
+    NFD_LOG_FACE_WARN("Send or receive operation failed: " << error.message());
 
   shutdownSocket();
 
   if (error == boost::asio::error::eof)
-    {
-      this->fail("Connection closed");
-    }
+    this->fail("Connection closed");
   else
-    {
-      this->fail("Send or receive operation failed: " + error.message());
-    }
+    this->fail(error.message());
 }
 
 template<class T, class U>
@@ -254,8 +243,7 @@
 
   BOOST_ASSERT(!m_sendQueue.empty());
 
-  NFD_LOG_TRACE("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                << "] Successfully sent: " << nBytesSent << " bytes");
+  NFD_LOG_FACE_TRACE("Successfully sent: " << nBytesSent << " bytes");
   this->getMutableCounters().getNOutBytes() += nBytesSent;
 
   m_sendQueue.pop();
@@ -271,8 +259,7 @@
   if (error)
     return processErrorCode(error);
 
-  NFD_LOG_TRACE("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                << "] Received: " << nBytesReceived << " bytes");
+  NFD_LOG_FACE_TRACE("Received: " << nBytesReceived << " bytes");
   this->getMutableCounters().getNInBytes() += nBytesReceived;
 
   m_inputBufferSize += nBytesReceived;
@@ -293,17 +280,13 @@
 
       if (!this->decodeAndDispatchInput(element))
         {
-          NFD_LOG_WARN("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                       << "] Received unrecognized block of type ["
-                       << element.type() << "]");
+          NFD_LOG_FACE_WARN("Received unrecognized TLV block of type " << element.type());
           // ignore unknown packet and proceed
         }
     }
   if (!isOk && m_inputBufferSize == ndn::MAX_NDN_PACKET_SIZE && offset == 0)
     {
-      NFD_LOG_WARN("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                   << "] Failed to parse incoming packet or packet too large to process, "
-                   << "closing face");
+      NFD_LOG_FACE_WARN("Failed to parse incoming packet or packet too large to process");
       shutdownSocket();
       this->fail("Failed to parse incoming packet or packet too large to process");
       return;
@@ -332,6 +315,8 @@
 inline void
 StreamFace<T, U>::shutdownSocket()
 {
+  NFD_LOG_FACE_TRACE(__func__);
+
   // Cancel all outstanding operations and shutdown the socket
   // so that no further sends or receives are possible.
   // Use the non-throwing variants and ignore errors, if any.
@@ -361,8 +346,7 @@
 inline void
 StreamFace<T, U>::deferredClose(const shared_ptr<Face>& face)
 {
-  NFD_LOG_DEBUG("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                << "] Clearing send queue");
+  NFD_LOG_FACE_TRACE(__func__);
 
   // clear send queue
   std::queue<Block> emptyQueue;
diff --git a/daemon/face/tcp-face.hpp b/daemon/face/tcp-face.hpp
index 3eddde1..e4427de 100644
--- a/daemon/face/tcp-face.hpp
+++ b/daemon/face/tcp-face.hpp
@@ -40,7 +40,6 @@
           bool isOnDemand);
 };
 
-//
 
 /**
  * \brief Implementation of Face abstraction that uses TCP
@@ -58,19 +57,19 @@
 /** \brief Class validating use of TcpLocalFace
  */
 template<>
-struct StreamFaceValidator<boost::asio::ip::tcp, LocalFace>
+struct StreamFaceValidator<TcpLocalFace::protocol, LocalFace>
 {
   /** Check that local endpoint is loopback
    *
    *  @throws Face::Error if validation failed
    */
   static void
-  validateSocket(boost::asio::ip::tcp::socket& socket)
+  validateSocket(const TcpLocalFace::protocol::socket& socket)
   {
     if (!socket.local_endpoint().address().is_loopback() ||
         !socket.remote_endpoint().address().is_loopback())
       {
-        throw Face::Error("TcpLocalFace can be created only on loopback interface");
+        throw Face::Error("TcpLocalFace can be created only on a loopback address");
       }
   }
 };
diff --git a/daemon/face/udp-face.cpp b/daemon/face/udp-face.cpp
index 53dc374..8962f0d 100644
--- a/daemon/face/udp-face.cpp
+++ b/daemon/face/udp-face.cpp
@@ -63,8 +63,7 @@
   if (::setsockopt(socket->native_handle(), IPPROTO_IP,
                    IP_MTU_DISCOVER, &value, sizeof(value)) < 0)
     {
-      NFD_LOG_WARN("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                   << "] Failed to disable path MTU discovery: " << std::strerror(errno));
+      NFD_LOG_FACE_WARN("Failed to disable path MTU discovery: " << std::strerror(errno));
     }
 #endif
 
@@ -108,14 +107,13 @@
   // (non-on-demand -> on-demand transition is not allowed)
   if (isOnDemand()) {
     if (!hasBeenUsedRecently()) {
-      NFD_LOG_INFO("[id:" << this->getId() << ",uri:" << this->getRemoteUri()
-                   << "] Idle for more than " << m_idleTimeout << ", closing");
+      NFD_LOG_FACE_INFO("Closing for inactivity");
       close();
 
       // #1718 manual test: uncomment, run NFD in valgrind, send in a UDP packet
       //                    expect read-after-free error and crash
       // getGlobalIoService().post([this] {
-      //   NFD_LOG_ERROR("Remaining references: " << this->shared_from_this().use_count());
+      //   NFD_LOG_FACE_ERROR("Remaining references: " << this->shared_from_this().use_count());
       // });
     }
     else {
diff --git a/daemon/face/udp-face.hpp b/daemon/face/udp-face.hpp
index 829b3bc..f6c3183 100644
--- a/daemon/face/udp-face.hpp
+++ b/daemon/face/udp-face.hpp
@@ -52,9 +52,9 @@
   closeIfIdle();
 
 private:
-  scheduler::EventId m_closeIfIdleEvent;
-  time::seconds m_idleTimeout;
+  const time::seconds m_idleTimeout;
   time::steady_clock::TimePoint m_lastIdleCheck;
+  scheduler::EventId m_closeIfIdleEvent;
 };
 
 } // namespace nfd
diff --git a/daemon/face/unix-stream-face.cpp b/daemon/face/unix-stream-face.cpp
index 93ff30e..60b2236 100644
--- a/daemon/face/unix-stream-face.cpp
+++ b/daemon/face/unix-stream-face.cpp
@@ -33,14 +33,15 @@
                                                 UnixStreamFace::protocol, LocalFace,
                                                 "UnixStreamFace");
 
-BOOST_STATIC_ASSERT((boost::is_same<UnixStreamFace::protocol::socket::native_handle_type,
-                     int>::value));
-
 UnixStreamFace::UnixStreamFace(const shared_ptr<UnixStreamFace::protocol::socket>& socket)
   : StreamFace<protocol, LocalFace>(FaceUri::fromFd(socket->native_handle()),
                                     FaceUri(socket->local_endpoint()),
                                     socket, true)
 {
+  static_assert(
+    std::is_same<std::remove_cv<protocol::socket::native_handle_type>::type, int>::value,
+    "The native handle type for UnixStreamFace sockets must be 'int'"
+  );
 }
 
 } // namespace nfd
diff --git a/daemon/face/websocket-face.cpp b/daemon/face/websocket-face.cpp
index 4875f6c..27a8f57 100644
--- a/daemon/face/websocket-face.cpp
+++ b/daemon/face/websocket-face.cpp
@@ -37,6 +37,7 @@
   , m_server(server)
   , m_closed(false)
 {
+  NFD_LOG_FACE_INFO("Creating face");
   this->setOnDemand(true);
 }
 
@@ -46,6 +47,8 @@
   if (m_closed)
     return;
 
+  NFD_LOG_FACE_TRACE(__func__);
+
   this->emitSignal(onSendInterest, interest);
 
   const Block& payload = interest.wireEncode();
@@ -56,7 +59,7 @@
                   websocketpp::frame::opcode::binary);
   }
   catch (const websocketpp::lib::error_code& e) {
-    NFD_LOG_WARN("Failed to send Interest: " << e << " (" << e.message() << ")");
+    NFD_LOG_FACE_WARN("Failed to send Interest: " << e << " (" << e.message() << ")");
   }
 }
 
@@ -66,6 +69,8 @@
   if (m_closed)
     return;
 
+  NFD_LOG_FACE_TRACE(__func__);
+
   this->emitSignal(onSendData, data);
 
   const Block& payload = data.wireEncode();
@@ -76,22 +81,24 @@
                   websocketpp::frame::opcode::binary);
   }
   catch (const websocketpp::lib::error_code& e) {
-    NFD_LOG_WARN("Failed to send Data: " << e << " (" << e.message() << ")");
+    NFD_LOG_FACE_WARN("Failed to send Data: " << e << " (" << e.message() << ")");
   }
 }
 
 void
 WebSocketFace::close()
 {
-  if (m_closed == false)
-    {
-      m_closed = true;
-      scheduler::cancel(m_pingEventId);
-      websocketpp::lib::error_code ecode;
-      m_server.close(m_handle, websocketpp::close::status::normal, "closed by nfd", ecode);
+  if (m_closed)
+    return;
 
-      fail("Face closed");
-    }
+  NFD_LOG_FACE_INFO("Closing face");
+
+  m_closed = true;
+  scheduler::cancel(m_pingEventId);
+  websocketpp::lib::error_code ecode;
+  m_server.close(m_handle, websocketpp::close::status::normal, "closed by nfd", ecode);
+
+  fail("Face closed");
 }
 
 void
@@ -100,13 +107,11 @@
   // Copy message into Face internal buffer
   if (msg.size() > ndn::MAX_NDN_PACKET_SIZE)
     {
-      NFD_LOG_WARN("[id:" << this->getId()
-                   << "] Received WebSocket message is too big (" << msg.size() << " bytes)");
+      NFD_LOG_FACE_WARN("Received WebSocket message is too big (" << msg.size() << " bytes)");
       return;
     }
 
-  NFD_LOG_TRACE("[id:" << this->getId()
-                << "] Received: " << msg.size() << " bytes");
+  NFD_LOG_FACE_TRACE("Received: " << msg.size() << " bytes");
   this->getMutableCounters().getNInBytes() += msg.size();
 
   // Try to parse message data
@@ -115,15 +120,13 @@
                                 msg.size(), element);
   if (!isOk)
     {
-      NFD_LOG_WARN("[id:" << this->getId()
-                   << "] Received block is invalid or too large to process");
+      NFD_LOG_FACE_WARN("Received block is invalid or too large to process");
       return;
     }
 
   if (!this->decodeAndDispatchInput(element))
     {
-      NFD_LOG_WARN("[id:" << this->getId()
-                   << "] Received unrecognized TLV block of type " << element.type());
+      NFD_LOG_FACE_WARN("Received unrecognized TLV block of type " << element.type());
       // ignore unknown packet and proceed
     }
 }
diff --git a/daemon/face/websocket-face.hpp b/daemon/face/websocket-face.hpp
index 711699b..7838572 100644
--- a/daemon/face/websocket-face.hpp
+++ b/daemon/face/websocket-face.hpp
@@ -27,7 +27,6 @@
 #define NFD_DAEMON_FACE_WEBSOCKET_FACE_HPP
 
 #include "face.hpp"
-#include "core/logger.hpp"
 #include "core/scheduler.hpp"
 
 #ifndef HAVE_WEBSOCKET