I'm using https://github.com/near/workspaces-rs/ and have lines in my functions like log!("Removed {} from {}", &key, &recipient);
(using use near_sdk::{env, log};)
But those log messages don't appear in the terminal when I run my integration tests.
How to initialize the logger for integration tests? pointed me to https://docs.rs/env_logger/0.9.0/env_logger/index.html#capturing-logs-in-tests which gives this example:
#[cfg(test)]
mod tests {
fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}
#[test]
fn it_works() {
init();
info!("This record will be captured by `cargo test`");
assert_eq!(2, 1 + 1);
}
}
But even when I create and call that init() function and also replace my log!() calls with info!(), I get nothing.
(I can see the log outputs of the tests themselves but not the logging from within the main implementation code.)
Logs will be shown in the outcome from
.call()and can be retrieved from thereceiptselement in the returned data structure (receipts -> ExecutionOutcome -> logs).To prove this works, I created a new project in my projects directory with
npx create-near-appwhich comes with a basic get-set string contract in TypeScript. I deleted theintegration-testsfolder since the implementation was in JS/TS and created a new tests folder in instead, with a similar structure to that seen here: https://github.com/near-examples/NFT/tree/master/integration-tests/rsHere are the files that I modified: https://gist.github.com/idea404/5ecbcfaa2b1e41b9e33df15dfdaa0dae
Upon running the tests with
npm testfrom the project's root directory, I get the following output: