mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Init RuntimeLogger automatically for each runtime api call (#8128)
* Init `RuntimeLogger` automatically for each runtime api call This pr change the runtime api in such a way to always and automatically enable the `RuntimeLogger`. This enables the user to use `log` or `tracing` from inside the runtime to create log messages. As logging introduces some extra code and especially increases the size of the wasm blob. It is advised to disable all logging completely with `sp-api/disable-logging` when doing the wasm builds for the on-chain wasm runtime. Besides these changes, the pr also brings most of the logging found in frame to the same format "runtime::*". * Update frame/im-online/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update test-utils/runtime/Cargo.toml * Fix test * Don't use tracing in the runtime, as we don't support it :D * Fixes Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -30,6 +30,19 @@
|
||||
//! api, the [`ApiExt`] trait, the [`CallApiAt`] trait and the [`ConstructRuntimeApi`] trait.
|
||||
//!
|
||||
//! On a meta level this implies, the client calls the generated API from the client perspective.
|
||||
//!
|
||||
//!
|
||||
//! # Logging
|
||||
//!
|
||||
//! Substrate supports logging from the runtime in native and in wasm. For that purpose it provides
|
||||
//! the [`RuntimeLogger`](sp_runtime::runtime_logger::RuntimeLogger). This runtime logger is
|
||||
//! automatically enabled for each call into the runtime through the runtime api. As logging
|
||||
//! introduces extra code that isn't actually required for the logic of your runtime and also
|
||||
//! increases the final wasm blob size, it is recommended to disable the logging for on-chain
|
||||
//! wasm blobs. This can be done by enabling the `disable-logging` feature of this crate. Be aware
|
||||
//! that this feature instructs `log` and `tracing` to disable logging at compile time by setting
|
||||
//! the `max_level_off` feature for these crates. So, you should not enable this feature for a
|
||||
//! native build as otherwise the node will not output any log messages.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
@@ -386,6 +399,12 @@ pub trait ConstructRuntimeApi<Block: BlockT, C: CallApiAt<Block>> {
|
||||
fn construct_runtime_api<'a>(call: &'a C) -> ApiRef<'a, Self::RuntimeApi>;
|
||||
}
|
||||
|
||||
/// Init the [`RuntimeLogger`](sp_runtime::runtime_logger::RuntimeLogger).
|
||||
pub fn init_runtime_logger() {
|
||||
#[cfg(not(feature = "disable-logging"))]
|
||||
sp_runtime::runtime_logger::RuntimeLogger::init();
|
||||
}
|
||||
|
||||
/// An error describing which API call failed.
|
||||
#[cfg(feature = "std")]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
||||
Reference in New Issue
Block a user