Skip to content

Commit

Permalink
Add logging example (stellar#130)
Browse files Browse the repository at this point in the history
* Add logging example

* profile
  • Loading branch information
leighmcculloch authored Oct 6, 2022
1 parent ece69b2 commit dda4f40
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ members = [
"single_offer_router",
"events",
"timelock",
"token"
"token",
"logging",
]

[profile.release-with-logs]
inherits = "release"
debug-assertions = true

[profile.release]
opt-level = "z"
overflow-checks = true
Expand Down
20 changes: 20 additions & 0 deletions logging/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "soroban-logging-contract"
version = "0.0.0"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib", "rlib"]
doctest = false

[features]
testutils = ["soroban-sdk/testutils"]

[dependencies]
soroban-sdk = "0.0.4"

[dev_dependencies]
soroban-sdk = { version = "0.0.4", features = ["testutils"] }
13 changes: 13 additions & 0 deletions logging/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![no_std]
use soroban_sdk::{contractimpl, log, Env, Symbol};

pub struct Contract;

#[contractimpl]
impl Contract {
pub fn hello(env: Env, value: Symbol) {
log!(&env, "Hello {}", value);
}
}

mod test;
18 changes: 18 additions & 0 deletions logging/src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![cfg(test)]

use super::*;
use soroban_sdk::{symbol, testutils::Logger, BytesN, Env};

extern crate std;

#[test]
fn test() {
let env = Env::default();
let contract_id = BytesN::from_array(&env, &[0; 32]);
env.register_contract(&contract_id, Contract);
let client = ContractClient::new(&env, &contract_id);

client.hello(&symbol!("Dev"));

assert_eq!(env.logger().all(), std::vec!["Hello Symbol(Dev)"]);
}

0 comments on commit dda4f40

Please sign in to comment.