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
+13 -4
View File
@@ -85,7 +85,7 @@ use sp_runtime::{
use sp_core::{ChangesTrieConfiguration, storage::well_known_keys};
use frame_support::{
Parameter, debug, storage,
Parameter, storage,
traits::{
Contains, Get, PalletInfo, OnNewAccount, OnKilledAccount, HandleLifetime,
StoredMap, EnsureOrigin, OriginTrait, Filter,
@@ -1060,7 +1060,10 @@ impl<T: Config> Module<T> {
(0, _) => {
// Logic error - cannot decrement beyond zero and no item should
// exist with zero providers.
debug::print!("Logic error: Unexpected underflow in reducing provider");
log::error!(
target: "runtime::system",
"Logic error: Unexpected underflow in reducing provider",
);
Ok(DecRefStatus::Reaped)
},
(1, 0) => {
@@ -1078,7 +1081,10 @@ impl<T: Config> Module<T> {
}
}
} else {
debug::print!("Logic error: Account already dead when reducing provider");
log::error!(
target: "runtime::system",
"Logic error: Account already dead when reducing provider",
);
Ok(DecRefStatus::Reaped)
}
})
@@ -1107,7 +1113,10 @@ impl<T: Config> Module<T> {
Account::<T>::mutate(who, |a| if a.consumers > 0 {
a.consumers -= 1;
} else {
debug::print!("Logic error: Unexpected underflow in reducing consumer");
log::error!(
target: "runtime::system",
"Logic error: Unexpected underflow in reducing consumer",
);
})
}
+3 -3
View File
@@ -63,7 +63,7 @@ use sp_std::convert::{TryInto, TryFrom};
use sp_std::prelude::{Box, Vec};
use sp_runtime::app_crypto::RuntimeAppPublic;
use sp_runtime::traits::{Extrinsic as ExtrinsicT, IdentifyAccount, One};
use frame_support::{debug, RuntimeDebug};
use frame_support::RuntimeDebug;
/// Marker struct used to flag using all supported keys to sign a payload.
pub struct ForAll {}
@@ -550,8 +550,8 @@ pub trait SendSignedTransaction<
call: LocalCall,
) -> Option<Result<(), ()>> {
let mut account_data = crate::Account::<T>::get(&account.id);
debug::native::debug!(
target: "offchain",
log::debug!(
target: "runtime::offchain",
"Creating signed transaction from account: {:?} (nonce: {:?})",
account.id,
account_data.nonce,