Skip to content

Commit 411af8b

Browse files
committed
fix(jade): logging macros
1 parent 5b32ed4 commit 411af8b

5 files changed

Lines changed: 67 additions & 103 deletions

File tree

crates/cli/src/bin/cargo-jam.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

crates/jade/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ testing.workspace = true
2727
[features]
2828
default = []
2929
cli = ["dep:cjam"]
30-
std = ["anyhow/std", "codec/std", "serde/std", "service/std"]
3130
logging = []
31+
std = ["anyhow/std", "codec/std", "serde/std", "service/std"]
3232
tiny = []

crates/jade/src/logging.rs

Lines changed: 63 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,64 @@
1-
//! This module is extracted from `jam-pvm-common`
1+
//! This module is extracted from `jam-pvm-common` with fixes
22
3-
#[cfg(any(feature = "logging", doc))]
4-
pub mod stuff {
3+
pub use api::*;
54

6-
/// Log a message with the `error` level. Regular formatting may be used.
7-
#[macro_export]
8-
macro_rules! error {
9-
(target=$target:expr,$($arg:tt)*) => {
10-
$crate::logging::stuff::log_target(0, $target, &$crate::prelude::format!($($arg)*));
11-
};
12-
($($arg:tt)*) => {
13-
$crate::logging::stuff::log(0, &$crate::prelude::format!($($arg)*));
14-
};
15-
}
5+
/// Log a message with the `error` level. Regular formatting may be used.
6+
#[macro_export]
7+
macro_rules! error {
8+
(target=$target:expr,$($arg:tt)*) => {
9+
$crate::logging::log_target(0, $target, &$crate::prelude::format!($($arg)*));
10+
};
11+
($($arg:tt)*) => {
12+
$crate::logging::log(0, &$crate::prelude::format!($($arg)*));
13+
};
14+
}
1615

17-
/// Log a message with the `warn` level. Regular formatting may be used.
18-
#[macro_export]
19-
macro_rules! warn {
20-
(target=$target:expr,$($arg:tt)*) => {
21-
$crate::logging::stuff::log_target(1, $target, &$crate::prelude::format!($($arg)*));
22-
};
23-
($($arg:tt)*) => {
24-
$crate::logging::stuff::log(1, &$crate::prelude::format!($($arg)*));
25-
};
26-
}
16+
/// Log a message with the `warn` level. Regular formatting may be used.
17+
#[macro_export]
18+
macro_rules! warn {
19+
(target=$target:expr,$($arg:tt)*) => {
20+
$crate::logging::log_target(1, $target, &$crate::prelude::format!($($arg)*));
21+
};
22+
($($arg:tt)*) => {
23+
$crate::logging::log(1, &$crate::prelude::format!($($arg)*));
24+
};
25+
}
2726

28-
/// Log a message with the `info` level. Regular formatting may be used.
29-
#[macro_export]
30-
macro_rules! info {
31-
(target=$target:expr,$($arg:tt)*) => {
32-
$crate::logging::stuff::log_target(2, $target, &$crate::prelude::format!($($arg)*));
33-
};
34-
($($arg:tt)*) => {
35-
$crate::logging::stuff::log(2, &$crate::prelude::format!($($arg)*));
36-
};
37-
}
27+
/// Log a message with the `info` level. Regular formatting may be used.
28+
#[macro_export]
29+
macro_rules! info {
30+
(target=$target:expr,$($arg:tt)*) => {
31+
$crate::logging::log_target(2, $target, &$crate::prelude::format!($($arg)*));
32+
};
33+
($($arg:tt)*) => {
34+
$crate::logging::log(2, &$crate::prelude::format!($($arg)*));
35+
};
36+
}
3837

39-
/// Log a message with the `debug` level. Regular formatting may be used.
40-
#[macro_export]
41-
macro_rules! debug {
42-
(target=$target:expr,$($arg:tt)*) => {
43-
$crate::logging::stuff::log_target(3, $target, &$crate::prelude::format!($($arg)*));
44-
};
45-
($($arg:tt)*) => {
46-
$crate::logging::stuff::log(3, &$crate::prelude::format!($($arg)*));
47-
};
48-
}
38+
/// Log a message with the `debug` level. Regular formatting may be used.
39+
#[macro_export]
40+
macro_rules! debug {
41+
(target=$target:expr,$($arg:tt)*) => {
42+
$crate::logging::log_target(3, $target, &$crate::prelude::format!($($arg)*));
43+
};
44+
($($arg:tt)*) => {
45+
$crate::logging::log(3, &$crate::prelude::format!($($arg)*));
46+
};
47+
}
4948

50-
/// Log a message with the `trace` level. Regular formatting may be used.
51-
#[macro_export]
52-
macro_rules! trace {
53-
(target=$target:expr,$($arg:tt)*) => {
54-
$crate::logging::stuff::log_target(4, $target, &$crate::prelude::format!($($arg)*));
55-
};
56-
($($arg:tt)*) => {
57-
$crate::logging::stuff::log(4, &$crate::prelude::format!($($arg)*));
58-
};
59-
}
49+
/// Log a message with the `trace` level. Regular formatting may be used.
50+
#[macro_export]
51+
macro_rules! trace {
52+
(target=$target:expr,$($arg:tt)*) => {
53+
$crate::logging::log_target(4, $target, &$crate::prelude::format!($($arg)*));
54+
};
55+
($($arg:tt)*) => {
56+
$crate::logging::log(4, &$crate::prelude::format!($($arg)*));
57+
};
58+
}
6059

60+
#[cfg(any(feature = "logging", doc))]
61+
mod api {
6162
// CAUTION: Not public API. DO NOT USE.
6263
pub fn log_target(level: u64, target: &str, msg: &str) {
6364
let t = target.as_bytes();
@@ -83,44 +84,14 @@ pub mod stuff {
8384
}
8485

8586
#[cfg(not(any(feature = "logging", doc)))]
86-
pub mod stuff {
87-
/// Log a message with the `error` level. Regular formatting may be used.mod stuff {
88-
#[macro_export]
89-
macro_rules! error {
90-
($($arg:tt)*) => {
91-
{ let _ = ($( $arg, )*); }
92-
};
93-
}
94-
95-
/// Log a message with the `warn` level. Regular formatting may be used.
96-
#[macro_export]
97-
macro_rules! warn {
98-
($($arg:tt)*) => {
99-
{ let _ = ($( $arg, )*); }
100-
};
101-
}
102-
103-
/// Log a message with the `info` level. Regular formatting may be used.
104-
#[macro_export]
105-
macro_rules! info {
106-
($($arg:tt)*) => {
107-
{ let _ = ($( $arg, )*); }
108-
};
109-
}
110-
111-
/// Log a message with the `debug` level. Regular formatting may be used.
112-
#[macro_export]
113-
macro_rules! debug {
114-
($($arg:tt)*) => {
115-
{ let _ = ($( $arg, )*); }
116-
};
117-
}
87+
mod api {
88+
// CAUTION: Not public API. DO NOT USE.
89+
pub fn log_target(level: u64, target: &str, msg: &str) {
90+
let _ = (level, target, msg);
91+
}
11892

119-
/// Log a message with the `trace` level. Regular formatting may be used.
120-
#[macro_export]
121-
macro_rules! trace {
122-
($($arg:tt)*) => {
123-
{ let _ = ($( $arg, )*); }
124-
};
125-
}
93+
// CAUTION: Not public API. DO NOT USE.
94+
pub fn log(level: u64, msg: &str) {
95+
let _ = (level, msg);
96+
}
12697
}

services/nauth/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description = "A JAM authorizer which always authorizes"
1212
tiny = []
1313

1414
[dependencies]
15-
jade = { workspace = true, features = ["logging"] }
15+
jade = { workspace = true }
1616

1717
[build-dependencies]
1818
cjam.workspace = true

services/stoken/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ std = ["codec/std"]
1414

1515
[dependencies]
1616
codec.workspace = true
17-
serde = { workspace = true, features = ["alloc"] }
18-
jade = { workspace = true, features = ["logging"] }
17+
jade.workspace = true
18+
serde.workspace = true
1919

2020
[dev-dependencies]
2121
nauth.workspace = true

0 commit comments

Comments
 (0)