From 09d3754319cf67aea22595823ffbcb65b7b09165 Mon Sep 17 00:00:00 2001
From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Date: Mon, 17 Feb 2025 17:27:14 +0200
Subject: [PATCH] libp2p: Enhance logging targets for granular control  (#7494)

This PR modifies the libp2p networking-specific log targets for granular
control (e.g., just enabling trace for req-resp).

Previously, all logs were outputted to `sub-libp2p` target, flooding the
log messages on busy validators.

### Changes
- Discover: `sub-libp2p::discovery`
- Notification/behaviour: `sub-libp2p::notification::behaviour`
- Notification/handler: `sub-libp2p::notification::handler`
- Notification/service: `sub-libp2p::notification::service`
- Notification/upgrade: `sub-libp2p::notification::upgrade`
- Request response: `sub-libp2p::request-response`

cc @paritytech/networking

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Dmitry Markin <dmitry@markin.tech>
---
 prdoc/pr_7494.prdoc                           |  18 ++
 substrate/client/network/src/discovery.rs     |  65 ++---
 .../src/protocol/notifications/behaviour.rs   | 244 +++++++++---------
 .../src/protocol/notifications/handler.rs     |  11 +-
 .../src/protocol/notifications/service/mod.rs |   2 +-
 .../notifications/upgrade/notifications.rs    |   9 +-
 .../client/network/src/request_responses.rs   |  37 +--
 substrate/client/network/src/service.rs       |  59 +++--
 8 files changed, 239 insertions(+), 206 deletions(-)
 create mode 100644 prdoc/pr_7494.prdoc

diff --git a/prdoc/pr_7494.prdoc b/prdoc/pr_7494.prdoc
new file mode 100644
index 00000000000..b0e1ec02665
--- /dev/null
+++ b/prdoc/pr_7494.prdoc
@@ -0,0 +1,18 @@
+title: Enhance libp2p logging targets for granular control
+
+doc:
+  - audience: [Node Dev, Node Operator]
+    description: |
+      This PR modifies the libp2p networking-specific log targets for granular control (e.g., just enabling trace for req-resp).
+
+      Previously, all logs were outputted to `sub-libp2p` target, flooding the log messages on busy validators.
+        - Discovery: `sub-libp2p::discovery`;
+        - Notification/behaviour: `sub-libp2p::notification::behaviour`;
+        - Notification/handler: `sub-libp2p::notification::handler`;
+        - Notification/service: `sub-libp2p::notification::service`;
+        - Notification/upgrade: `sub-libp2p::notification::upgrade`;
+        - Request response: `sub-libp2p::request-response`.
+
+crates:
+  - name: sc-network
+    bump: patch
diff --git a/substrate/client/network/src/discovery.rs b/substrate/client/network/src/discovery.rs
index 917449cf228..6b958de8691 100644
--- a/substrate/client/network/src/discovery.rs
+++ b/substrate/client/network/src/discovery.rs
@@ -84,6 +84,9 @@ use std::{
 	time::{Duration, Instant},
 };
 
+/// Logging target for the file.
+const LOG_TARGET: &str = "sub-libp2p::discovery";
+
 /// Maximum number of known external addresses that we will cache.
 /// This only affects whether we will log whenever we (re-)discover
 /// a given address.
@@ -262,7 +265,7 @@ impl DiscoveryConfig {
 				match TokioMdns::new(mdns::Config::default(), local_peer_id) {
 					Ok(mdns) => Toggle::from(Some(mdns)),
 					Err(err) => {
-						warn!(target: "sub-libp2p", "Failed to initialize mDNS: {:?}", err);
+						warn!(target: LOG_TARGET, "Failed to initialize mDNS: {:?}", err);
 						Toggle::from(None)
 					},
 				}
@@ -375,7 +378,7 @@ impl DiscoveryBehaviour {
 		if let Some(kademlia) = self.kademlia.as_mut() {
 			if !self.allow_non_globals_in_dht && !Self::can_add_to_dht(&addr) {
 				trace!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"Ignoring self-reported non-global address {} from {}.", addr, peer_id
 				);
 				return
@@ -393,7 +396,7 @@ impl DiscoveryBehaviour {
 					.expect("kademlia protocol was checked above to be enabled; qed")
 			}) {
 				trace!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"Ignoring self-reported address {} from {} as remote node is not part of the \
 					 Kademlia DHT supported by the local node.", addr, peer_id,
 				);
@@ -401,7 +404,7 @@ impl DiscoveryBehaviour {
 			}
 
 			trace!(
-				target: "sub-libp2p",
+				target: LOG_TARGET,
 				"Adding self-reported address {} from {} to Kademlia DHT.",
 				addr, peer_id
 			);
@@ -425,7 +428,7 @@ impl DiscoveryBehaviour {
 	pub fn put_value(&mut self, key: RecordKey, value: Vec<u8>) {
 		if let Some(k) = self.kademlia.as_mut() {
 			if let Err(e) = k.put_record(Record::new(key.clone(), value.clone()), Quorum::All) {
-				warn!(target: "sub-libp2p", "Libp2p => Failed to put record: {:?}", e);
+				warn!(target: LOG_TARGET, "Libp2p => Failed to put record: {:?}", e);
 				self.pending_events
 					.push_back(DiscoveryOut::ValuePutFailed(key.clone(), Duration::from_secs(0)));
 			}
@@ -444,7 +447,7 @@ impl DiscoveryBehaviour {
 		if let Some(kad) = self.kademlia.as_mut() {
 			if update_local_storage {
 				if let Err(_e) = kad.store_mut().put(record.clone()) {
-					warn!(target: "sub-libp2p", "Failed to update local starage");
+					warn!(target: LOG_TARGET, "Failed to update local starage");
 				}
 			}
 
@@ -462,7 +465,7 @@ impl DiscoveryBehaviour {
 	pub fn start_providing(&mut self, key: RecordKey) {
 		if let Some(kad) = self.kademlia.as_mut() {
 			if let Err(e) = kad.start_providing(key.clone()) {
-				warn!(target: "sub-libp2p", "Libp2p => Failed to start providing {key:?}: {e}.");
+				warn!(target: LOG_TARGET, "Libp2p => Failed to start providing {key:?}: {e}.");
 				self.pending_events.push_back(DiscoveryOut::StartProvidingFailed(key));
 			}
 		}
@@ -498,7 +501,7 @@ impl DiscoveryBehaviour {
 				expires,
 			}) {
 				debug!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"Failed to store record with key: {:?}",
 					err
 				);
@@ -712,7 +715,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 			});
 		}
 
-		trace!(target: "sub-libp2p", "Addresses of {:?}: {:?}", peer_id, list);
+		trace!(target: LOG_TARGET, "Addresses of {:?}: {:?}", peer_id, list);
 
 		Ok(list.into_iter().collect())
 	}
@@ -781,7 +784,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 				if let Some(Protocol::P2p(peer_id)) = addr.iter().last() {
 					if peer_id != self.local_peer_id {
 						warn!(
-							target: "sub-libp2p",
+							target: LOG_TARGET,
 							"🔍 Discovered external address for a peer that is not us: {addr}",
 						);
 						// Ensure this address is not propagated to kademlia.
@@ -796,7 +799,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 					// in which case we just want to refrain from logging.
 					if self.known_external_addresses.insert(address.clone()) {
 						info!(
-						  target: "sub-libp2p",
+						  target: LOG_TARGET,
 						  "🔍 Discovered new external address for our node: {address}",
 						);
 					}
@@ -805,7 +808,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 				self.kademlia.on_swarm_event(FromSwarm::ExternalAddrConfirmed(e));
 			},
 			event => {
-				debug!(target: "sub-libp2p", "New unknown `FromSwarm` libp2p event: {event:?}");
+				debug!(target: LOG_TARGET, "New unknown `FromSwarm` libp2p event: {event:?}");
 				self.kademlia.on_swarm_event(event);
 			},
 		}
@@ -834,7 +837,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 						if self.num_connections < self.discovery_only_if_under_num {
 							let random_peer_id = PeerId::random();
 							debug!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"Libp2p <= Starting random Kademlia request for {:?}",
 								random_peer_id,
 							);
@@ -842,7 +845,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 							true
 						} else {
 							debug!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"Kademlia paused due to high number of connections ({})",
 								self.num_connections
 							);
@@ -899,20 +902,20 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 					} => match res {
 						Err(GetClosestPeersError::Timeout { key, peers }) => {
 							debug!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"Libp2p => Query for {:?} timed out with {} results",
 								HexDisplay::from(&key), peers.len(),
 							);
 						},
 						Ok(ok) => {
 							trace!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"Libp2p => Query for {:?} yielded {:?} results",
 								HexDisplay::from(&ok.key), ok.peers.len(),
 							);
 							if ok.peers.is_empty() && self.num_connections != 0 {
 								debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Random Kademlia query has yielded empty results",
 								);
 							}
@@ -927,7 +930,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 						let ev = match res {
 							Ok(GetRecordOk::FoundRecord(r)) => {
 								debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Found record ({:?}) with value: {:?} id {:?} stats {:?}",
 									r.record.key,
 									r.record.value,
@@ -959,7 +962,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 								cache_candidates,
 							}) => {
 								debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Finished with no-additional-record {:?} stats {:?} took {:?} ms",
 									id,
 									stats,
@@ -986,7 +989,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 							},
 							Err(e @ libp2p::kad::GetRecordError::NotFound { .. }) => {
 								trace!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Failed to get record: {:?}",
 									e,
 								);
@@ -997,7 +1000,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 							},
 							Err(e) => {
 								debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Failed to get record: {:?}",
 									e,
 								);
@@ -1018,7 +1021,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 						let ev = match res {
 							Ok(GetProvidersOk::FoundProviders { key, providers }) => {
 								debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Found providers {:?} for key {:?}, id {:?}, stats {:?}",
 									providers,
 									key,
@@ -1036,7 +1039,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 								closest_peers: _,
 							}) => {
 								debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Finished with no additional providers {:?}, stats {:?}, took {:?} ms",
 									id,
 									stats,
@@ -1047,7 +1050,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 							},
 							Err(GetProvidersError::Timeout { key, closest_peers: _ }) => {
 								debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Failed to get providers for {key:?} due to timeout.",
 								);
 
@@ -1069,7 +1072,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 								DiscoveryOut::ValuePut(ok.key, stats.duration().unwrap_or_default()),
 							Err(e) => {
 								debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Libp2p => Failed to put record: {:?}",
 									e,
 								);
@@ -1086,12 +1089,12 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 						..
 					} => match res {
 						Ok(ok) => debug!(
-							target: "sub-libp2p",
+							target: LOG_TARGET,
 							"Libp2p => Record republished: {:?}",
 							ok.key,
 						),
 						Err(e) => debug!(
-							target: "sub-libp2p",
+							target: LOG_TARGET,
 							"Libp2p => Republishing of record {:?} failed with: {:?}",
 							e.key(), e,
 						),
@@ -1101,20 +1104,20 @@ impl NetworkBehaviour for DiscoveryBehaviour {
 						..
 					} => match res {
 						Ok(ok) => debug!(
-							target: "sub-libp2p",
+							target: LOG_TARGET,
 							"Libp2p => DHT bootstrap progressed: {ok:?}",
 						),
 						Err(e) => warn!(
-							target: "sub-libp2p",
+							target: LOG_TARGET,
 							"Libp2p => DHT bootstrap error: {e:?}",
 						),
 					},
 					// We never start any other type of query.
 					KademliaEvent::OutboundQueryProgressed { result: e, .. } => {
-						warn!(target: "sub-libp2p", "Libp2p => Unhandled Kademlia event: {:?}", e)
+						warn!(target: LOG_TARGET, "Libp2p => Unhandled Kademlia event: {:?}", e)
 					},
 					Event::ModeChanged { new_mode } => {
-						debug!(target: "sub-libp2p", "Libp2p => Kademlia mode changed: {new_mode}")
+						debug!(target: LOG_TARGET, "Libp2p => Kademlia mode changed: {new_mode}")
 					},
 				},
 				ToSwarm::Dial { opts } => return Poll::Ready(ToSwarm::Dial { opts }),
diff --git a/substrate/client/network/src/protocol/notifications/behaviour.rs b/substrate/client/network/src/protocol/notifications/behaviour.rs
index e6909fcdefe..217ef304bd0 100644
--- a/substrate/client/network/src/protocol/notifications/behaviour.rs
+++ b/substrate/client/network/src/protocol/notifications/behaviour.rs
@@ -60,13 +60,13 @@ use std::{
 	time::{Duration, Instant},
 };
 
+/// Logging target for the file.
+const LOG_TARGET: &str = "sub-libp2p::notification::behaviour";
+
 /// Type representing a pending substream validation.
 type PendingInboundValidation =
 	BoxFuture<'static, (Result<ValidationResult, RecvError>, IncomingIndex)>;
 
-/// Logging target for the file.
-const LOG_TARGET: &str = "sub-libp2p";
-
 /// Network behaviour that handles opening substreams for custom protocols with other peers.
 ///
 /// # How it works
@@ -470,7 +470,7 @@ impl Notifications {
 		if let Some(p) = self.notif_protocols.get_mut(usize::from(set_id)) {
 			*p.handshake.write() = handshake_message.into();
 		} else {
-			log::error!(target: "sub-libp2p", "Unknown handshake change set: {:?}", set_id);
+			log::error!(target: LOG_TARGET, "Unknown handshake change set: {:?}", set_id);
 			debug_assert!(false);
 		}
 	}
@@ -487,7 +487,7 @@ impl Notifications {
 
 	/// Disconnects the given peer if we are connected to it.
 	pub fn disconnect_peer(&mut self, peer_id: &PeerId, set_id: SetId) {
-		trace!(target: "sub-libp2p", "External API => Disconnect({}, {:?})", peer_id, set_id);
+		trace!(target: LOG_TARGET, "External API => Disconnect({}, {:?})", peer_id, set_id);
 		self.disconnect_peer_inner(peer_id, set_id);
 	}
 
@@ -508,7 +508,7 @@ impl Notifications {
 
 			// DisabledPendingEnable => Disabled.
 			PeerState::DisabledPendingEnable { connections, timer_deadline, timer: _ } => {
-				trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id);
+				trace!(target: LOG_TARGET, "PSM <= Dropped({}, {:?})", peer_id, set_id);
 				self.protocol_controller_handles[usize::from(set_id)].dropped(*peer_id);
 				*entry.into_mut() =
 					PeerState::Disabled { connections, backoff_until: Some(timer_deadline) }
@@ -518,11 +518,11 @@ impl Notifications {
 			// All open or opening connections are sent a `Close` message.
 			// If relevant, the external API is instantly notified.
 			PeerState::Enabled { mut connections } => {
-				trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id);
+				trace!(target: LOG_TARGET, "PSM <= Dropped({}, {:?})", peer_id, set_id);
 				self.protocol_controller_handles[usize::from(set_id)].dropped(*peer_id);
 
 				if connections.iter().any(|(_, s)| matches!(s, ConnectionState::Open(_))) {
-					trace!(target: "sub-libp2p", "External API <= Closed({}, {:?})", peer_id, set_id);
+					trace!(target: LOG_TARGET, "External API <= Closed({}, {:?})", peer_id, set_id);
 					let event =
 						NotificationsOut::CustomProtocolClosed { peer_id: *peer_id, set_id };
 					self.events.push_back(ToSwarm::GenerateEvent(event));
@@ -531,7 +531,7 @@ impl Notifications {
 				for (connec_id, connec_state) in
 					connections.iter_mut().filter(|(_, s)| matches!(s, ConnectionState::Open(_)))
 				{
-					trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Close({:?})", peer_id, *connec_id, set_id);
+					trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Close({:?})", peer_id, *connec_id, set_id);
 					self.events.push_back(ToSwarm::NotifyHandler {
 						peer_id: *peer_id,
 						handler: NotifyHandler::One(*connec_id),
@@ -543,7 +543,7 @@ impl Notifications {
 				for (connec_id, connec_state) in
 					connections.iter_mut().filter(|(_, s)| matches!(s, ConnectionState::Opening))
 				{
-					trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Close({:?})", peer_id, *connec_id, set_id);
+					trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Close({:?})", peer_id, *connec_id, set_id);
 					self.events.push_back(ToSwarm::NotifyHandler {
 						peer_id: *peer_id,
 						handler: NotifyHandler::One(*connec_id),
@@ -573,7 +573,7 @@ impl Notifications {
 					inc
 				} else {
 					error!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"State mismatch in libp2p: no entry in incoming for incoming peer"
 					);
 					return
@@ -585,7 +585,7 @@ impl Notifications {
 					.iter_mut()
 					.filter(|(_, s)| matches!(s, ConnectionState::OpenDesiredByRemote))
 				{
-					trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Close({:?})", peer_id, *connec_id, set_id);
+					trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Close({:?})", peer_id, *connec_id, set_id);
 					self.events.push_back(ToSwarm::NotifyHandler {
 						peer_id: *peer_id,
 						handler: NotifyHandler::One(*connec_id),
@@ -601,7 +601,7 @@ impl Notifications {
 			},
 
 			PeerState::Poisoned => {
-				error!(target: "sub-libp2p", "State of {:?} is poisoned", peer_id)
+				error!(target: LOG_TARGET, "State of {:?} is poisoned", peer_id)
 			},
 		}
 	}
@@ -614,12 +614,12 @@ impl Notifications {
 			Entry::Vacant(entry) => {
 				// If there's no entry in `self.peers`, start dialing.
 				trace!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"PSM => Connect({}, {:?}): Starting to connect",
 					entry.key().0,
 					set_id,
 				);
-				trace!(target: "sub-libp2p", "Libp2p <= Dial {}", entry.key().0);
+				trace!(target: LOG_TARGET, "Libp2p <= Dial {}", entry.key().0);
 				self.events.push_back(ToSwarm::Dial { opts: entry.key().0.into() });
 				entry.insert(PeerState::Requested);
 				return
@@ -633,7 +633,7 @@ impl Notifications {
 			PeerState::Backoff { ref timer, ref timer_deadline } if *timer_deadline > now => {
 				let peer_id = occ_entry.key().0;
 				trace!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"PSM => Connect({}, {:?}): Will start to connect at until {:?}",
 					peer_id,
 					set_id,
@@ -646,12 +646,12 @@ impl Notifications {
 			// Backoff (expired) => Requested
 			PeerState::Backoff { .. } => {
 				trace!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"PSM => Connect({}, {:?}): Starting to connect",
 					occ_entry.key().0,
 					set_id,
 				);
-				trace!(target: "sub-libp2p", "Libp2p <= Dial {:?}", occ_entry.key());
+				trace!(target: LOG_TARGET, "Libp2p <= Dial {:?}", occ_entry.key());
 				self.events.push_back(ToSwarm::Dial { opts: occ_entry.key().0.into() });
 				*occ_entry.into_mut() = PeerState::Requested;
 			},
@@ -662,7 +662,7 @@ impl Notifications {
 			{
 				let peer_id = occ_entry.key().0;
 				trace!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"PSM => Connect({}, {:?}): But peer is backed-off until {:?}",
 					peer_id,
 					set_id,
@@ -697,9 +697,9 @@ impl Notifications {
 				if let Some((connec_id, connec_state)) =
 					connections.iter_mut().find(|(_, s)| matches!(s, ConnectionState::Closed))
 				{
-					trace!(target: "sub-libp2p", "PSM => Connect({}, {:?}): Enabling connections.",
+					trace!(target: LOG_TARGET, "PSM => Connect({}, {:?}): Enabling connections.",
 						occ_entry.key().0, set_id);
-					trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Open({:?})", peer_id, *connec_id, set_id);
+					trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Open({:?})", peer_id, *connec_id, set_id);
 					self.events.push_back(ToSwarm::NotifyHandler {
 						peer_id,
 						handler: NotifyHandler::One(*connec_id),
@@ -714,7 +714,7 @@ impl Notifications {
 						matches!(s, ConnectionState::OpeningThenClosing | ConnectionState::Closing)
 					}));
 					trace!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"PSM => Connect({}, {:?}): No connection in proper state. Delaying.",
 						occ_entry.key().0, set_id
 					);
@@ -750,7 +750,7 @@ impl Notifications {
 			// Incoming => Incoming
 			st @ PeerState::Incoming { .. } => {
 				debug!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"PSM => Connect({}, {:?}): Ignoring obsolete connect, we are awaiting accept/reject.",
 					occ_entry.key().0, set_id
 				);
@@ -759,26 +759,26 @@ impl Notifications {
 
 			// Other states are kept as-is.
 			st @ PeerState::Enabled { .. } => {
-				debug!(target: "sub-libp2p",
+				debug!(target: LOG_TARGET,
 					"PSM => Connect({}, {:?}): Already connected.",
 					occ_entry.key().0, set_id);
 				*occ_entry.into_mut() = st;
 			},
 			st @ PeerState::DisabledPendingEnable { .. } => {
-				debug!(target: "sub-libp2p",
+				debug!(target: LOG_TARGET,
 					"PSM => Connect({}, {:?}): Already pending enabling.",
 					occ_entry.key().0, set_id);
 				*occ_entry.into_mut() = st;
 			},
 			st @ PeerState::Requested { .. } | st @ PeerState::PendingRequest { .. } => {
-				debug!(target: "sub-libp2p",
+				debug!(target: LOG_TARGET,
 					"PSM => Connect({}, {:?}): Duplicate request.",
 					occ_entry.key().0, set_id);
 				*occ_entry.into_mut() = st;
 			},
 
 			PeerState::Poisoned => {
-				error!(target: "sub-libp2p", "State of {:?} is poisoned", occ_entry.key());
+				error!(target: LOG_TARGET, "State of {:?} is poisoned", occ_entry.key());
 				debug_assert!(false);
 			},
 		}
@@ -789,7 +789,7 @@ impl Notifications {
 		let mut entry = match self.peers.entry((peer_id, set_id)) {
 			Entry::Occupied(entry) => entry,
 			Entry::Vacant(entry) => {
-				trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Already disabled.",
+				trace!(target: LOG_TARGET, "PSM => Drop({}, {:?}): Already disabled.",
 					entry.key().0, set_id);
 				return
 			},
@@ -797,7 +797,7 @@ impl Notifications {
 
 		match mem::replace(entry.get_mut(), PeerState::Poisoned) {
 			st @ PeerState::Disabled { .. } | st @ PeerState::Backoff { .. } => {
-				trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Already disabled.",
+				trace!(target: LOG_TARGET, "PSM => Drop({}, {:?}): Already disabled.",
 					entry.key().0, set_id);
 				*entry.into_mut() = st;
 			},
@@ -805,7 +805,7 @@ impl Notifications {
 			// DisabledPendingEnable => Disabled
 			PeerState::DisabledPendingEnable { connections, timer_deadline, timer: _ } => {
 				debug_assert!(!connections.is_empty());
-				trace!(target: "sub-libp2p",
+				trace!(target: LOG_TARGET,
 					"PSM => Drop({}, {:?}): Interrupting pending enabling.",
 					entry.key().0, set_id);
 				*entry.into_mut() =
@@ -814,7 +814,7 @@ impl Notifications {
 
 			// Enabled => Disabled
 			PeerState::Enabled { mut connections } => {
-				trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Disabling connections.",
+				trace!(target: LOG_TARGET, "PSM => Drop({}, {:?}): Disabling connections.",
 					entry.key().0, set_id);
 
 				debug_assert!(connections.iter().any(|(_, s)| matches!(
@@ -823,7 +823,7 @@ impl Notifications {
 				)));
 
 				if connections.iter().any(|(_, s)| matches!(s, ConnectionState::Open(_))) {
-					trace!(target: "sub-libp2p", "External API <= Closed({}, {:?})", entry.key().0, set_id);
+					trace!(target: LOG_TARGET, "External API <= Closed({}, {:?})", entry.key().0, set_id);
 					let event =
 						NotificationsOut::CustomProtocolClosed { peer_id: entry.key().0, set_id };
 					self.events.push_back(ToSwarm::GenerateEvent(event));
@@ -832,7 +832,7 @@ impl Notifications {
 				for (connec_id, connec_state) in
 					connections.iter_mut().filter(|(_, s)| matches!(s, ConnectionState::Opening))
 				{
-					trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Close({:?})",
+					trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Close({:?})",
 						entry.key(), *connec_id, set_id);
 					self.events.push_back(ToSwarm::NotifyHandler {
 						peer_id: entry.key().0,
@@ -845,7 +845,7 @@ impl Notifications {
 				for (connec_id, connec_state) in
 					connections.iter_mut().filter(|(_, s)| matches!(s, ConnectionState::Open(_)))
 				{
-					trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Close({:?})",
+					trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Close({:?})",
 						entry.key(), *connec_id, set_id);
 					self.events.push_back(ToSwarm::NotifyHandler {
 						peer_id: entry.key().0,
@@ -863,14 +863,14 @@ impl Notifications {
 				// We don't cancel dialing. Libp2p doesn't expose that on purpose, as other
 				// sub-systems (such as the discovery mechanism) may require dialing this peer as
 				// well at the same time.
-				trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Not yet connected.",
+				trace!(target: LOG_TARGET, "PSM => Drop({}, {:?}): Not yet connected.",
 					entry.key().0, set_id);
 				entry.remove();
 			},
 
 			// PendingRequest => Backoff
 			PeerState::PendingRequest { timer, timer_deadline } => {
-				trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Not yet connected",
+				trace!(target: LOG_TARGET, "PSM => Drop({}, {:?}): Not yet connected",
 					entry.key().0, set_id);
 				*entry.into_mut() = PeerState::Backoff { timer, timer_deadline }
 			},
@@ -880,7 +880,7 @@ impl Notifications {
 			// the protocol, reject the substream
 			PeerState::Incoming { backoff_until, connections, incoming_index, .. } => {
 				debug!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"PSM => Drop({}, {:?}): Ignoring obsolete disconnect, we are awaiting accept/reject.",
 					entry.key().0, set_id,
 				);
@@ -892,7 +892,7 @@ impl Notifications {
 				};
 			},
 			PeerState::Poisoned => {
-				error!(target: "sub-libp2p", "State of {:?} is poisoned", entry.key());
+				error!(target: LOG_TARGET, "State of {:?} is poisoned", entry.key());
 				debug_assert!(false);
 			},
 		}
@@ -944,19 +944,19 @@ impl Notifications {
 			if let Some(pos) = self.incoming.iter().position(|i| i.incoming_id == index) {
 				(pos, self.incoming.get(pos))
 			} else {
-				error!(target: "sub-libp2p", "PSM => Accept({:?}): Invalid index", index);
+				error!(target: LOG_TARGET, "PSM => Accept({:?}): Invalid index", index);
 				return
 			};
 
 		let Some(incoming) = incoming else {
-			error!(target: "sub-libp2p", "Incoming connection ({:?}) doesn't exist", index);
+			error!(target: LOG_TARGET, "Incoming connection ({:?}) doesn't exist", index);
 			debug_assert!(false);
 			return;
 		};
 
 		if !incoming.alive {
 			trace!(
-				target: "sub-libp2p",
+				target: LOG_TARGET,
 				"PSM => Accept({:?}, {}, {:?}): Obsolete incoming",
 				index,
 				incoming.peer_id,
@@ -967,7 +967,7 @@ impl Notifications {
 				Some(PeerState::DisabledPendingEnable { .. }) | Some(PeerState::Enabled { .. }) => {
 				},
 				_ => {
-					trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})",
+					trace!(target: LOG_TARGET, "PSM <= Dropped({}, {:?})",
 						incoming.peer_id, incoming.set_id);
 					self.protocol_controller_handles[usize::from(incoming.set_id)]
 						.dropped(incoming.peer_id);
@@ -982,7 +982,7 @@ impl Notifications {
 			Some(s) => s,
 			None => {
 				log::debug!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"Connection to {:?} closed, ({:?} {:?}), ignoring accept",
 					incoming.peer_id,
 					incoming.set_id,
@@ -1003,7 +1003,7 @@ impl Notifications {
 			} => {
 				if index < incoming_index {
 					warn!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"PSM => Accept({:?}, {}, {:?}): Ignoring obsolete incoming index, we are already awaiting {:?}.",
 						index, incoming.peer_id, incoming.set_id, incoming_index
 					);
@@ -1012,7 +1012,7 @@ impl Notifications {
 					return
 				} else if index > incoming_index {
 					error!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"PSM => Accept({:?}, {}, {:?}): Ignoring incoming index from the future, we are awaiting {:?}.",
 						index, incoming.peer_id, incoming.set_id, incoming_index
 					);
@@ -1026,7 +1026,7 @@ impl Notifications {
 				// for the it to be closed so reject the substream now
 				if peerset_rejected {
 					trace!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"Protocol accepted ({:?} {:?} {:?}) but Peerset had request disconnection, rejecting",
 						index,
 						incoming.peer_id,
@@ -1043,7 +1043,7 @@ impl Notifications {
 				}
 
 				trace!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"PSM => Accept({:?}, {}, {:?}): Enabling connections.",
 					index,
 					incoming.peer_id,
@@ -1057,7 +1057,7 @@ impl Notifications {
 					.iter_mut()
 					.filter(|(_, s)| matches!(s, ConnectionState::OpenDesiredByRemote))
 				{
-					trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Open({:?})",
+					trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Open({:?})",
 						incoming.peer_id, *connec_id, incoming.set_id);
 					self.events.push_back(ToSwarm::NotifyHandler {
 						peer_id: incoming.peer_id,
@@ -1077,7 +1077,7 @@ impl Notifications {
 			// Any state other than `Incoming` is invalid.
 			peer => {
 				error!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"State mismatch in libp2p: Expected alive incoming. Got {:?}.",
 					peer
 				);
@@ -1106,13 +1106,13 @@ impl Notifications {
 		{
 			self.incoming.remove(pos)
 		} else {
-			error!(target: "sub-libp2p", "PSM => Reject({:?}): Invalid index", index);
+			error!(target: LOG_TARGET, "PSM => Reject({:?}): Invalid index", index);
 			return None
 		};
 
 		if !incoming.alive {
 			trace!(
-				target: "sub-libp2p",
+				target: LOG_TARGET,
 				"PSM => Reject({:?}, {}, {:?}): Obsolete incoming, ignoring",
 				index,
 				incoming.peer_id,
@@ -1126,7 +1126,7 @@ impl Notifications {
 			Some(s) => s,
 			None => {
 				log::debug!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"Connection to {:?} closed, ({:?} {:?}), ignoring accept",
 					incoming.peer_id,
 					incoming.set_id,
@@ -1141,14 +1141,14 @@ impl Notifications {
 			PeerState::Incoming { mut connections, backoff_until, incoming_index, .. } => {
 				if index < incoming_index {
 					warn!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"PSM => Reject({:?}, {}, {:?}): Ignoring obsolete incoming index, we are already awaiting {:?}.",
 						index, incoming.peer_id, incoming.set_id, incoming_index
 					);
 					return None
 				} else if index > incoming_index {
 					error!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"PSM => Reject({:?}, {}, {:?}): Ignoring incoming index from the future, we are awaiting {:?}.",
 						index, incoming.peer_id, incoming.set_id, incoming_index
 					);
@@ -1156,7 +1156,7 @@ impl Notifications {
 					return None
 				}
 
-				trace!(target: "sub-libp2p", "PSM => Reject({:?}, {}, {:?}): Rejecting connections.",
+				trace!(target: LOG_TARGET, "PSM => Reject({:?}, {}, {:?}): Rejecting connections.",
 					index, incoming.peer_id, incoming.set_id);
 
 				debug_assert!(connections
@@ -1166,7 +1166,7 @@ impl Notifications {
 					.iter_mut()
 					.filter(|(_, s)| matches!(s, ConnectionState::OpenDesiredByRemote))
 				{
-					trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Close({:?})",
+					trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Close({:?})",
 						incoming.peer_id, connec_id, incoming.set_id);
 					self.events.push_back(ToSwarm::NotifyHandler {
 						peer_id: incoming.peer_id,
@@ -1252,11 +1252,11 @@ impl NetworkBehaviour for Notifications {
 						// Requested | PendingRequest => Enabled
 						st @ &mut PeerState::Requested |
 						st @ &mut PeerState::PendingRequest { .. } => {
-							trace!(target: "sub-libp2p",
+							trace!(target: LOG_TARGET,
 								"Libp2p => Connected({}, {:?}, {:?}): Connection was requested by PSM.",
 								peer_id, set_id, endpoint
 							);
-							trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Open({:?})", peer_id, connection_id, set_id);
+							trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Open({:?})", peer_id, connection_id, set_id);
 							self.events.push_back(ToSwarm::NotifyHandler {
 								peer_id,
 								handler: NotifyHandler::One(connection_id),
@@ -1277,7 +1277,7 @@ impl NetworkBehaviour for Notifications {
 								} else {
 									None
 								};
-							trace!(target: "sub-libp2p",
+							trace!(target: LOG_TARGET,
 								"Libp2p => Connected({}, {:?}, {:?}, {:?}): Not requested by PSM, disabling.",
 								peer_id, set_id, endpoint, connection_id);
 
@@ -1292,7 +1292,7 @@ impl NetworkBehaviour for Notifications {
 						PeerState::Disabled { connections, .. } |
 						PeerState::DisabledPendingEnable { connections, .. } |
 						PeerState::Enabled { connections, .. } => {
-							trace!(target: "sub-libp2p",
+							trace!(target: LOG_TARGET,
 								"Libp2p => Connected({}, {:?}, {:?}, {:?}): Secondary connection. Leaving closed.",
 								peer_id, set_id, endpoint, connection_id);
 							connections.push((connection_id, ConnectionState::Closed));
@@ -1307,7 +1307,7 @@ impl NetworkBehaviour for Notifications {
 					{
 						entry
 					} else {
-						error!(target: "sub-libp2p", "inject_connection_closed: State mismatch in the custom protos handler");
+						error!(target: LOG_TARGET, "inject_connection_closed: State mismatch in the custom protos handler");
 						debug_assert!(false);
 						return
 					};
@@ -1315,7 +1315,7 @@ impl NetworkBehaviour for Notifications {
 					match mem::replace(entry.get_mut(), PeerState::Poisoned) {
 						// Disabled => Disabled | Backoff | Ø
 						PeerState::Disabled { mut connections, backoff_until } => {
-							trace!(target: "sub-libp2p", "Libp2p => Disconnected({}, {:?}, {:?}): Disabled.",
+							trace!(target: LOG_TARGET, "Libp2p => Disconnected({}, {:?}, {:?}): Disabled.",
 								peer_id, set_id, connection_id);
 
 							if let Some(pos) =
@@ -1324,7 +1324,7 @@ impl NetworkBehaviour for Notifications {
 								connections.remove(pos);
 							} else {
 								debug_assert!(false);
-								error!(target: "sub-libp2p",
+								error!(target: LOG_TARGET,
 									"inject_connection_closed: State mismatch in the custom protos handler");
 							}
 
@@ -1366,7 +1366,7 @@ impl NetworkBehaviour for Notifications {
 							timer,
 						} => {
 							trace!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"Libp2p => Disconnected({}, {:?}, {:?}): Disabled but pending enable.",
 								peer_id, set_id, connection_id
 							);
@@ -1376,13 +1376,13 @@ impl NetworkBehaviour for Notifications {
 							{
 								connections.remove(pos);
 							} else {
-								error!(target: "sub-libp2p",
+								error!(target: LOG_TARGET,
 									"inject_connection_closed: State mismatch in the custom protos handler");
 								debug_assert!(false);
 							}
 
 							if connections.is_empty() {
-								trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id);
+								trace!(target: LOG_TARGET, "PSM <= Dropped({}, {:?})", peer_id, set_id);
 								self.protocol_controller_handles[usize::from(set_id)]
 									.dropped(peer_id);
 								*entry.get_mut() = PeerState::Backoff { timer, timer_deadline };
@@ -1403,7 +1403,7 @@ impl NetworkBehaviour for Notifications {
 							peerset_rejected,
 						} => {
 							trace!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"Libp2p => Disconnected({}, {:?}, {:?}): OpenDesiredByRemote.",
 								peer_id, set_id, connection_id
 							);
@@ -1417,7 +1417,7 @@ impl NetworkBehaviour for Notifications {
 							{
 								connections.remove(pos);
 							} else {
-								error!(target: "sub-libp2p",
+								error!(target: LOG_TARGET,
 									"inject_connection_closed: State mismatch in the custom protos handler");
 								debug_assert!(false);
 							}
@@ -1439,7 +1439,7 @@ impl NetworkBehaviour for Notifications {
 								{
 									state.alive = false;
 								} else {
-									error!(target: "sub-libp2p", "State mismatch in libp2p: no entry in \
+									error!(target: LOG_TARGET, "State mismatch in libp2p: no entry in \
 										incoming corresponding to an incoming state in peers");
 									debug_assert!(false);
 								}
@@ -1489,7 +1489,7 @@ impl NetworkBehaviour for Notifications {
 						// Peers are always backed-off when disconnecting while Enabled.
 						PeerState::Enabled { mut connections } => {
 							trace!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"Libp2p => Disconnected({}, {:?}, {:?}): Enabled.",
 								peer_id, set_id, connection_id
 							);
@@ -1513,7 +1513,7 @@ impl NetworkBehaviour for Notifications {
 										}) {
 										if pos <= replacement_pos {
 											trace!(
-												target: "sub-libp2p",
+												target: LOG_TARGET,
 												"External API <= Sink replaced({}, {:?})",
 												peer_id, set_id
 											);
@@ -1526,7 +1526,7 @@ impl NetworkBehaviour for Notifications {
 										}
 									} else {
 										trace!(
-											target: "sub-libp2p", "External API <= Closed({}, {:?})",
+											target: LOG_TARGET, "External API <= Closed({}, {:?})",
 											peer_id, set_id
 										);
 										let event = NotificationsOut::CustomProtocolClosed {
@@ -1537,13 +1537,13 @@ impl NetworkBehaviour for Notifications {
 									}
 								}
 							} else {
-								error!(target: "sub-libp2p",
+								error!(target: LOG_TARGET,
 									"inject_connection_closed: State mismatch in the custom protos handler");
 								debug_assert!(false);
 							}
 
 							if connections.is_empty() {
-								trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id);
+								trace!(target: LOG_TARGET, "PSM <= Dropped({}, {:?})", peer_id, set_id);
 								self.protocol_controller_handles[usize::from(set_id)]
 									.dropped(peer_id);
 								let ban_dur = Uniform::new(5, 10).sample(&mut rand::thread_rng());
@@ -1566,7 +1566,7 @@ impl NetworkBehaviour for Notifications {
 							} else if !connections.iter().any(|(_, s)| {
 								matches!(s, ConnectionState::Opening | ConnectionState::Open(_))
 							}) {
-								trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id);
+								trace!(target: LOG_TARGET, "PSM <= Dropped({}, {:?})", peer_id, set_id);
 								self.protocol_controller_handles[usize::from(set_id)]
 									.dropped(peer_id);
 
@@ -1581,13 +1581,13 @@ impl NetworkBehaviour for Notifications {
 						PeerState::PendingRequest { .. } |
 						PeerState::Backoff { .. } => {
 							// This is a serious bug either in this state machine or in libp2p.
-							error!(target: "sub-libp2p",
+							error!(target: LOG_TARGET,
 								"`inject_connection_closed` called for unknown peer {}",
 								peer_id);
 							debug_assert!(false);
 						},
 						PeerState::Poisoned => {
-							error!(target: "sub-libp2p", "State of peer {} is poisoned", peer_id);
+							error!(target: LOG_TARGET, "State of peer {} is poisoned", peer_id);
 							debug_assert!(false);
 						},
 					}
@@ -1596,12 +1596,12 @@ impl NetworkBehaviour for Notifications {
 			FromSwarm::DialFailure(DialFailure { peer_id, error, .. }) => {
 				if let DialError::Transport(errors) = error {
 					for (addr, error) in errors.iter() {
-						trace!(target: "sub-libp2p", "Libp2p => Reach failure for {:?} through {:?}: {:?}", peer_id, addr, error);
+						trace!(target: LOG_TARGET, "Libp2p => Reach failure for {:?} through {:?}: {:?}", peer_id, addr, error);
 					}
 				}
 
 				if let Some(peer_id) = peer_id {
-					trace!(target: "sub-libp2p", "Libp2p => Dial failure for {:?}", peer_id);
+					trace!(target: LOG_TARGET, "Libp2p => Dial failure for {:?}", peer_id);
 
 					for set_id in (0..self.notif_protocols.len()).map(SetId::from) {
 						if let Entry::Occupied(mut entry) = self.peers.entry((peer_id, set_id)) {
@@ -1615,7 +1615,7 @@ impl NetworkBehaviour for Notifications {
 								// requested.
 								st @ PeerState::Requested |
 								st @ PeerState::PendingRequest { .. } => {
-									trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id);
+									trace!(target: LOG_TARGET, "PSM <= Dropped({}, {:?})", peer_id, set_id);
 									self.protocol_controller_handles[usize::from(set_id)]
 										.dropped(peer_id);
 
@@ -1654,7 +1654,7 @@ impl NetworkBehaviour for Notifications {
 								},
 
 								PeerState::Poisoned => {
-									error!(target: "sub-libp2p", "State of {:?} is poisoned", peer_id);
+									error!(target: LOG_TARGET, "State of {:?} is poisoned", peer_id);
 									debug_assert!(false);
 								},
 							}
@@ -1673,7 +1673,7 @@ impl NetworkBehaviour for Notifications {
 			FromSwarm::AddressChange(_) => {},
 			FromSwarm::NewListenAddr(_) => {},
 			event => {
-				warn!(target: "sub-libp2p", "New unknown `FromSwarm` libp2p event: {event:?}");
+				warn!(target: LOG_TARGET, "New unknown `FromSwarm` libp2p event: {event:?}");
 			},
 		}
 	}
@@ -1688,7 +1688,7 @@ impl NetworkBehaviour for Notifications {
 			NotifsHandlerOut::OpenDesiredByRemote { protocol_index, handshake } => {
 				let set_id = SetId::from(protocol_index);
 
-				trace!(target: "sub-libp2p",
+				trace!(target: LOG_TARGET,
 					"Handler({:?}, {:?}]) => OpenDesiredByRemote({:?})",
 					peer_id, connection_id, set_id);
 
@@ -1697,7 +1697,7 @@ impl NetworkBehaviour for Notifications {
 					entry
 				} else {
 					error!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"OpenDesiredByRemote: State mismatch in the custom protos handler"
 					);
 					debug_assert!(false);
@@ -1733,7 +1733,7 @@ impl NetworkBehaviour for Notifications {
 							}
 						} else {
 							error!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"OpenDesiredByRemote: State mismatch in the custom protos handler"
 							);
 							debug_assert!(false);
@@ -1757,7 +1757,7 @@ impl NetworkBehaviour for Notifications {
 							connections.iter_mut().find(|(c, _)| *c == connection_id)
 						{
 							if let ConnectionState::Closed = *connec_state {
-								trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Open({:?})",
+								trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Open({:?})",
 									peer_id, connection_id, set_id);
 								self.events.push_back(ToSwarm::NotifyHandler {
 									peer_id,
@@ -1779,7 +1779,7 @@ impl NetworkBehaviour for Notifications {
 							}
 						} else {
 							error!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"OpenDesiredByRemote: State mismatch in the custom protos handler"
 							);
 							debug_assert!(false);
@@ -1799,7 +1799,7 @@ impl NetworkBehaviour for Notifications {
 								let incoming_id = self.next_incoming_index;
 								self.next_incoming_index.0 += 1;
 
-								trace!(target: "sub-libp2p", "PSM <= Incoming({}, {:?}, {:?}).",
+								trace!(target: LOG_TARGET, "PSM <= Incoming({}, {:?}, {:?}).",
 									peer_id, set_id, incoming_id);
 								self.protocol_controller_handles[usize::from(set_id)]
 									.incoming_connection(peer_id, incoming_id);
@@ -1831,7 +1831,7 @@ impl NetworkBehaviour for Notifications {
 							}
 						} else {
 							error!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"OpenDesiredByRemote: State mismatch in the custom protos handler"
 							);
 							debug_assert!(false);
@@ -1844,7 +1844,7 @@ impl NetworkBehaviour for Notifications {
 							connections.iter_mut().find(|(c, _)| *c == connection_id)
 						{
 							if let ConnectionState::Closed = *connec_state {
-								trace!(target: "sub-libp2p", "Handler({:?}, {:?}) <= Open({:?})",
+								trace!(target: LOG_TARGET, "Handler({:?}, {:?}) <= Open({:?})",
 									peer_id, connection_id, set_id);
 								self.events.push_back(ToSwarm::NotifyHandler {
 									peer_id,
@@ -1871,7 +1871,7 @@ impl NetworkBehaviour for Notifications {
 							}
 						} else {
 							error!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"OpenDesiredByRemote: State mismatch in the custom protos handler"
 							);
 							debug_assert!(false);
@@ -1879,7 +1879,7 @@ impl NetworkBehaviour for Notifications {
 					},
 
 					state => {
-						error!(target: "sub-libp2p",
+						error!(target: LOG_TARGET,
 							   "OpenDesiredByRemote: Unexpected state in the custom protos handler: {:?}",
 							   state);
 						debug_assert!(false);
@@ -1890,7 +1890,7 @@ impl NetworkBehaviour for Notifications {
 			NotifsHandlerOut::CloseDesired { protocol_index } => {
 				let set_id = SetId::from(protocol_index);
 
-				trace!(target: "sub-libp2p",
+				trace!(target: LOG_TARGET,
 					"Handler({}, {:?}) => CloseDesired({:?})",
 					peer_id, connection_id, set_id);
 
@@ -1898,7 +1898,7 @@ impl NetworkBehaviour for Notifications {
 				{
 					entry
 				} else {
-					error!(target: "sub-libp2p", "CloseDesired: State mismatch in the custom protos handler");
+					error!(target: LOG_TARGET, "CloseDesired: State mismatch in the custom protos handler");
 					debug_assert!(false);
 					return
 				};
@@ -1916,7 +1916,7 @@ impl NetworkBehaviour for Notifications {
 						{
 							pos
 						} else {
-							error!(target: "sub-libp2p",
+							error!(target: LOG_TARGET,
 								"CloseDesired: State mismatch in the custom protos handler");
 							debug_assert!(false);
 							return
@@ -1930,7 +1930,7 @@ impl NetworkBehaviour for Notifications {
 						debug_assert!(matches!(connections[pos].1, ConnectionState::Open(_)));
 						connections[pos].1 = ConnectionState::Closing;
 
-						trace!(target: "sub-libp2p", "Handler({}, {:?}) <= Close({:?})", peer_id, connection_id, set_id);
+						trace!(target: LOG_TARGET, "Handler({}, {:?}) <= Close({:?})", peer_id, connection_id, set_id);
 						self.events.push_back(ToSwarm::NotifyHandler {
 							peer_id,
 							handler: NotifyHandler::One(connection_id),
@@ -1943,7 +1943,7 @@ impl NetworkBehaviour for Notifications {
 								_ => None,
 							}) {
 							if pos <= replacement_pos {
-								trace!(target: "sub-libp2p", "External API <= Sink replaced({:?}, {:?})", peer_id, set_id);
+								trace!(target: LOG_TARGET, "External API <= Sink replaced({:?}, {:?})", peer_id, set_id);
 								let event = NotificationsOut::CustomProtocolReplaced {
 									peer_id,
 									set_id,
@@ -1959,7 +1959,7 @@ impl NetworkBehaviour for Notifications {
 								.iter()
 								.any(|(_, s)| matches!(s, ConnectionState::Opening))
 							{
-								trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id);
+								trace!(target: LOG_TARGET, "PSM <= Dropped({}, {:?})", peer_id, set_id);
 								self.protocol_controller_handles[usize::from(set_id)]
 									.dropped(peer_id);
 								*entry.into_mut() =
@@ -1968,7 +1968,7 @@ impl NetworkBehaviour for Notifications {
 								*entry.into_mut() = PeerState::Enabled { connections };
 							}
 
-							trace!(target: "sub-libp2p", "External API <= Closed({}, {:?})", peer_id, set_id);
+							trace!(target: LOG_TARGET, "External API <= Closed({}, {:?})", peer_id, set_id);
 							let event = NotificationsOut::CustomProtocolClosed { peer_id, set_id };
 							self.events.push_back(ToSwarm::GenerateEvent(event));
 						}
@@ -1981,7 +1981,7 @@ impl NetworkBehaviour for Notifications {
 						*entry.into_mut() = state;
 					},
 					state => {
-						error!(target: "sub-libp2p",
+						error!(target: LOG_TARGET,
 							"Unexpected state in the custom protos handler: {:?}",
 							state);
 					},
@@ -1991,7 +1991,7 @@ impl NetworkBehaviour for Notifications {
 			NotifsHandlerOut::CloseResult { protocol_index } => {
 				let set_id = SetId::from(protocol_index);
 
-				trace!(target: "sub-libp2p",
+				trace!(target: LOG_TARGET,
 					"Handler({}, {:?}) => CloseResult({:?})",
 					peer_id, connection_id, set_id);
 
@@ -2006,14 +2006,14 @@ impl NetworkBehaviour for Notifications {
 						}) {
 							*connec_state = ConnectionState::Closed;
 						} else {
-							error!(target: "sub-libp2p",
+							error!(target: LOG_TARGET,
 								"CloseResult: State mismatch in the custom protos handler");
 							debug_assert!(false);
 						}
 					},
 
 					state => {
-						error!(target: "sub-libp2p",
+						error!(target: LOG_TARGET,
 							   "CloseResult: Unexpected state in the custom protos handler: {:?}",
 							   state);
 						debug_assert!(false);
@@ -2030,7 +2030,7 @@ impl NetworkBehaviour for Notifications {
 				..
 			} => {
 				let set_id = SetId::from(protocol_index);
-				trace!(target: "sub-libp2p",
+				trace!(target: LOG_TARGET,
 					"Handler({}, {:?}) => OpenResultOk({:?})",
 					peer_id, connection_id, set_id);
 
@@ -2047,7 +2047,7 @@ impl NetworkBehaviour for Notifications {
 							*c == connection_id && matches!(s, ConnectionState::Opening)
 						}) {
 							if !any_open {
-								trace!(target: "sub-libp2p", "External API <= Open({}, {:?})", peer_id, set_id);
+								trace!(target: LOG_TARGET, "External API <= Open({}, {:?})", peer_id, set_id);
 								let event = NotificationsOut::CustomProtocolOpen {
 									peer_id,
 									set_id,
@@ -2070,7 +2070,7 @@ impl NetworkBehaviour for Notifications {
 							}) {
 							*connec_state = ConnectionState::Closing;
 						} else {
-							error!(target: "sub-libp2p",
+							error!(target: LOG_TARGET,
 								"OpenResultOk State mismatch in the custom protos handler");
 							debug_assert!(false);
 						}
@@ -2084,14 +2084,14 @@ impl NetworkBehaviour for Notifications {
 						}) {
 							*connec_state = ConnectionState::Closing;
 						} else {
-							error!(target: "sub-libp2p",
+							error!(target: LOG_TARGET,
 								"OpenResultOk State mismatch in the custom protos handler");
 							debug_assert!(false);
 						}
 					},
 
 					state => {
-						error!(target: "sub-libp2p",
+						error!(target: LOG_TARGET,
 							   "OpenResultOk: Unexpected state in the custom protos handler: {:?}",
 							   state);
 						debug_assert!(false);
@@ -2101,7 +2101,7 @@ impl NetworkBehaviour for Notifications {
 
 			NotifsHandlerOut::OpenResultErr { protocol_index } => {
 				let set_id = SetId::from(protocol_index);
-				trace!(target: "sub-libp2p",
+				trace!(target: LOG_TARGET,
 					"Handler({:?}, {:?}) => OpenResultErr({:?})",
 					peer_id, connection_id, set_id);
 
@@ -2109,7 +2109,7 @@ impl NetworkBehaviour for Notifications {
 				{
 					entry
 				} else {
-					error!(target: "sub-libp2p", "OpenResultErr: State mismatch in the custom protos handler");
+					error!(target: LOG_TARGET, "OpenResultErr: State mismatch in the custom protos handler");
 					debug_assert!(false);
 					return
 				};
@@ -2132,7 +2132,7 @@ impl NetworkBehaviour for Notifications {
 							}) {
 							*connec_state = ConnectionState::Closing;
 						} else {
-							error!(target: "sub-libp2p",
+							error!(target: LOG_TARGET,
 								"OpenResultErr: State mismatch in the custom protos handler");
 							debug_assert!(false);
 						}
@@ -2140,7 +2140,7 @@ impl NetworkBehaviour for Notifications {
 						if !connections.iter().any(|(_, s)| {
 							matches!(s, ConnectionState::Opening | ConnectionState::Open(_))
 						}) {
-							trace!(target: "sub-libp2p", "PSM <= Dropped({:?}, {:?})", peer_id, set_id);
+							trace!(target: LOG_TARGET, "PSM <= Dropped({:?}, {:?})", peer_id, set_id);
 							self.protocol_controller_handles[usize::from(set_id)].dropped(peer_id);
 
 							let ban_dur = Uniform::new(5, 10).sample(&mut rand::thread_rng());
@@ -2166,7 +2166,7 @@ impl NetworkBehaviour for Notifications {
 									}) {
 									*connec_state = ConnectionState::Closing;
 								} else {
-									error!(target: "sub-libp2p",
+									error!(target: LOG_TARGET,
 										"OpenResultErr: State mismatch in the custom protos handler");
 									debug_assert!(false);
 								}
@@ -2180,7 +2180,7 @@ impl NetworkBehaviour for Notifications {
 						*entry.into_mut() = state;
 					},
 					state => {
-						error!(target: "sub-libp2p",
+						error!(target: LOG_TARGET,
 							"Unexpected state in the custom protos handler: {:?}",
 							state);
 						debug_assert!(false);
@@ -2192,7 +2192,7 @@ impl NetworkBehaviour for Notifications {
 				let set_id = SetId::from(protocol_index);
 				if self.is_open(&peer_id, set_id) {
 					trace!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"Handler({:?}) => Notification({}, {:?}, {} bytes)",
 						connection_id,
 						peer_id,
@@ -2200,7 +2200,7 @@ impl NetworkBehaviour for Notifications {
 						message.len()
 					);
 					trace!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"External API <= Message({}, {:?})",
 						peer_id,
 						set_id,
@@ -2213,7 +2213,7 @@ impl NetworkBehaviour for Notifications {
 					self.events.push_back(ToSwarm::GenerateEvent(event));
 				} else {
 					trace!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"Handler({:?}) => Post-close notification({}, {:?}, {} bytes)",
 						connection_id,
 						peer_id,
@@ -2225,7 +2225,7 @@ impl NetworkBehaviour for Notifications {
 			NotifsHandlerOut::Close { protocol_index } => {
 				let set_id = SetId::from(protocol_index);
 
-				trace!(target: "sub-libp2p", "Handler({}, {:?}) => SyncNotificationsClogged({:?})", peer_id, connection_id, set_id);
+				trace!(target: LOG_TARGET, "Handler({}, {:?}) => SyncNotificationsClogged({:?})", peer_id, connection_id, set_id);
 				self.events.push_back(ToSwarm::CloseConnection {
 					peer_id,
 					connection: CloseConnection::One(connection_id),
@@ -2256,7 +2256,7 @@ impl NetworkBehaviour for Notifications {
 				},
 				Poll::Ready(None) => {
 					error!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"Protocol controllers receiver stream has returned `None`. Ignore this error if the node is shutting down.",
 					);
 					break
@@ -2314,12 +2314,12 @@ impl NetworkBehaviour for Notifications {
 
 			match peer_state {
 				PeerState::Backoff { timer, .. } if *timer == delay_id => {
-					trace!(target: "sub-libp2p", "Libp2p <= Clean up ban of {:?} from the state ({:?})", peer_id, set_id);
+					trace!(target: LOG_TARGET, "Libp2p <= Clean up ban of {:?} from the state ({:?})", peer_id, set_id);
 					self.peers.remove(&(peer_id, set_id));
 				},
 
 				PeerState::PendingRequest { timer, .. } if *timer == delay_id => {
-					trace!(target: "sub-libp2p", "Libp2p <= Dial {:?} now that ban has expired ({:?})", peer_id, set_id);
+					trace!(target: LOG_TARGET, "Libp2p <= Dial {:?} now that ban has expired ({:?})", peer_id, set_id);
 					self.events.push_back(ToSwarm::Dial { opts: peer_id.into() });
 					*peer_state = PeerState::Requested;
 				},
@@ -2331,7 +2331,7 @@ impl NetworkBehaviour for Notifications {
 					if let Some((connec_id, connec_state)) =
 						connections.iter_mut().find(|(_, s)| matches!(s, ConnectionState::Closed))
 					{
-						trace!(target: "sub-libp2p", "Handler({}, {:?}) <= Open({:?}) (ban expired)",
+						trace!(target: LOG_TARGET, "Handler({}, {:?}) <= Open({:?}) (ban expired)",
 							peer_id, *connec_id, set_id);
 						self.events.push_back(ToSwarm::NotifyHandler {
 							peer_id,
diff --git a/substrate/client/network/src/protocol/notifications/handler.rs b/substrate/client/network/src/protocol/notifications/handler.rs
index 332de9f19c4..416a35ad88c 100644
--- a/substrate/client/network/src/protocol/notifications/handler.rs
+++ b/substrate/client/network/src/protocol/notifications/handler.rs
@@ -79,7 +79,7 @@ use libp2p::{
 	},
 	PeerId,
 };
-use log::{error, warn};
+
 use parking_lot::{Mutex, RwLock};
 use std::{
 	collections::VecDeque,
@@ -90,6 +90,9 @@ use std::{
 	time::Duration,
 };
 
+/// Logging target for the file.
+const LOG_TARGET: &str = "sub-libp2p::notification::handler";
+
 /// Number of pending notifications in asynchronous contexts.
 /// See [`NotificationsSink::reserve_notification`] for context.
 pub(crate) const ASYNC_NOTIFICATIONS_BUFFER_SIZE: usize = 8;
@@ -561,7 +564,7 @@ impl ConnectionHandler for NotifsHandler {
 						*pending_opening = false;
 					},
 					State::Open { .. } => {
-						error!(target: "sub-libp2p", "☎️ State mismatch in notifications handler");
+						log::error!(target: LOG_TARGET, "☎️ State mismatch in notifications handler");
 						debug_assert!(false);
 					},
 					State::Opening { ref mut in_substream, inbound } => {
@@ -622,7 +625,7 @@ impl ConnectionHandler for NotifsHandler {
 			},
 			ConnectionEvent::ListenUpgradeError(_listen_upgrade_error) => {},
 			event => {
-				warn!(target: "sub-libp2p", "New unknown `ConnectionEvent` libp2p event: {event:?}");
+				log::warn!(target: LOG_TARGET, "New unknown `ConnectionEvent` libp2p event: {event:?}");
 			},
 		}
 	}
@@ -686,7 +689,7 @@ impl ConnectionHandler for NotifsHandler {
 					State::Opening { .. } | State::Open { .. } => {
 						// As documented, it is forbidden to send an `Open` while there is already
 						// one in the fly.
-						error!(target: "sub-libp2p", "opening already-opened handler");
+						log::error!(target: LOG_TARGET, "opening already-opened handler");
 						debug_assert!(false);
 					},
 				}
diff --git a/substrate/client/network/src/protocol/notifications/service/mod.rs b/substrate/client/network/src/protocol/notifications/service/mod.rs
index a7eb31fc579..fe88a879376 100644
--- a/substrate/client/network/src/protocol/notifications/service/mod.rs
+++ b/substrate/client/network/src/protocol/notifications/service/mod.rs
@@ -49,7 +49,7 @@ pub(crate) mod metrics;
 mod tests;
 
 /// Logging target for the file.
-const LOG_TARGET: &str = "sub-libp2p";
+const LOG_TARGET: &str = "sub-libp2p::notification::service";
 
 /// Default command queue size.
 const COMMAND_QUEUE_SIZE: usize = 64;
diff --git a/substrate/client/network/src/protocol/notifications/upgrade/notifications.rs b/substrate/client/network/src/protocol/notifications/upgrade/notifications.rs
index 9e8a03fc07c..b4d0de171a1 100644
--- a/substrate/client/network/src/protocol/notifications/upgrade/notifications.rs
+++ b/substrate/client/network/src/protocol/notifications/upgrade/notifications.rs
@@ -50,6 +50,9 @@ use std::{
 	vec,
 };
 
+/// Logging target for the file.
+const LOG_TARGET: &str = "sub-libp2p::notification::upgrade";
+
 /// Maximum allowed size of the two handshake messages, in bytes.
 const MAX_HANDSHAKE_SIZE: usize = 1024;
 
@@ -210,7 +213,7 @@ where
 	/// Sends the handshake in order to inform the remote that we accept the substream.
 	pub fn send_handshake(&mut self, message: impl Into<Vec<u8>>) {
 		if !matches!(self.handshake, NotificationsInSubstreamHandshake::NotSent) {
-			error!(target: "sub-libp2p", "Tried to send handshake twice");
+			error!(target: LOG_TARGET, "Tried to send handshake twice");
 			return
 		}
 
@@ -349,7 +352,7 @@ impl NotificationsOut {
 	) -> Self {
 		let initial_message = initial_message.into();
 		if initial_message.len() > MAX_HANDSHAKE_SIZE {
-			error!(target: "sub-libp2p", "Outbound networking handshake is above allowed protocol limit");
+			error!(target: LOG_TARGET, "Outbound networking handshake is above allowed protocol limit");
 		}
 
 		let mut protocol_names = fallback_names;
@@ -464,7 +467,7 @@ where
 			Poll::Pending => {},
 			Poll::Ready(Some(_)) => {
 				error!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"Unexpected incoming data in `NotificationsOutSubstream`",
 				);
 			},
diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs
index e21773632ed..ac87224549f 100644
--- a/substrate/client/network/src/request_responses.rs
+++ b/substrate/client/network/src/request_responses.rs
@@ -64,6 +64,9 @@ use std::{
 
 pub use libp2p::request_response::{Config, InboundRequestId, OutboundRequestId};
 
+/// Logging target for the file.
+const LOG_TARGET: &str = "sub-libp2p::request-response";
+
 /// Periodically check if requests are taking too long.
 const PERIODIC_REQUEST_CHECK: Duration = Duration::from_secs(2);
 
@@ -461,7 +464,7 @@ impl RequestResponsesBehaviour {
 		pending_response: oneshot::Sender<Result<(Vec<u8>, ProtocolName), RequestFailure>>,
 		connect: IfDisconnected,
 	) {
-		log::trace!(target: "sub-libp2p", "send request to {target} ({protocol_name:?}), {} bytes", request.len());
+		log::trace!(target: LOG_TARGET, "send request to {target} ({protocol_name:?}), {} bytes", request.len());
 
 		if let Some(ProtocolDetails { behaviour, .. }) =
 			self.protocols.get_mut(protocol_name.deref())
@@ -478,7 +481,7 @@ impl RequestResponsesBehaviour {
 			)
 		} else if pending_response.send(Err(RequestFailure::UnknownProtocol)).is_err() {
 			log::debug!(
-				target: "sub-libp2p",
+				target: LOG_TARGET,
 				"Unknown protocol {:?}. At the same time local \
 				 node is no longer interested in the result.",
 				protocol_name,
@@ -509,7 +512,7 @@ impl RequestResponsesBehaviour {
 			debug_assert!(prev_req_id.is_none(), "Expect request id to be unique.");
 		} else if pending_response.send(Err(RequestFailure::NotConnected)).is_err() {
 			log::debug!(
-				target: "sub-libp2p",
+				target: LOG_TARGET,
 				"Not connected to peer {:?}. At the same time local \
 				 node is no longer interested in the result.",
 				target,
@@ -615,7 +618,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 			return behaviour.on_connection_handler_event(peer_id, connection_id, event.1)
 		} else {
 			log::warn!(
-				target: "sub-libp2p",
+				target: LOG_TARGET,
 				"on_connection_handler_event: no request-response instance registered for protocol {:?}",
 				p_name
 			);
@@ -631,14 +634,14 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 						self.protocols.get(&id.protocol)
 					else {
 						log::warn!(
-							target: "sub-libp2p",
+							target: LOG_TARGET,
 							"Request {id:?} has no protocol registered.",
 						);
 
 						if let Some(response_tx) = req.response_tx.take() {
 							if response_tx.send(Err(RequestFailure::UnknownProtocol)).is_err() {
 								log::debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Request {id:?} has no protocol registered. At the same time local node is no longer interested in the result.",
 								);
 							}
@@ -649,14 +652,14 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 					let elapsed = req.started_at.elapsed();
 					if elapsed > *request_timeout {
 						log::debug!(
-							target: "sub-libp2p",
+							target: LOG_TARGET,
 							"Request {id:?} force detected as timeout.",
 						);
 
 						if let Some(response_tx) = req.response_tx.take() {
 							if response_tx.send(Err(RequestFailure::Network(OutboundFailure::Timeout))).is_err() {
 								log::debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Request {id:?} force detected as timeout. At the same time local node is no longer interested in the result.",
 								);
 							}
@@ -688,13 +691,13 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 					if let Some(ProtocolDetails { behaviour, .. }) =
 						self.protocols.get_mut(&*protocol_name)
 					{
-						log::trace!(target: "sub-libp2p", "send response to {peer} ({protocol_name:?}), {} bytes", payload.len());
+						log::trace!(target: LOG_TARGET, "send response to {peer} ({protocol_name:?}), {} bytes", payload.len());
 
 						if behaviour.send_response(inner_channel, Ok(payload)).is_err() {
 							// Note: Failure is handled further below when receiving
 							// `InboundFailure` event from request-response [`Behaviour`].
 							log::debug!(
-								target: "sub-libp2p",
+								target: LOG_TARGET,
 								"Failed to send response for {:?} on protocol {:?} due to a \
 								 timeout or due to the connection to the peer being closed. \
 								 Dropping response",
@@ -730,7 +733,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 						ToSwarm::Dial { opts } => {
 							if opts.get_peer_id().is_none() {
 								log::error!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"The request-response isn't supposed to start dialing addresses"
 								);
 							}
@@ -762,7 +765,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 
 							if reputation < BANNED_THRESHOLD {
 								log::debug!(
-									target: "sub-libp2p",
+									target: LOG_TARGET,
 									"Cannot handle requests from a node with a low reputation {}: {}",
 									peer,
 									reputation,
@@ -828,7 +831,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 									..
 								}) => {
 									log::trace!(
-										target: "sub-libp2p",
+										target: LOG_TARGET,
 										"received response from {peer} ({protocol:?}), {} bytes",
 										response.as_ref().map_or(0usize, |response| response.len()),
 									);
@@ -844,7 +847,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 								},
 								_ => {
 									log::debug!(
-										target: "sub-libp2p",
+										target: LOG_TARGET,
 										"Received `RequestResponseEvent::Message` with unexpected request id {:?} from {:?}",
 										request_id,
 										peer,
@@ -887,7 +890,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 											fallback_request
 										{
 											log::trace!(
-												target: "sub-libp2p",
+												target: LOG_TARGET,
 												"Request with id {:?} failed. Trying the fallback protocol. {}",
 												request_id,
 												fallback_protocol.deref()
@@ -907,7 +910,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 										.is_err()
 									{
 										log::debug!(
-											target: "sub-libp2p",
+											target: LOG_TARGET,
 											"Request with id {:?} failed. At the same time local \
 											 node is no longer interested in the result.",
 											request_id,
@@ -917,7 +920,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
 								},
 								_ => {
 									log::debug!(
-										target: "sub-libp2p",
+										target: LOG_TARGET,
 										"Received `RequestResponseEvent::OutboundFailure` with unexpected request id {:?} error {:?} from {:?}",
 										request_id,
 										error,
diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs
index b4463ad4808..3f6ff7c5f6d 100644
--- a/substrate/client/network/src/service.rs
+++ b/substrate/client/network/src/service.rs
@@ -110,6 +110,9 @@ pub(crate) mod out_events;
 pub mod signature;
 pub mod traits;
 
+/// Logging target for the file.
+const LOG_TARGET: &str = "sub-libp2p";
+
 struct Libp2pBandwidthSink {
 	#[allow(deprecated)]
 	sink: Arc<transport::BandwidthSinks>,
@@ -287,7 +290,7 @@ where
 			.filter(|reserved_node| {
 				if reserved_node.peer_id == local_peer_id.into() {
 					warn!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"Local peer ID used in reserved node, ignoring: {}",
 						reserved_node,
 					);
@@ -329,11 +332,11 @@ where
 		}
 
 		info!(
-			target: "sub-libp2p",
+			target: LOG_TARGET,
 			"🏷  Local node identity is: {}",
 			local_peer_id.to_base58(),
 		);
-		info!(target: "sub-libp2p", "Running libp2p network backend");
+		info!(target: LOG_TARGET, "Running libp2p network backend");
 
 		let (transport, bandwidth) = {
 			let config_mem = match network_config.transport {
@@ -569,7 +572,7 @@ where
 		// Listen on multiaddresses.
 		for addr in &network_config.listen_addresses {
 			if let Err(err) = Swarm::<Behaviour<B>>::listen_on(&mut swarm, addr.clone().into()) {
-				warn!(target: "sub-libp2p", "Can't listen on {} because: {:?}", addr, err)
+				warn!(target: LOG_TARGET, "Can't listen on {} because: {:?}", addr, err)
 			}
 		}
 
@@ -681,7 +684,7 @@ where
 						) {
 						addrs.into_iter().collect()
 					} else {
-						error!(target: "sub-libp2p", "Was not able to get known addresses for {:?}", peer_id);
+						error!(target: LOG_TARGET, "Was not able to get known addresses for {:?}", peer_id);
 						return None
 					};
 
@@ -690,7 +693,7 @@ where
 					{
 						e.clone().into()
 					} else {
-						error!(target: "sub-libp2p", "Found state inconsistency between custom protocol \
+						error!(target: LOG_TARGET, "Found state inconsistency between custom protocol \
 						and debug information about {:?}", peer_id);
 						return None
 					};
@@ -732,7 +735,7 @@ where
 						) {
 						addrs.into_iter().collect()
 					} else {
-						error!(target: "sub-libp2p", "Was not able to get known addresses for {:?}", peer_id);
+						error!(target: LOG_TARGET, "Was not able to get known addresses for {:?}", peer_id);
 						Default::default()
 					};
 
@@ -1145,7 +1148,7 @@ where
 		match Roles::decode_all(&mut &handshake[..]) {
 			Ok(role) => Some(role.into()),
 			Err(_) => {
-				log::debug!(target: "sub-libp2p", "handshake doesn't contain peer role: {handshake:?}");
+				log::debug!(target: LOG_TARGET, "handshake doesn't contain peer role: {handshake:?}");
 				self.peer_store_handle.peer_role(&(peer_id.into()))
 			},
 		}
@@ -1278,11 +1281,11 @@ impl<'a> NotificationSenderReadyT for NotificationSenderReady<'a> {
 		}
 
 		trace!(
-			target: "sub-libp2p",
+			target: LOG_TARGET,
 			"External API => Notification({:?}, {}, {} bytes)",
 			self.peer_id, self.protocol_name, notification.len(),
 		);
-		trace!(target: "sub-libp2p", "Handler({:?}) <= Async notification", self.peer_id);
+		trace!(target: LOG_TARGET, "Handler({:?}) <= Async notification", self.peer_id);
 
 		self.ready
 			.take()
@@ -1570,7 +1573,7 @@ where
 			}) => {
 				if listen_addrs.len() > 30 {
 					debug!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"Node {:?} has reported more than 30 addresses; it is identified by {:?} and {:?}",
 						peer_id, protocol_version, agent_version
 					);
@@ -1684,9 +1687,9 @@ where
 				..
 			} => {
 				if let Some(errors) = concurrent_dial_errors {
-					debug!(target: "sub-libp2p", "Libp2p => Connected({:?}) with errors: {:?}", peer_id, errors);
+					debug!(target: LOG_TARGET, "Libp2p => Connected({:?}) with errors: {:?}", peer_id, errors);
 				} else {
-					debug!(target: "sub-libp2p", "Libp2p => Connected({:?})", peer_id);
+					debug!(target: LOG_TARGET, "Libp2p => Connected({:?})", peer_id);
 				}
 
 				if let Some(metrics) = self.metrics.as_ref() {
@@ -1708,7 +1711,7 @@ where
 				endpoint,
 				num_established,
 			} => {
-				debug!(target: "sub-libp2p", "Libp2p => Disconnected({peer_id:?} via {connection_id:?}, {cause:?})");
+				debug!(target: LOG_TARGET, "Libp2p => Disconnected({peer_id:?} via {connection_id:?}, {cause:?})");
 				if let Some(metrics) = self.metrics.as_ref() {
 					let direction = match endpoint {
 						ConnectedPoint::Dialer { .. } => "out",
@@ -1728,14 +1731,14 @@ where
 				}
 			},
 			SwarmEvent::NewListenAddr { address, .. } => {
-				trace!(target: "sub-libp2p", "Libp2p => NewListenAddr({})", address);
+				trace!(target: LOG_TARGET, "Libp2p => NewListenAddr({})", address);
 				if let Some(metrics) = self.metrics.as_ref() {
 					metrics.listeners_local_addresses.inc();
 				}
 				self.listen_addresses.lock().insert(address.clone());
 			},
 			SwarmEvent::ExpiredListenAddr { address, .. } => {
-				info!(target: "sub-libp2p", "📪 No longer listening on {}", address);
+				info!(target: LOG_TARGET, "📪 No longer listening on {}", address);
 				if let Some(metrics) = self.metrics.as_ref() {
 					metrics.listeners_local_addresses.dec();
 				}
@@ -1744,7 +1747,7 @@ where
 			SwarmEvent::OutgoingConnectionError { connection_id, peer_id, error } => {
 				if let Some(peer_id) = peer_id {
 					trace!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"Libp2p => Failed to reach {peer_id:?} via {connection_id:?}: {error}",
 					);
 
@@ -1800,10 +1803,10 @@ where
 				}
 			},
 			SwarmEvent::Dialing { connection_id, peer_id } => {
-				trace!(target: "sub-libp2p", "Libp2p => Dialing({peer_id:?}) via {connection_id:?}")
+				trace!(target: LOG_TARGET, "Libp2p => Dialing({peer_id:?}) via {connection_id:?}")
 			},
 			SwarmEvent::IncomingConnection { connection_id, local_addr, send_back_addr } => {
-				trace!(target: "sub-libp2p", "Libp2p => IncomingConnection({local_addr},{send_back_addr} via {connection_id:?}))");
+				trace!(target: LOG_TARGET, "Libp2p => IncomingConnection({local_addr},{send_back_addr} via {connection_id:?}))");
 				if let Some(metrics) = self.metrics.as_ref() {
 					metrics.incoming_connections_total.inc();
 				}
@@ -1815,7 +1818,7 @@ where
 				error,
 			} => {
 				debug!(
-					target: "sub-libp2p",
+					target: LOG_TARGET,
 					"Libp2p => IncomingConnectionError({local_addr},{send_back_addr} via {connection_id:?}): {error}"
 				);
 				if let Some(metrics) = self.metrics.as_ref() {
@@ -1854,37 +1857,37 @@ where
 					addresses.into_iter().map(|a| a.to_string()).collect::<Vec<_>>().join(", ");
 				match reason {
 					Ok(()) => error!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"📪 Libp2p listener ({}) closed gracefully",
 						addrs
 					),
 					Err(e) => error!(
-						target: "sub-libp2p",
+						target: LOG_TARGET,
 						"📪 Libp2p listener ({}) closed: {}",
 						addrs, e
 					),
 				}
 			},
 			SwarmEvent::ListenerError { error, .. } => {
-				debug!(target: "sub-libp2p", "Libp2p => ListenerError: {}", error);
+				debug!(target: LOG_TARGET, "Libp2p => ListenerError: {}", error);
 				if let Some(metrics) = self.metrics.as_ref() {
 					metrics.listeners_errors_total.inc();
 				}
 			},
 			SwarmEvent::NewExternalAddrCandidate { address } => {
-				trace!(target: "sub-libp2p", "Libp2p => NewExternalAddrCandidate: {address:?}");
+				trace!(target: LOG_TARGET, "Libp2p => NewExternalAddrCandidate: {address:?}");
 			},
 			SwarmEvent::ExternalAddrConfirmed { address } => {
-				trace!(target: "sub-libp2p", "Libp2p => ExternalAddrConfirmed: {address:?}");
+				trace!(target: LOG_TARGET, "Libp2p => ExternalAddrConfirmed: {address:?}");
 			},
 			SwarmEvent::ExternalAddrExpired { address } => {
-				trace!(target: "sub-libp2p", "Libp2p => ExternalAddrExpired: {address:?}");
+				trace!(target: LOG_TARGET, "Libp2p => ExternalAddrExpired: {address:?}");
 			},
 			SwarmEvent::NewExternalAddrOfPeer { peer_id, address } => {
-				trace!(target: "sub-libp2p", "Libp2p => NewExternalAddrOfPeer({peer_id:?}): {address:?}")
+				trace!(target: LOG_TARGET, "Libp2p => NewExternalAddrOfPeer({peer_id:?}): {address:?}")
 			},
 			event => {
-				warn!(target: "sub-libp2p", "New unknown SwarmEvent libp2p event: {event:?}");
+				warn!(target: LOG_TARGET, "New unknown SwarmEvent libp2p event: {event:?}");
 			},
 		}
 	}
-- 
GitLab