mirror of
https://github.com/trussed-dev/delog.git
synced 2026-06-20 04:16:34 -07:00
Towards "default local" logging macros
This commit is contained in:
+5
-6
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "delog"
|
||||
version = "0.1.0-alpha.1"
|
||||
description = "Deferred logging, an implementation and extension of `log`"
|
||||
description = "Deferred logging, an implementation and extension of Rust's standard logging facade."
|
||||
authors = ["Nicolas Stalder <n@stalder.io>"]
|
||||
license = "Apache-2.0 OR MIT"
|
||||
repository = "https://github.com/nickray/delog"
|
||||
@@ -12,7 +12,7 @@ keywords = ["log", "logging", "formatting"]
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
features = ["example"]
|
||||
targets = []
|
||||
|
||||
[dependencies]
|
||||
@@ -26,9 +26,8 @@ insta = "1.3.0"
|
||||
|
||||
[features]
|
||||
default = ["fallible", "immediate"]
|
||||
std = []
|
||||
example = ["std", "flushers"]
|
||||
flushers = []
|
||||
semihosting = ["cortex-m-semihosting"]
|
||||
fallible = []
|
||||
immediate = []
|
||||
example = ["std-example-flushers"]
|
||||
semihosting-example-flushers = ["cortex-m-semihosting"]
|
||||
std-example-flushers = []
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
test: non-qemu-tests qemu-tests
|
||||
|
||||
non-qemu-tests:
|
||||
non-qemu-tests: simple-tests delog-examples gate-tests
|
||||
|
||||
simple-tests:
|
||||
cargo test --lib
|
||||
cargo test --doc
|
||||
cargo test --examples --features flushers,std
|
||||
cargo test --examples
|
||||
|
||||
.PHONY: delog-examples
|
||||
delog-examples:
|
||||
$(MAKE) -C delog-examples run
|
||||
|
||||
.PHONY: gate-tests
|
||||
gate-tests:
|
||||
$(MAKE) -C gate-tests
|
||||
|
||||
.PHONY: qemu-tests
|
||||
qemu-tests:
|
||||
$(MAKE) -C qemu-tests test
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "examples"
|
||||
version = "0.1.0"
|
||||
authors = ["Nicolas Stalder <n@stalder.io>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies.delog]
|
||||
path = ".."
|
||||
features = ["std-example-flushers"]
|
||||
|
||||
[features]
|
||||
default = ["log-all"]
|
||||
log-none = []
|
||||
log-all = []
|
||||
@@ -0,0 +1,5 @@
|
||||
run:
|
||||
cargo run --example log
|
||||
cargo run --example try-log
|
||||
cargo run --example try-log --features log-none
|
||||
cargo run --example around
|
||||
@@ -0,0 +1,9 @@
|
||||
# delog-examples
|
||||
|
||||
While it's possible to have multi-file examples, the usual examples mechanism
|
||||
in `cargo` does not support defining features (we need to set a subset of the `log-*`
|
||||
features to see output from the "local" logging macros), not requiring features
|
||||
(for convenience, we use the `std-example-flushers` feature).
|
||||
|
||||
So this is a "library" that sets things up, apart from that the examples here
|
||||
have the same role as normal examples for `delog` would have.
|
||||
@@ -1,8 +1,7 @@
|
||||
#[macro_use]
|
||||
extern crate delog;
|
||||
|
||||
#[cfg(not(all(feature = "flushers", feature = "std")))]
|
||||
compile_error!("This example needs the `flushers` and `std` features");
|
||||
use delog::upstream::info;
|
||||
|
||||
use delog::flushers::StdoutFlusher;
|
||||
|
||||
@@ -11,10 +10,11 @@ delog!(Delogger, 25, StdoutFlusher);
|
||||
static STDOUT_FLUSHER: StdoutFlusher = StdoutFlusher {};
|
||||
|
||||
fn main() {
|
||||
Delogger::init(log::LevelFilter::Info, &STDOUT_FLUSHER).ok();
|
||||
Delogger::init_default(delog::LevelFilter::Info, &STDOUT_FLUSHER).ok();
|
||||
|
||||
let msg = "1234567890";
|
||||
|
||||
// this logs more than fits the buffer
|
||||
(0..10).for_each(|_| {
|
||||
info!("{}", msg);
|
||||
Delogger::flush();
|
||||
@@ -1,17 +1,15 @@
|
||||
#[macro_use]
|
||||
extern crate delog;
|
||||
|
||||
#[cfg(not(all(feature = "flushers", feature = "std")))]
|
||||
compile_error!("This example needs the `flushers` and `std` features");
|
||||
|
||||
use delog::flushers::StdoutFlusher;
|
||||
|
||||
delog!(Delogger, 256, StdoutFlusher);
|
||||
local_macros!();
|
||||
|
||||
static STDOUT_FLUSHER: StdoutFlusher = StdoutFlusher {};
|
||||
static FLUSHER: StdoutFlusher = StdoutFlusher {};
|
||||
|
||||
fn main() {
|
||||
Delogger::init(log::LevelFilter::Info, &STDOUT_FLUSHER).ok();
|
||||
Delogger::init_default(delog::LevelFilter::Info, &FLUSHER).ok();
|
||||
|
||||
// do some serious work
|
||||
warn!("This is a warning");
|
||||
@@ -0,0 +1,37 @@
|
||||
#[macro_use]
|
||||
extern crate delog;
|
||||
|
||||
use delog::flushers::StdoutFlusher;
|
||||
use delog::renderers::RipgrepRenderer;
|
||||
delog!(Delogger, 196, StdoutFlusher, renderer: RipgrepRenderer);
|
||||
local_macros!();
|
||||
|
||||
static STDOUT_FLUSHER: StdoutFlusher = StdoutFlusher {};
|
||||
static RENDERER: RipgrepRenderer = RipgrepRenderer {};
|
||||
|
||||
fn main() {
|
||||
Delogger::init(delog::LevelFilter::Info, &STDOUT_FLUSHER, &RENDERER).ok();
|
||||
|
||||
// do some serious work
|
||||
global_try_warn!("This is a warning").unwrap();
|
||||
global_try_info!("This is information").unwrap();
|
||||
global_try_warn!("This is a warning").unwrap();
|
||||
global_try_info!("This is information").expect_err("should error out due to incapacity");
|
||||
|
||||
// flush the logs
|
||||
Delogger::flush();
|
||||
|
||||
println!("===");
|
||||
|
||||
try_warn!("This is a warning").unwrap();
|
||||
try_info!("This is information").unwrap();
|
||||
try_warn!(target: "!", "This is a warning").unwrap();
|
||||
try_warn!("This is a warning").unwrap();
|
||||
#[cfg(not(feature = "log-none"))]
|
||||
try_info!("This is information").expect_err("should error out due to incapacity");
|
||||
#[cfg(feature = "log-none")]
|
||||
try_info!("This is information").ok();
|
||||
|
||||
// flush the logs
|
||||
Delogger::flush();
|
||||
}
|
||||
+6
-9
@@ -1,13 +1,10 @@
|
||||
use delog::hex::*;
|
||||
use delog::hex_str;
|
||||
|
||||
// these examples are also `insta` tests,
|
||||
// see <src/snapshots> for expected outputs
|
||||
fn main() {
|
||||
let buf = [1u8, 2, 3, 0xA1, 0xB7, 0xFF, 0x3];
|
||||
println!("'{:02X}'", hex_str_1(&buf));
|
||||
println!("'{:02X}'", hex_str_2(&buf));
|
||||
println!("'{:02x}'", delog::hex_str!(&buf, 2));
|
||||
println!("'{:02X}'", hex_str_4(&buf));
|
||||
println!("'{:02X}'", hex_str_4(&buf[..]));
|
||||
println!("'{:X}'", hex_str_4(&buf));
|
||||
println!("'{}'", hex_str!(&buf));
|
||||
println!("'{}'", hex_str!(&buf, 2));
|
||||
println!("'{:02x}'", hex_str!(&buf, 2));
|
||||
println!("'{}'", hex_str!(&buf, 4));
|
||||
println!("'{}'", hex_str!(&buf[..], 4));
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
use delog::{try_info, try_warn};
|
||||
|
||||
#[cfg(not(all(feature = "flushers", feature = "std")))]
|
||||
compile_error!("This example needs the `flushers` and `std` features");
|
||||
|
||||
use delog::flushers::StdoutFlusher;
|
||||
|
||||
delog::delog!(Delogger, 64, StdoutFlusher);
|
||||
|
||||
static STDOUT_FLUSHER: StdoutFlusher = StdoutFlusher {};
|
||||
|
||||
fn main() {
|
||||
Delogger::init(log::LevelFilter::Info, &STDOUT_FLUSHER).ok();
|
||||
|
||||
// do some serious work
|
||||
try_warn!("This is a warning").unwrap();
|
||||
try_info!("This is information").unwrap();
|
||||
try_warn!("This is a warning").unwrap();
|
||||
try_info!("This is information").expect_err("should error out due to incapacity");
|
||||
|
||||
// flush the logs
|
||||
Delogger::flush();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
cfg-if = "1"
|
||||
|
||||
[dependencies.lib-a]
|
||||
path = "lib-a"
|
||||
|
||||
@@ -14,5 +17,8 @@ path = "lib-b"
|
||||
|
||||
[dependencies.delog]
|
||||
path = ".."
|
||||
features = ["std", "flushers"]
|
||||
features = ["std-example-flushers"]
|
||||
|
||||
[features]
|
||||
default = ["verbose-renderer"]
|
||||
verbose-renderer = []
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
something:
|
||||
cargo run
|
||||
cargo run --no-default-features --features lib-a/log-all,lib-b/log-all
|
||||
cargo run --features lib-a/log-all,lib-b/log-all
|
||||
cargo run --features lib-a/log-all
|
||||
cargo run --features lib-b/log-all
|
||||
|
||||
@@ -6,7 +6,6 @@ edition = "2018"
|
||||
|
||||
[dependencies.delog]
|
||||
path = "../.."
|
||||
features = ["std"]
|
||||
|
||||
[features]
|
||||
log-error = []
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
#[macro_use]
|
||||
extern crate delog;
|
||||
|
||||
local_delog!();
|
||||
delog::local_macros!();
|
||||
|
||||
pub fn f() {
|
||||
info!("global info log from lib_a");
|
||||
warn!("global info log from lib_a");
|
||||
|
||||
local_log!(delog::Level::Info, "log level info from lib_a::f");
|
||||
local_log!(target: "!", delog::Level::Info, "log level info from lib_a::f");
|
||||
local_log!(target: "!", delog::Level::Warn, "log level warn from lib_a::f");
|
||||
log!(delog::Level::Info, "log level info from lib_a::f");
|
||||
log!(target: "!", delog::Level::Info, "log level info from lib_a::f");
|
||||
log!(target: "!", delog::Level::Warn, "log level warn from lib_a::f");
|
||||
|
||||
local_info!("local info from lib_a::f");
|
||||
local_warn!("local warn from lib_a::f");
|
||||
local_info!(target: "!", "immediate local info from lib_a::f");
|
||||
local_warn!(target: "!", "immediate local warn from lib_a::f");
|
||||
info!("local info from lib_a::f");
|
||||
warn!("local warn from lib_a::f");
|
||||
info!(target: "!", "immediate local info from lib_a::f");
|
||||
warn!(target: "!", "immediate local warn from lib_a::f");
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ edition = "2018"
|
||||
|
||||
[dependencies.delog]
|
||||
path = "../.."
|
||||
features = ["std"]
|
||||
|
||||
[features]
|
||||
# default = ["log-warn"]
|
||||
|
||||
+12
-13
@@ -1,18 +1,17 @@
|
||||
#[macro_use]
|
||||
extern crate delog;
|
||||
|
||||
local_delog!();
|
||||
delog::local_macros!();
|
||||
|
||||
pub fn g() {
|
||||
info!("global info log from lib-b");
|
||||
warn!("global info log from lib-b");
|
||||
delog::upstream::info!("global info from B");
|
||||
warn!("info from B");
|
||||
|
||||
local_log!(delog::Level::Info, "log level info from lib_b::g");
|
||||
local_log!(target: "!", delog::Level::Info, "log level info from lib_b::g");
|
||||
local_log!(target: "!", delog::Level::Warn, "log level warn from lib_b::g");
|
||||
log!(delog::Level::Info, "log level info from B");
|
||||
log!(target: "!", delog::Level::Info, "info from B");
|
||||
log!(target: "!", delog::Level::Warn, "warn from B");
|
||||
|
||||
local_info!("local info from lib_b::g");
|
||||
local_warn!("local warn from lib_b::g");
|
||||
local_info!(target: "!", "immediate local info from lib_b::g");
|
||||
local_warn!(target: "!", "immediate local warn from lib_b::g");
|
||||
info!("info from B");
|
||||
warn!("warn from B");
|
||||
error!("error from B");
|
||||
error!("another error from B");
|
||||
info!(target: "!", "immediate local info from B");
|
||||
warn!(target: "!", "immediate local warn from B");
|
||||
}
|
||||
|
||||
+12
-2
@@ -3,12 +3,22 @@ extern crate delog;
|
||||
|
||||
use delog::flushers::StdoutFlusher;
|
||||
|
||||
delog!(Delogger, 4096, StdoutFlusher);
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "verbose-renderer")] {
|
||||
use delog::renderers::RipgrepRenderer;
|
||||
delog!(Delogger, 4096, StdoutFlusher, renderer: RipgrepRenderer);
|
||||
static RENDERER: RipgrepRenderer = RipgrepRenderer {};
|
||||
} else {
|
||||
use delog::renderers::ArgumentsRenderer;
|
||||
delog!(Delogger, 4096, StdoutFlusher);
|
||||
static RENDERER: ArgumentsRenderer = ArgumentsRenderer {};
|
||||
}
|
||||
}
|
||||
|
||||
static FLUSHER: StdoutFlusher = StdoutFlusher {};
|
||||
|
||||
fn main() {
|
||||
Delogger::init(delog::LevelFilter::Info, &FLUSHER).expect("all good");
|
||||
Delogger::init(delog::LevelFilter::Info, &FLUSHER, &RENDERER).expect("all good");
|
||||
lib_a::f();
|
||||
lib_b::g();
|
||||
println!("{:?}", delog::trylogger().unwrap().statistics());
|
||||
|
||||
@@ -7,13 +7,19 @@ description = "Test salty using QEMU musca-b1"
|
||||
license = "Apache-2.0 OR MIT"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.6.1"
|
||||
cortex-m = "0.6.0"
|
||||
cortex-m-rt = "0.6.10"
|
||||
cortex-m-semihosting = "0.3.5"
|
||||
panic-semihosting = { version = "0.5.3", features = ["exit"] }
|
||||
|
||||
[dependencies.delog]
|
||||
path = ".."
|
||||
features = ["semihosting-example-flushers"]
|
||||
|
||||
[features]
|
||||
default = ["log-all"]
|
||||
log-all = []
|
||||
log-none = []
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
main-test:
|
||||
cargo run --release
|
||||
cargo run --release --features log-none
|
||||
|
||||
test:
|
||||
@echo "\nTesting debug build\n"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user