mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-13 06:50:47 +08:00
The main dependant of `radicle-git`, and its crates, is [`heartwood`]. It is licensed under MIT or Apache-2.0, which has been incompatible with the GPL-3.0 license. Since the intellectual property of this code base is with the Better Internet Foundation, it was decided to re-license code in this repository to make the upstream repository compatible. - Remove the license headers (and instructions to add them) - Add MIT and Apache-2.0 licenses - Remove the GPL-3.0 license - Change the license declarations in the `Cargo.toml` files [`heartwood`]: https://app.radicle.xyz/nodes/seed.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
52 lines
2.0 KiB
Rust
52 lines
2.0 KiB
Rust
use std::env;
|
|
|
|
use log::{log_enabled, Level};
|
|
use tracing::subscriber::set_global_default as set_subscriber;
|
|
use tracing_subscriber::{EnvFilter, FmtSubscriber};
|
|
|
|
/// Initialise logging / tracing
|
|
///
|
|
/// Note that this will capture logs, so they can be output as part of the test
|
|
/// output. Use `RUST_LOG` with care, as this may create unwanted memory
|
|
/// pressure. Note, however, that if `RUST_LOG` is not set, we set the level to
|
|
/// `error` by default in order to surface errors on CI.
|
|
///
|
|
/// The `TRACING_FMT` environment variable can be used to control the log
|
|
/// formatting. Supported values:
|
|
///
|
|
/// * "pretty": [`tracing_subscriber::fmt::format::Pretty`]
|
|
/// * "compact": [`tracing_subscriber::fmt::format::Compact`]
|
|
/// * "json": [`tracing_subscriber::fmt::format::Json`]
|
|
///
|
|
/// If the variable is not set, or set to any other value, the
|
|
/// [`tracing_subscriber::fmt::format::Full`] format is used.
|
|
pub fn init() {
|
|
if env_logger::builder().is_test(true).try_init().is_ok() {
|
|
if env::var("RUST_LOG").is_err() {
|
|
env::set_var("RUST_LOG", "debug");
|
|
}
|
|
|
|
let mut builder = FmtSubscriber::builder()
|
|
.with_env_filter(EnvFilter::from_default_env())
|
|
.with_test_writer();
|
|
if log_enabled!(target: "librad", Level::Trace) {
|
|
builder = builder.with_thread_ids(true);
|
|
} else if env::var("TRACING_FMT").is_err() {
|
|
let default_format = if env::var("CI").is_ok() {
|
|
"compact"
|
|
} else {
|
|
"pretty"
|
|
};
|
|
env::set_var("TRACING_FMT", default_format);
|
|
}
|
|
|
|
match env::var("TRACING_FMT").ok().as_deref() {
|
|
Some("pretty") => set_subscriber(builder.pretty().finish()),
|
|
Some("compact") => set_subscriber(builder.compact().finish()),
|
|
Some("json") => set_subscriber(builder.json().flatten_event(true).finish()),
|
|
_ => set_subscriber(builder.finish()),
|
|
}
|
|
.expect("setting tracing subscriber failed")
|
|
}
|
|
}
|