Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: Add `log` to node config
cloudhead committed 2 years ago
commit b31fbde1593f0a24b5b9f75f89e3d1593934fc15
parent 0b816d5c8662df961da19e1faabc126a9e7b536f
4 files changed +18 -7
modified radicle-cli/examples/rad-config.md
@@ -28,6 +28,7 @@ $ rad config
    "externalAddresses": [],
    "tor": null,
    "network": "main",
+
    "log": "INFO",
    "relay": true,
    "limits": {
      "routingMaxSize": 1000,
modified radicle-httpd/src/api/v1/profile.rs
@@ -91,6 +91,7 @@ mod routes {
                  "externalAddresses": [],
                  "tor": null,
                  "network": "main",
+
                  "log": "INFO",
                  "relay": true,
                  "limits": {
                    "routingMaxSize": 1000,
modified radicle-node/src/main.rs
@@ -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);

modified radicle/src/node/config.rs
@@ -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
+
    }
}