message: [network] Make NetworkContext serialize consistently
  NetworkContext wasn't serializing Private networks into a single string
  like it would for validator and public networks.  Now, it'll serialize
  them all into a string for logs.
  Closes:
diff: // SPDX-License-Identifier: Apache-2.0
  use crate::config::RoleType;
  use libra_types::PeerId;
  -use serde::{Deserialize, Serialize};
  +use serde::{Deserialize, Serialize, Serializer};
  use std::fmt;
  /// A grouping of common information between all networking code for logging.
  @@ -10,6 +10,7 @@ use std::fmt;
  /// for logging accordingly.
  #[derive(Clone, Eq, PartialEq, Serialize)]
  pub struct NetworkContext {
  + #[serde(serialize_with = "NetworkId::serialize_str")]
  network_id: NetworkId,
  role: RoleType,
  peer_id: PeerId,
  @@ -26,7 +27,7 @@ impl fmt::Display for NetworkContext {
  write!(
  f,
  "[{},{},{}]",
  - self.network_id,
  + self.network_id.as_str(),
  self.role,
  self.peer_id.short_str(),
  )
  @@ -153,6 +154,13 @@ impl NetworkId {
  NetworkId::Private(info) => info.as_ref(),
  }
  }
  +
  + fn serialize_str<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
  + where
  + S: Serializer,
  + {
  + self.as_str().serialize(serializer)
  + }
  }
  #[cfg(test)]
  @@ -177,4 +185,17 @@ mod test {
  let decoded: NetworkId = serde_yaml::from_slice(encoded.as_slice()).unwrap();
  assert_eq!(id, decoded);
  }
  +
  + #[test]
  + fn test_network_context_serialization() {
  + let network_name = "Awesome".to_string();
  + let role = RoleType::Validator;
  + let peer_id = PeerId::random();
  + let context = NetworkContext::new(NetworkId::Private(network_name.clone()), role, peer_id);
  + let expected = format!(
  + "---\nnetwork_id: {}\nrole: {}\npeer_id: {}",
  + network_name, role, peer_id
  + );
  + assert_eq!(expected, serde_yaml::to_string(&context).unwrap());
  + }
  }
  