node: Add `log` to node config

This commit is contained in:
cloudhead 2024-04-29 15:59:17 +02:00
parent 0b816d5c86
commit b31fbde159
No known key found for this signature in database
4 changed files with 18 additions and 7 deletions

View File

@ -28,6 +28,7 @@ $ rad config
"externalAddresses": [],
"tor": null,
"network": "main",
"log": "INFO",
"relay": true,
"limits": {
"routingMaxSize": 1000,

View File

@ -91,6 +91,7 @@ mod routes {
"externalAddresses": [],
"tor": null,
"network": "main",
"log": "INFO",
"relay": true,
"limits": {
"routingMaxSize": 1000,

View File

@ -41,7 +41,7 @@ Options
struct Options {
config: Option<PathBuf>,
listen: Vec<net::SocketAddr>,
log: log::Level,
log: Option<log::Level>,
force: bool,
}
@ -53,7 +53,7 @@ impl Options {
let mut listen = Vec::new();
let mut config = None;
let mut force = false;
let mut log = log::Level::Info;
let mut log = None;
while let Some(arg) = parser.next()? {
match arg {
@ -70,7 +70,7 @@ impl Options {
listen.push(addr);
}
Long("log") => {
log = parser.value()?.parse()?;
log = Some(parser.value()?.parse()?);
}
Long("help") | Short('h') => {
println!("{HELP_MSG}");
@ -96,8 +96,10 @@ impl Options {
fn execute() -> anyhow::Result<()> {
let home = profile::home()?;
let options = Options::from_env()?;
let config = options.config.unwrap_or_else(|| home.config());
let mut config = profile::Config::load(&config)?;
logger::init(options.log)?;
logger::init(options.log.unwrap_or(config.node.log))?;
log::info!(target: "node", "Starting node..");
log::info!(target: "node", "Version {} ({})", env!("RADICLE_VERSION"), env!("GIT_HEAD"));
@ -109,9 +111,6 @@ fn execute() -> anyhow::Result<()> {
log::info!(target: "node", "Node ID is {}", signer.public_key());
let config = options.config.unwrap_or_else(|| home.config());
let mut config = profile::Config::load(&config)?;
// Add the preferred seeds as persistent peers so that we reconnect to them automatically.
config.node.connect.extend(config.preferred_seeds);

View File

@ -272,6 +272,10 @@ pub struct Config {
/// Peer-to-peer network.
#[serde(default)]
pub network: Network,
/// Log level.
#[serde(default = "defaults::log")]
#[serde(with = "crate::serde_ext::string")]
pub log: log::Level,
/// Whether or not our node should relay inventories.
#[serde(default = "crate::serde_ext::bool::yes")]
pub relay: bool,
@ -309,6 +313,7 @@ impl Config {
relay: true,
limits: Limits::default(),
workers: DEFAULT_WORKERS,
log: defaults::log(),
policy: Policy::default(),
scope: Scope::default(),
}
@ -336,4 +341,9 @@ mod defaults {
pub fn workers() -> usize {
super::DEFAULT_WORKERS
}
/// Log level.
pub fn log() -> log::Level {
log::Level::Info
}
}