radicle: expose shared logger
To be able to use log setup across the different components of heartwood, expose a `logger` module from `radicle`. This also includes a `test` logger. These modules are guarded behind a `logger` feature flag, so that other crates are not bringing any uneeded dependencies. This allows logging to be setup in `radicle-cli-test` so that when a test fails, the log output is present for debugging purposes. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
f9d9bdf8cd
commit
47a440a384
|
|
@ -2354,6 +2354,8 @@ name = "radicle"
|
|||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"amplify",
|
||||
"chrono",
|
||||
"colored",
|
||||
"crossbeam-channel",
|
||||
"cyphernet",
|
||||
"fastrand",
|
||||
|
|
@ -2430,6 +2432,7 @@ dependencies = [
|
|||
"escargot",
|
||||
"log",
|
||||
"pretty_assertions",
|
||||
"radicle",
|
||||
"shlex",
|
||||
"snapbox",
|
||||
"thiserror",
|
||||
|
|
|
|||
|
|
@ -21,3 +21,8 @@ pretty_assertions = { version = "1.3.0" }
|
|||
shlex = { version = "1.1.0" }
|
||||
snapbox = { version = "0.4.3" }
|
||||
thiserror = { version = "1" }
|
||||
|
||||
[dependencies.radicle]
|
||||
path = "../radicle"
|
||||
version = "0.2.0"
|
||||
features = ["logger", "test"]
|
||||
|
|
|
|||
|
|
@ -192,6 +192,10 @@ impl TestFormula {
|
|||
// We don't need to re-build everytime the `build` function is called. Once is enough.
|
||||
BUILD.call_once(|| {
|
||||
use escargot::format::Message;
|
||||
use radicle::logger::env_level;
|
||||
use radicle::logger::test as logger;
|
||||
|
||||
logger::init(env_level().unwrap_or(log::Level::Debug));
|
||||
|
||||
for (package, binary) in binaries {
|
||||
log::debug!(target: "test", "Building binaries for package `{package}`..");
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ thiserror = { version = "1" }
|
|||
[dependencies.radicle]
|
||||
path = "../radicle"
|
||||
version = "0.2.0"
|
||||
features = ["logger"]
|
||||
|
||||
[dependencies.radicle-fetch]
|
||||
path = "../radicle-fetch"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
pub mod bounded;
|
||||
pub mod control;
|
||||
pub mod deserializer;
|
||||
pub mod logger;
|
||||
pub mod runtime;
|
||||
pub mod service;
|
||||
pub mod signals;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ use std::{env, fs, net, path::PathBuf, process};
|
|||
use anyhow::Context;
|
||||
use crossbeam_channel as chan;
|
||||
|
||||
use radicle::logger;
|
||||
use radicle::prelude::Signer;
|
||||
use radicle::profile;
|
||||
use radicle::version;
|
||||
use radicle_node::crypto::ssh::keystore::{Keystore, MemorySigner};
|
||||
use radicle_node::signals;
|
||||
use radicle_node::Runtime;
|
||||
use radicle_node::{logger, signals};
|
||||
|
||||
pub const NAME: &str = "radicle-node";
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ pub mod arbitrary;
|
|||
pub mod environment;
|
||||
pub mod gossip;
|
||||
pub mod handle;
|
||||
pub mod logger;
|
||||
pub mod peer;
|
||||
pub mod simulator;
|
||||
|
||||
pub use radicle::assert_matches;
|
||||
pub use radicle::logger::test as logger;
|
||||
pub use radicle::test::*;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ edition = "2021"
|
|||
[features]
|
||||
default = []
|
||||
test = ["qcheck", "radicle-crypto/test"]
|
||||
logger = ["colored", "chrono"]
|
||||
|
||||
[dependencies]
|
||||
amplify = { version = "4.0.0", default-features = false, features = ["std"] }
|
||||
|
|
@ -31,6 +32,16 @@ tempfile = { version = "3.3.0" }
|
|||
thiserror = { version = "1" }
|
||||
unicode-normalization = { version = "0.1" }
|
||||
|
||||
[dependencies.chrono]
|
||||
version = "0.4.0"
|
||||
default-features = false
|
||||
features = ["clock"]
|
||||
optional = true
|
||||
|
||||
[dependencies.colored]
|
||||
version = "1.9.0"
|
||||
optional = true
|
||||
|
||||
[dependencies.git2]
|
||||
version = "0.18.1"
|
||||
default-features = false
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ pub mod cob;
|
|||
pub mod collections;
|
||||
pub mod git;
|
||||
pub mod identity;
|
||||
#[cfg(feature = "logger")]
|
||||
pub mod logger;
|
||||
pub mod node;
|
||||
pub mod profile;
|
||||
pub mod rad;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
//! Logging module.
|
||||
//!
|
||||
//! For test logging see [`test`].
|
||||
|
||||
#[cfg(feature = "test")]
|
||||
pub mod test;
|
||||
|
||||
use std::io::{self, Write};
|
||||
|
||||
use chrono::prelude::*;
|
||||
|
|
@ -55,3 +61,10 @@ pub fn init(level: Level) -> Result<(), SetLoggerError> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the level set by the environment variable `RUST_LOG`, if
|
||||
/// present.
|
||||
pub fn env_level() -> Option<Level> {
|
||||
let level = std::env::var("RUST_LOG").ok()?;
|
||||
level.parse().ok()
|
||||
}
|
||||
Loading…
Reference in New Issue