node: Update logging config

Promote message logging to `debug` level, and change default level to
`info`.

This is because `trace` level often covers details at a different level
of detail than for eg. messages sent and received. This means we don't
have to use `trace` level just to see the gossip.
This commit is contained in:
cloudhead 2024-03-22 13:51:21 +01:00
parent 33be2a62da
commit 474df7fc3c
No known key found for this signature in database
2 changed files with 19 additions and 8 deletions

View File

@ -32,6 +32,7 @@ Options
--config <path> Config file to use (default ~/.radicle/config.json) --config <path> Config file to use (default ~/.radicle/config.json)
--force Force start even if an existing control socket is found --force Force start even if an existing control socket is found
--listen <address> Address to listen on --listen <address> Address to listen on
--log <level> Set log level (default: info)
--version Print program version --version Print program version
--help Print help --help Print help
"#; "#;
@ -40,6 +41,7 @@ Options
struct Options { struct Options {
config: Option<PathBuf>, config: Option<PathBuf>,
listen: Vec<net::SocketAddr>, listen: Vec<net::SocketAddr>,
log: log::Level,
force: bool, force: bool,
} }
@ -51,6 +53,7 @@ impl Options {
let mut listen = Vec::new(); let mut listen = Vec::new();
let mut config = None; let mut config = None;
let mut force = false; let mut force = false;
let mut log = log::Level::Info;
while let Some(arg) = parser.next()? { while let Some(arg) = parser.next()? {
match arg { match arg {
@ -66,6 +69,9 @@ impl Options {
let addr = parser.value()?.parse()?; let addr = parser.value()?.parse()?;
listen.push(addr); listen.push(addr);
} }
Long("log") => {
log = parser.value()?.parse()?;
}
Long("help") | Short('h') => { Long("help") | Short('h') => {
println!("{HELP_MSG}"); println!("{HELP_MSG}");
process::exit(0); process::exit(0);
@ -81,17 +87,18 @@ impl Options {
Ok(Self { Ok(Self {
force, force,
listen, listen,
log,
config, config,
}) })
} }
} }
fn execute() -> anyhow::Result<()> { fn execute() -> anyhow::Result<()> {
logger::init(log::Level::Debug)?;
let home = profile::home()?; let home = profile::home()?;
let options = Options::from_env()?; let options = Options::from_env()?;
logger::init(options.log)?;
log::info!(target: "node", "Starting node.."); log::info!(target: "node", "Starting node..");
log::info!(target: "node", "Version {} ({})", env!("CARGO_PKG_VERSION"), env!("GIT_HEAD")); log::info!(target: "node", "Version {} ({})", env!("CARGO_PKG_VERSION"), env!("GIT_HEAD"));
log::info!(target: "node", "Unlocking node keystore.."); log::info!(target: "node", "Unlocking node keystore..");

View File

@ -942,10 +942,14 @@ where
namespaces, namespaces,
clone, clone,
}) => { }) => {
debug!(target: "service", "Fetched {rid} from {remote} successfully"); info!(target: "service", "Fetched {rid} from {remote} successfully");
for update in &updated { for update in &updated {
debug!(target: "service", "Ref updated: {update} for {rid}"); if update.old() != update.new() {
debug!(target: "service", "Ref updated: {update} for {rid}");
} else {
trace!(target: "service", "Ref skipped: {update} for {rid}");
}
} }
self.emitter.emit(Event::RefsFetched { self.emitter.emit(Event::RefsFetched {
remote, remote,
@ -1100,7 +1104,7 @@ where
} }
pub fn listening(&mut self, local_addr: net::SocketAddr) { pub fn listening(&mut self, local_addr: net::SocketAddr) {
log::info!(target: "node", "Listening on {local_addr}.."); info!(target: "node", "Listening on {local_addr}..");
self.listening.push(local_addr); self.listening.push(local_addr);
} }
@ -1147,7 +1151,7 @@ where
pub fn disconnected(&mut self, remote: NodeId, reason: &DisconnectReason) { pub fn disconnected(&mut self, remote: NodeId, reason: &DisconnectReason) {
let since = self.local_time(); let since = self.local_time();
debug!(target: "service", "Disconnected from {} ({})", remote, reason); info!(target: "service", "Disconnected from {} ({})", remote, reason);
self.emitter.emit(Event::PeerDisconnected { self.emitter.emit(Event::PeerDisconnected {
nid: remote, nid: remote,
reason: reason.to_string(), reason: reason.to_string(),
@ -1296,7 +1300,7 @@ where
match self.db.gossip_mut().announced(announcer, announcement) { match self.db.gossip_mut().announced(announcer, announcement) {
Ok(fresh) => { Ok(fresh) => {
if !fresh { if !fresh {
trace!(target: "service", "Ignoring stale announcement from {announcer} (t={})", self.time()); debug!(target: "service", "Ignoring stale announcement from {announcer} (t={})", self.time());
return Ok(false); return Ok(false);
} }
} }
@ -1617,7 +1621,7 @@ where
trace!(target: "service", "Rate limiting message from {remote} ({})", peer.addr); trace!(target: "service", "Rate limiting message from {remote} ({})", peer.addr);
return Ok(()); return Ok(());
} }
message.log(log::Level::Trace, remote, Link::Inbound); message.log(log::Level::Debug, remote, Link::Inbound);
trace!(target: "service", "Received message {:?} from {}", &message, peer.id); trace!(target: "service", "Received message {:?} from {}", &message, peer.id);