Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

introduce log-target constant to more frame pallets #13116

Merged
1 change: 1 addition & 0 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub use pallet::*;
pub use weights::WeightInfo;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
const LOG_TARGET: &str = "runtime::assets";

/// Trait with callbacks that are executed after successfull asset creation or destruction.
pub trait AssetsCallback<AssetId, AccountId> {
Expand Down
12 changes: 10 additions & 2 deletions frame/assets/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ pub mod v1 {
Some(old_value.migrate_to_v1())
});
current_version.put::<Pallet<T>>();
log::info!(target: "runtime::assets", "Upgraded {} pools, storage to version {:?}", translated, current_version);
log::info!(
target: LOG_TARGET,
"Upgraded {} pools, storage to version {:?}",
translated,
current_version
);
T::DbWeight::get().reads_writes(translated + 1, translated + 1)
} else {
log::info!(target: "runtime::assets", "Migration did not execute. This probably should be removed");
log::info!(
target: LOG_TARGET,
"Migration did not execute. This probably should be removed"
);
T::DbWeight::get().reads(1)
}
}
Expand Down
6 changes: 4 additions & 2 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ pub use weights::WeightInfo;

pub use pallet::*;

const LOG_TARGET: &str = "runtime::balances";

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

#[frame_support::pallet]
Expand Down Expand Up @@ -950,7 +952,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

if locks.len() as u32 > T::MaxLocks::get() {
log::warn!(
target: "runtime::balances",
target: LOG_TARGET,
"Warning: A user has more currency locks than expected. \
A runtime configuration adjustment may be needed."
);
Expand Down Expand Up @@ -985,7 +987,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
// since the funds that are under the lock will themselves be stored in the
// account and therefore will need a reference.
log::warn!(
target: "runtime::balances",
target: LOG_TARGET,
"Warning: Attempt to introduce lock consumer reference, yet no providers. \
This is unexpected but should be safe."
);
Expand Down
14 changes: 10 additions & 4 deletions frame/balances/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ fn migrate_v0_to_v1<T: Config<I>, I: 'static>(accounts: &[T::AccountId]) -> Weig
// Set storage version to `1`.
StorageVersion::new(1).put::<Pallet<T, I>>();

log::info!(target: "runtime::balances", "Storage to version 1");
log::info!(target: LOG_TARGET, "Storage to version 1");
T::DbWeight::get().reads_writes(2 + accounts.len() as u64, 3)
} else {
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
log::info!(
target: LOG_TARGET,
"Migration did not execute. This probably should be removed"
);
T::DbWeight::get().reads(1)
}
}
Expand Down Expand Up @@ -87,10 +90,13 @@ impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for ResetInactive<T, I> {
// Set storage version to `0`.
StorageVersion::new(0).put::<Pallet<T, I>>();

log::info!(target: "runtime::balances", "Storage to version 0");
log::info!(target: LOG_TARGET, "Storage to version 0");
T::DbWeight::get().reads_writes(1, 2)
} else {
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
log::info!(
target: LOG_TARGET,
"Migration did not execute. This probably should be removed"
);
T::DbWeight::get().reads(1)
}
}
Expand Down
8 changes: 5 additions & 3 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub mod weights;
pub use pallet::*;
pub use weights::WeightInfo;

const LOG_TARGET: &str = "runtime::collective";

/// Simple index type for proposal counting.
pub type ProposalIndex = u32;

Expand Down Expand Up @@ -390,7 +392,7 @@ pub mod pallet {
ensure_root(origin)?;
if new_members.len() > T::MaxMembers::get() as usize {
log::error!(
target: "runtime::collective",
target: LOG_TARGET,
"New members count ({}) exceeds maximum amount of members expected ({}).",
new_members.len(),
T::MaxMembers::get(),
Expand All @@ -400,7 +402,7 @@ pub mod pallet {
let old = Members::<T, I>::get();
if old.len() > old_count as usize {
log::warn!(
target: "runtime::collective",
target: LOG_TARGET,
"Wrong count used to estimate set_members weight. expected ({}) vs actual ({})",
old_count,
old.len(),
Expand Down Expand Up @@ -1040,7 +1042,7 @@ impl<T: Config<I>, I: 'static> ChangeMembers<T::AccountId> for Pallet<T, I> {
) {
if new.len() > T::MaxMembers::get() as usize {
log::error!(
target: "runtime::collective",
target: LOG_TARGET,
"New members count ({}) exceeds maximum amount of members expected ({}).",
new.len(),
T::MaxMembers::get(),
Expand Down
9 changes: 5 additions & 4 deletions frame/collective/src/migrations/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use sp_io::hashing::twox_128;

use super::super::LOG_TARGET;
use frame_support::{
traits::{
Get, GetStorageVersion, PalletInfoAccess, StorageVersion,
Expand All @@ -42,15 +43,15 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,

if new_pallet_name == old_pallet_name {
log::info!(
target: "runtime::collective",
target: LOG_TARGET,
"New pallet name is equal to the old pallet name. No migration needs to be done.",
);
return Weight::zero()
}

let on_chain_storage_version = <P as GetStorageVersion>::on_chain_storage_version();
log::info!(
target: "runtime::collective",
target: LOG_TARGET,
"Running migration to v4 for collective with storage version {:?}",
on_chain_storage_version,
);
Expand All @@ -66,7 +67,7 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,
<T as frame_system::Config>::BlockWeights::get().max_block
} else {
log::warn!(
target: "runtime::collective",
target: LOG_TARGET,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
on_chain_storage_version,
);
Expand Down Expand Up @@ -138,7 +139,7 @@ pub fn post_migrate<P: GetStorageVersion + PalletInfoAccess, N: AsRef<str>>(old_

fn log_migration(stage: &str, old_pallet_name: &str, new_pallet_name: &str) {
log::info!(
target: "runtime::collective",
target: LOG_TARGET,
"{}, prefix: '{}' ==> '{}'",
stage,
old_pallet_name,
Expand Down
15 changes: 5 additions & 10 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub use weights::WeightInfo;
/// All migrations.
pub mod migrations;

const LOG_TARGET: &str = "runtime::elections-phragmen";

/// The maximum votes allowed per voter.
pub const MAXIMUM_VOTE: usize = 16;

Expand Down Expand Up @@ -789,10 +791,7 @@ impl<T: Config> Pallet<T> {
} else {
// overlap. This can never happen. If so, it seems like our intended replacement
// is already a member, so not much more to do.
log::error!(
target: "runtime::elections-phragmen",
"A member seems to also be a runner-up.",
);
log::error!(target: LOG_TARGET, "A member seems to also be a runner-up.");
}
next_best
});
Expand Down Expand Up @@ -939,7 +938,7 @@ impl<T: Config> Pallet<T> {
Ok(_) => (),
Err(_) => {
log::error!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Failed to run election. Number of voters exceeded",
);
Self::deposit_event(Event::ElectionError);
Expand Down Expand Up @@ -1103,11 +1102,7 @@ impl<T: Config> Pallet<T> {
<ElectionRounds<T>>::mutate(|v| *v += 1);
})
.map_err(|e| {
log::error!(
target: "runtime::elections-phragmen",
"Failed to run election [{:?}].",
e,
);
log::error!(target: LOG_TARGET, "Failed to run election [{:?}].", e,);
Self::deposit_event(Event::ElectionError);
});

Expand Down
25 changes: 7 additions & 18 deletions frame/elections-phragmen/src/migrations/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! Migrations to version [`3.0.0`], as denoted by the changelog.

use super::super::LOG_TARGET;
use crate::{Config, Pallet};
use codec::{Decode, Encode, FullCodec};
use frame_support::{
Expand Down Expand Up @@ -88,7 +89,7 @@ pub fn apply<V: V2ToV3, T: Config>(
) -> Weight {
let storage_version = StorageVersion::get::<Pallet<T>>();
log::info!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Running migration for elections-phragmen with storage version {:?}",
storage_version,
);
Expand All @@ -104,7 +105,7 @@ pub fn apply<V: V2ToV3, T: Config>(
Weight::MAX
} else {
log::warn!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Attempted to apply migration to V3 but failed because storage version is {:?}",
storage_version,
);
Expand All @@ -118,22 +119,14 @@ pub fn migrate_voters_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit: V::
Some(Voter { votes, stake, deposit: old_deposit })
});

log::info!(
target: "runtime::elections-phragmen",
"migrated {} voter accounts.",
<Voting<V, T>>::iter().count(),
);
log::info!(target: LOG_TARGET, "migrated {} voter accounts.", <Voting<V, T>>::iter().count());
}

/// Migrate all candidates to recorded deposit.
pub fn migrate_candidates_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit: V::Balance) {
let _ = <Candidates<V, T>>::translate::<Vec<V::AccountId>, _>(|maybe_old_candidates| {
maybe_old_candidates.map(|old_candidates| {
log::info!(
target: "runtime::elections-phragmen",
"migrated {} candidate accounts.",
old_candidates.len(),
);
log::info!(target: LOG_TARGET, "migrated {} candidate accounts.", old_candidates.len());
old_candidates.into_iter().map(|c| (c, old_deposit)).collect::<Vec<_>>()
})
});
Expand All @@ -143,11 +136,7 @@ pub fn migrate_candidates_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit:
pub fn migrate_members_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit: V::Balance) {
let _ = <Members<V, T>>::translate::<Vec<(V::AccountId, V::Balance)>, _>(|maybe_old_members| {
maybe_old_members.map(|old_members| {
log::info!(
target: "runtime::elections-phragmen",
"migrated {} member accounts.",
old_members.len(),
);
log::info!(target: LOG_TARGET, "migrated {} member accounts.", old_members.len());
old_members
.into_iter()
.map(|(who, stake)| SeatHolder { who, stake, deposit: old_deposit })
Expand All @@ -162,7 +151,7 @@ pub fn migrate_runners_up_to_recorded_deposit<V: V2ToV3, T: Config>(old_deposit:
|maybe_old_runners_up| {
maybe_old_runners_up.map(|old_runners_up| {
log::info!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"migrated {} runner-up accounts.",
old_runners_up.len(),
);
Expand Down
7 changes: 4 additions & 3 deletions frame/elections-phragmen/src/migrations/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! Migrations to version [`4.0.0`], as denoted by the changelog.

use super::super::LOG_TARGET;
use frame_support::{
traits::{Get, StorageVersion},
weights::Weight,
Expand All @@ -35,14 +36,14 @@ pub const OLD_PREFIX: &[u8] = b"PhragmenElection";
pub fn migrate<T: crate::Config, N: AsRef<str>>(new_pallet_name: N) -> Weight {
if new_pallet_name.as_ref().as_bytes() == OLD_PREFIX {
log::info!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"New pallet name is equal to the old prefix. No migration needs to be done.",
);
return Weight::zero()
}
let storage_version = StorageVersion::get::<crate::Pallet<T>>();
log::info!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Running migration to v4 for elections-phragmen with storage version {:?}",
storage_version,
);
Expand All @@ -59,7 +60,7 @@ pub fn migrate<T: crate::Config, N: AsRef<str>>(new_pallet_name: N) -> Weight {
<T as frame_system::Config>::BlockWeights::get().max_block
} else {
log::warn!(
target: "runtime::elections-phragmen",
target: LOG_TARGET,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
storage_version,
);
Expand Down
2 changes: 2 additions & 0 deletions frame/membership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod weights;
pub use pallet::*;
pub use weights::WeightInfo;

const LOG_TARGET: &str = "runtime::membership";

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

#[frame_support::pallet]
Expand Down
9 changes: 5 additions & 4 deletions frame/membership/src/migrations/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::super::LOG_TARGET;
use sp_io::hashing::twox_128;

use frame_support::{
Expand Down Expand Up @@ -43,15 +44,15 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,

if new_pallet_name == old_pallet_name {
log::info!(
target: "runtime::membership",
target: LOG_TARGET,
"New pallet name is equal to the old prefix. No migration needs to be done.",
);
return Weight::zero()
}

let on_chain_storage_version = <P as GetStorageVersion>::on_chain_storage_version();
log::info!(
target: "runtime::membership",
target: LOG_TARGET,
"Running migration to v4 for membership with storage version {:?}",
on_chain_storage_version,
);
Expand All @@ -67,7 +68,7 @@ pub fn migrate<T: frame_system::Config, P: GetStorageVersion + PalletInfoAccess,
<T as frame_system::Config>::BlockWeights::get().max_block
} else {
log::warn!(
target: "runtime::membership",
target: LOG_TARGET,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
on_chain_storage_version,
);
Expand Down Expand Up @@ -139,7 +140,7 @@ pub fn post_migrate<P: GetStorageVersion, N: AsRef<str>>(old_pallet_name: N, new

fn log_migration(stage: &str, old_pallet_name: &str, new_pallet_name: &str) {
log::info!(
target: "runtime::membership",
target: LOG_TARGET,
"{}, prefix: '{}' ==> '{}'",
stage,
old_pallet_name,
Expand Down
Loading