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

contracts Add LOG_TARGET constant #14002

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
gas::GasMeter,
storage::{self, DepositAccount, WriteOutcome},
BalanceOf, CodeHash, Config, ContractInfo, ContractInfoOf, DebugBufferVec, Determinism, Error,
Event, Nonce, Pallet as Contracts, Schedule, System,
Event, Nonce, Pallet as Contracts, Schedule, System, LOG_TARGET,
};
use frame_support::{
crypto::ecdsa::ECDSAExt,
Expand Down Expand Up @@ -1002,7 +1002,7 @@ where
} else {
if let Some((msg, false)) = self.debug_message.as_ref().map(|m| (m, m.is_empty())) {
log::debug!(
target: "runtime::contracts",
target: LOG_TARGET,
"Execution finished with debug buffer: {}",
core::str::from_utf8(msg).unwrap_or("<Invalid UTF8>"),
);
Expand Down Expand Up @@ -1331,7 +1331,7 @@ where
.try_extend(&mut msg.bytes())
.map_err(|_| {
log::debug!(
target: "runtime::contracts",
target: LOG_TARGET,
"Debug buffer (of {} bytes) exhausted!",
DebugBufferVec::<T>::bound(),
)
Expand Down
7 changes: 7 additions & 0 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ type OldWeight = u64;
/// that this value makes sense for a memory location or length.
const SENTINEL: u32 = u32::MAX;

/// The target that is used by the log output emitted by this crate.
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
///
/// Hence you can use this target to selectively increase the log level for this crate.
///
/// Example: `RUST_LOG=runtime::contracts=debug my_code --dev`
const LOG_TARGET: &str = "runtime::contracts";

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down
6 changes: 3 additions & 3 deletions frame/contracts/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use crate::{
storage::{ContractInfo, DepositAccount},
BalanceOf, Config, Error, Inspect, Pallet, System,
BalanceOf, Config, Error, Inspect, Pallet, System, LOG_TARGET,
};
use codec::Encode;
use frame_support::{
Expand Down Expand Up @@ -502,7 +502,7 @@ impl<T: Config> Ext<T> for ReservingExt {
);
if let Err(err) = result {
log::error!(
target: "runtime::contracts",
target: LOG_TARGET,
"Failed to transfer storage deposit {:?} from origin {:?} to deposit account {:?}: {:?}",
amount, origin, deposit_account, err,
);
Expand Down Expand Up @@ -531,7 +531,7 @@ impl<T: Config> Ext<T> for ReservingExt {
);
if matches!(result, Err(_)) {
log::error!(
target: "runtime::contracts",
target: LOG_TARGET,
"Failed to refund storage deposit {:?} from deposit account {:?} to origin {:?}: {:?}",
amount, deposit_account, origin, result,
);
Expand Down
6 changes: 3 additions & 3 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::{
exec::{ExecResult, Executable, ExportedFunction, Ext},
gas::GasMeter,
AccountIdOf, BalanceOf, CodeHash, CodeVec, Config, Error, OwnerInfoOf, RelaxedCodeVec,
Schedule,
Schedule, LOG_TARGET,
};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::dispatch::{DispatchError, DispatchResult};
Expand Down Expand Up @@ -326,7 +326,7 @@ impl<T: Config> Executable<T> for PrefabWasmModule<T> {
},
)
.map_err(|msg| {
log::debug!(target: "runtime::contracts", "failed to instantiate code: {}", msg);
log::debug!(target: LOG_TARGET, "failed to instantiate code: {}", msg);
Error::<T>::CodeRejected
})?;
store.data_mut().set_memory(memory);
Expand All @@ -335,7 +335,7 @@ impl<T: Config> Executable<T> for PrefabWasmModule<T> {
.get_export(&store, function.identifier())
.and_then(|export| export.into_func())
.ok_or_else(|| {
log::error!(target: "runtime::contracts", "failed to find entry point");
log::error!(target: LOG_TARGET, "failed to find entry point");
Error::<T>::CodeRejected
})?;

Expand Down
10 changes: 5 additions & 5 deletions frame/contracts/src/wasm/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
wasm::{
runtime::AllowDeprecatedInterface, Determinism, Environment, OwnerInfo, PrefabWasmModule,
},
AccountIdOf, CodeVec, Config, Error, Schedule,
AccountIdOf, CodeVec, Config, Error, Schedule, LOG_TARGET,
};
use codec::{Encode, MaxEncodedLen};
use sp_runtime::{traits::Hash, DispatchError};
Expand Down Expand Up @@ -379,7 +379,7 @@ where
})
.validate_all(original_code)
.map_err(|err| {
log::debug!(target: "runtime::contracts", "{}", err);
log::debug!(target: LOG_TARGET, "{}", err);
(Error::<T>::CodeRejected.into(), "validation of new code failed")
})?;

Expand All @@ -403,7 +403,7 @@ where
Ok((code, memory_limits))
})()
.map_err(|msg: &str| {
log::debug!(target: "runtime::contracts", "new code rejected: {}", msg);
log::debug!(target: LOG_TARGET, "new code rejected: {}", msg);
(Error::<T>::CodeRejected.into(), msg)
})?;

Expand All @@ -426,7 +426,7 @@ where
},
)
.map_err(|err| {
log::debug!(target: "runtime::contracts", "{}", err);
log::debug!(target: LOG_TARGET, "{}", err);
(Error::<T>::CodeRejected.into(), "new code rejected after instrumentation")
})?;
}
Expand Down Expand Up @@ -518,7 +518,7 @@ where
InstrumentReason::Reinstrument,
)
.map_err(|(err, msg)| {
log::error!(target: "runtime::contracts", "CodeRejected during reinstrument: {}", msg);
log::error!(target: LOG_TARGET, "CodeRejected during reinstrument: {}", msg);
err
})
.map(|(code, _)| code)
Expand Down