use-ink / cargo-contract

Setup and deployment tool for developing Wasm based smart contracts via ink!
GNU General Public License v3.0
244 stars 120 forks source link

There are still some logs with --output-json #1155

Open kvinwang opened 1 year ago

kvinwang commented 1 year ago
$ cargo contract build --output-json
2023-06-10T01:20:10.586663Z  INFO contract_build: No changes in the original wasm at /home/kvin/codes/chain/phala/phat/proven/target/ink/wasm32-unknown-unknown/release/proven.wasm, fingerprint Some(Fingerprint { path: "/home/kvin/codes/chain/phala/phat/proven/target/ink/wasm32-unknown-unknown/release/proven.wasm", hash: [242, 38, 236, 112, 198, 86, 153, 200, 13, 188, 105, 71, 49, 149, 115, 100, 70, 143, 255, 33, 223, 231, 71, 59, 4, 95, 88, 54, 77, 246, 18, 153], modified: SystemTime { tv_sec: 1686358618, tv_nsec: 219799198 }, target: "wasm32-unknown-unknown" }). Skipping Wasm optimization and metadata generation.
{
  "dest_wasm": "/home/kvin/codes/chain/phala/phat/proven/target/ink/proven.wasm",
  "metadata_result": {
    "dest_metadata": "/home/kvin/codes/chain/phala/phat/proven/target/ink/proven.json",
    "dest_bundle": "/home/kvin/codes/chain/phala/phat/proven/target/ink/proven.contract"
  },
  "target_directory": "/home/kvin/codes/chain/phala/phat/proven/target/ink",
  "optimization_result": null,
  "build_mode": "Debug",
  "build_artifact": "All",
  "verbosity": "Quiet"
}

This makes the json parsing failure:

$ cargo contract build --output-json | jq
parse error: Invalid numeric literal at line 1, column 2
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:1008:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
ascjones commented 1 year ago

Do you have RUST_LOG set in your environment? I only get this message when it is set e.g.

image

kvinwang commented 1 year ago

Do you have RUST_LOG set in your environment? I only get this message when it is set e.g.

Yes, RUST_LOG=info. So, is it on purpose? How about making it configurable, like CARGO_CONTRACT_LOG_TO_STDERR=true?

ascjones commented 1 year ago

It's not on purpose, it's the default behaviour and hasn't been considered previously. So yes the question is: how do we want it to behave?

Options:

  1. Log to stderr as you suggest, or make it the default, make it configurable
  2. Capture any log output and add it as a field in the json
  3. Leave it as it is and encourage users to disable logging for json output (maybe add a warning message)?

Probably more, but that's a start. Not sure which I prefer at the moment.