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:
Bastian Köcher
2021-03-01 15:29:17 +01:00
committed by GitHub
parent f2d9bb9ea6
commit 68390d4085
65 changed files with 571 additions and 422 deletions
+14 -14
View File
@@ -335,13 +335,13 @@ use sp_election_providers::ElectionProvider;
pub use weights::WeightInfo;
const STAKING_ID: LockIdentifier = *b"staking ";
pub(crate) const LOG_TARGET: &'static str = "staking";
pub(crate) const LOG_TARGET: &'static str = "runtime::staking";
// syntactic sugar for logging.
#[macro_export]
macro_rules! log {
($level:tt, $patter:expr $(, $values:expr)* $(,)?) => {
frame_support::debug::$level!(
log::$level!(
target: crate::LOG_TARGET,
concat!("💸 ", $patter) $(, $values)*
)
@@ -3404,30 +3404,30 @@ impl<T: Config> sp_election_providers::ElectionDataProvider<T::AccountId, T::Blo
/// some session can lag in between the newest session planned and the latest session started.
impl<T: Config> pallet_session::SessionManager<T::AccountId> for Module<T> {
fn new_session(new_index: SessionIndex) -> Option<Vec<T::AccountId>> {
frame_support::debug::native::trace!(
target: LOG_TARGET,
"[{}] planning new_session({})",
log!(
trace,
"[{:?}] planning new_session({})",
<frame_system::Module<T>>::block_number(),
new_index
new_index,
);
CurrentPlannedSession::put(new_index);
Self::new_session(new_index)
}
fn start_session(start_index: SessionIndex) {
frame_support::debug::native::trace!(
target: LOG_TARGET,
"[{}] starting start_session({})",
log!(
trace,
"[{:?}] starting start_session({})",
<frame_system::Module<T>>::block_number(),
start_index
start_index,
);
Self::start_session(start_index)
}
fn end_session(end_index: SessionIndex) {
frame_support::debug::native::trace!(
target: LOG_TARGET,
"[{}] ending end_session({})",
log!(
trace,
"[{:?}] ending end_session({})",
<frame_system::Module<T>>::block_number(),
end_index
end_index,
);
Self::end_session(end_index)
}