Skip to content

Commit

Permalink
Add logging to spooning example
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Jan 12, 2022
1 parent 801dbde commit 090273c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ near-units = "0.1.0"
# arbitrary_precision enabled for u128 types that workspaces requires for Balance types
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
tokio = { version = "1.10.0", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3.5", features = ["env-filter"] }
workspaces = { path = "../workspaces" }

[[example]]
Expand Down
16 changes: 14 additions & 2 deletions examples/src/spooning.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use borsh::{self, BorshDeserialize, BorshSerialize};
use std::env;
use tracing::info;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::EnvFilter;
use workspaces::prelude::*;
use workspaces::{AccountId, Contract, DevNetwork, Worker};

Expand Down Expand Up @@ -59,6 +63,14 @@ async fn deploy_status_contract(

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Parse log filters from RUST_LOG or fallback to INFO if empty
let filter = if env::var(EnvFilter::DEFAULT_ENV).is_ok() {
EnvFilter::from_default_env()
} else {
EnvFilter::default().add_directive(LevelFilter::INFO.into())
};
tracing_subscriber::fmt().with_env_filter(filter).init();

// Grab STATE from the testnet status_message contract. This contract contains the following data:
// get_status(dev-20211013002148-59466083160385) => "hello from testnet"
let (testnet_contract_id, status_msg) = {
Expand All @@ -75,7 +87,7 @@ async fn main() -> anyhow::Result<()> {
(contract_id, status_msg)
};

println!("Testnet: {:?}\n", status_msg);
info!(target: "spooning", "Testnet: {:?}", status_msg);

// Create our sandboxed environment and grab a worker to do stuff in it:
let worker = workspaces::sandbox();
Expand Down Expand Up @@ -106,7 +118,7 @@ async fn main() -> anyhow::Result<()> {
.await?
.json()?;

println!("New status patched: {:?}", status);
info!(target: "spooning", "New status patched: {:?}", status);
assert_eq!(&status, "hello from testnet");

// See that sandbox state was overriden. Grabbing get_status(sandbox_contract_id) should yield Null
Expand Down

0 comments on commit 090273c

Please sign in to comment.