Runtime logging. (#3821)

* Implement Printable for tuples.

* Add debugging function.

* Add debug 1.

* Implement  for everything.

* RuntimeDebug derive.

* Introduce RuntimeDebug.

* Add some dummy logging.

* Replace RuntimeDebug with Debug.

* Revert "Replace RuntimeDebug with Debug."

This reverts commit bc47070a8cb30241b2b590b2fa29fd195088162f.

* Working on Debug for all.

* Fix bounds.

* Add debug utils.

* Implement runtime logging.

* Add some docs and clean up.

* Clean up derives.

* Fix custom derive impl.

* Bump runtime.

* Fix long lines.

* Fix doc test.

* Use CARGO_CFG_STD.

* Revert "Use CARGO_CFG_STD."

This reverts commit ea429566de18ed0fa052571b359eb9826a64a9f4.

* Use parse_macro_input

* Update lockfile.

* Apply review suggestions.

* Remove stray re-export.

* Add no-std impl.

* Update lockfile.
This commit is contained in:
Tomasz Drwięga
2019-10-22 14:13:44 +02:00
committed by Bastian Köcher
parent 934d7aac1c
commit 20a3989785
86 changed files with 1266 additions and 469 deletions
+4 -2
View File
@@ -9,15 +9,16 @@ edition = "2018"
rustc_version = "0.2.3"
[dependencies]
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false }
hash-db = { version = "0.15.2", default-features = false }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
libsecp256k1 = { version = "0.3.0", optional = true }
tiny-keccak = { version = "1.5.0", optional = true }
substrate-state-machine = { path = "../state-machine", optional = true }
trie = { package = "substrate-trie", path = "../trie", optional = true }
externalities = { package = "substrate-externalities", path = "../externalities", optional = true }
log = { version = "0.4.8", optional = true }
[features]
default = ["std"]
@@ -31,6 +32,7 @@ std = [
"libsecp256k1",
"tiny-keccak",
"externalities",
"log",
]
nightly = []
strict = []
+15
View File
@@ -33,6 +33,7 @@ use primitives::{
offchain::{
Timestamp, HttpRequestId, HttpRequestStatus, HttpError, StorageKind, OpaqueNetworkState,
},
LogLevel,
};
/// Error verifying ECDSA signature
@@ -158,6 +159,20 @@ export_api! {
fn print_utf8(utf8: &[u8]);
/// Print any `u8` slice as hex.
fn print_hex(data: &[u8]);
/// Request to print a log message (stderr) on the host.
///
/// Note that this will be only displayed if the host
/// is enabed to display log messages with given
/// level and target.
///
/// Instead of using directly, prefer setting up `RuntimeLogger`
/// and using `log` macros.
fn log(
level: LogLevel,
target: &[u8],
message: &[u8]
);
}
}
+16
View File
@@ -192,6 +192,22 @@ impl OtherApi for () {
fn print_hex(data: &[u8]) {
println!("{}", HexDisplay::from(&data));
}
fn log(
level: LogLevel,
target: &[u8],
message: &[u8],
) {
let target = std::str::from_utf8(target).unwrap_or("invalid utf8");
let msg = std::str::from_utf8(message).unwrap_or("invalid utf8");
log::log!(
target: target,
log::Level::from(level),
"{}",
msg,
)
}
}
impl CryptoApi for () {
+24
View File
@@ -160,6 +160,14 @@ pub mod ext {
fn ext_print_hex(data: *const u8, len: u32);
/// Print a number
fn ext_print_num(value: u64);
/// Print a log line if logging for given level and target is enabled.
fn ext_log(
level: u32,
target_data: *const u8,
target_len: u32,
message_data: *const u8,
message_len: u32,
);
/// Set value for key in storage.
fn ext_set_storage(key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32);
@@ -780,6 +788,22 @@ impl OtherApi for () {
ext_print_hex.get()(data.as_ptr(), data.len() as u32);
}
}
fn log(
level: LogLevel,
target: &[u8],
message: &[u8]
) {
unsafe {
ext_log.get()(
level as u32,
target.as_ptr(),
target.len() as u32,
message.as_ptr(),
message.len() as u32,
)
}
}
}
impl HashingApi for () {