Skip to content

Commit

Permalink
chore(APP): surface debug logs and use uuid in the log file (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Poytr1 authored Nov 20, 2022
1 parent cbbf2dd commit 2dd4e76
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 30 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ cacache = "10.0.1"
serde_json = "1.0"
home = "0.5.4"
toml = "0.5.9"
uuid = { version = "1.2.1", features = [
"v4", # Lets you generate random UUIDs
"fast-rng", # Use a faster (but still sufficiently random) RNG
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
]}

[dev-dependencies]
ctor = "0.1.26"
56 changes: 34 additions & 22 deletions app/client/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
</div>
<div class="form-group">
<label for="function">Function</label>
<textarea
<input
v-model="message.func"
style="height: 4rem"
type="text"
class="form-control"
id="function"
placeholder="Enter a function name, e.g. 0x1::foo::bar"
required
></textarea>
>
</div>
<div class="form-group">
<label for="type_args">Type parameters</label>
Expand All @@ -30,6 +29,17 @@
placeholder="Enter type parameters, seperated by ','"
></textarea>
</div>
<div class="form-group">
<label for="args">Parameters</label>
<textarea
v-model="message.args"
type="text"
class="form-control"
style="height: 4rem"
id="args"
placeholder="Enter parameters, seperated by ','"
></textarea>
</div>
<div class="form-group">
<label for="ledger_version">Ledger Version</label>
<input
Expand All @@ -42,24 +52,21 @@
</div>
<div class="form-group">
<label for="network">Network</label>
<input
<select
v-model="message.network"
type="text"
class="form-control"
id="network"
placeholder="Enter Network"
/>
style="height: 2rem"
>
<option disabled value="">Please select network</option>
<option>mainnet</option>
<option>testnet</option>
<option>devnet</option>
</select>
</div>
<div class="form-group">
<label for="args">Parameters</label>
<textarea
v-model="message.args"
type="text"
class="form-control"
style="height: 4rem"
id="args"
placeholder="Enter parameters, seperated by ','"
></textarea>
<div style="text-align: left;">
<label style="display: inline-block;" for="checkbox">Enable debug logs</label>
<input style="display: inline-block; margin-left: -12rem;"
type="checkbox" id="checkbox" v-model="message.with_logs" />
</div>
<div style="text-align: right; margin-top: 1rem">
<button type="submit" class="btn btn-primary">Call Function</button>
Expand Down Expand Up @@ -152,6 +159,7 @@ export default defineComponent({
args: '',
ledger_version: 0,
network: '',
with_logs: false,
},
isShow: false,
result: '',
Expand All @@ -167,12 +175,16 @@ export default defineComponent({
methods: {
callFunction() {
console.log(this.message);
const typeArgs = this.message.type_args.trim();
const args = this.message.args.trim();
const network = this.message.network.trim();
const requestBody = {
func: this.message.func,
type_args: this.message.type_args.trim().split(','),
args: this.message.args.trim().split(','),
type_args: typeArgs.length > 0 ? typeArgs.split(',') : undefined,
args: args.length > 0 ? args.split(',') : undefined,
ledger_version: this.message.ledger_version,
network: this.message.network,
network: network.length > 0 ? network : undefined,
options: this.message.with_logs ? { with_logs: true } : undefined,
};
fetch(API_URL, {
method: 'POST',
Expand All @@ -185,7 +197,7 @@ export default defineComponent({
.then((result) => {
if (result.error) {
// there was an error...
const error = 'Failed to call the function, check errors in the result or re-call the function with logs = true';
const error = 'Failed to call the function, check errors in the result or re-call the function with debug logs enabled';
this.error = error;
this.result = JSON.stringify(result.details, null, 2);
} else {
Expand Down
7 changes: 5 additions & 2 deletions app/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ app.post('/call_function', (req, res) => {
commands = commands.concat('--network', `${body.network.toLowerCase()}`);
}
const with_logs = body.options?.with_logs;
if (with_logs) {
commands = commands.concat('--log_level', 'Debug');
}
console.log(commands);
process.env.RUST_BACKTRACE = '1';
const execution_result = execFileSync(aptos_bin, commands, {encoding: 'utf-8'});
Expand All @@ -69,15 +72,15 @@ app.post('/call_function', (req, res) => {
res.json({
details: {
return_values: parsed_res.return_values,
logs: with_logs ? read_log(parsed_res.log_path) : '',
logs: with_logs ? read_log(parsed_res.log_path).split('\n') : '',
},
error: false
})
} else {
res.json({
details: {
return_values: [],
logs: with_logs ? read_log(parsed_res.log_path) : '',
logs: with_logs ? read_log(parsed_res.log_path).split('\n') : '',
},
error: true
})
Expand Down
10 changes: 4 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use move_stdlib;
use move_vm_runtime::move_vm::MoveVM;
use move_vm_test_utils::gas_schedule::{CostTable, Gas, GasStatus};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::config::{ConfigData, ToolConfig};
use crate::helper::{
Expand Down Expand Up @@ -140,7 +141,8 @@ fn set_up_log(config: &ToolConfig, log_level: String) -> String {
}
let dir = Path::new(config.log_folder.as_ref().unwrap().as_str());
fs::create_dir_all(dir.clone()).unwrap();
let file = Path::new(&dir).join("aptos_tool_bin.log");
let id = Uuid::new_v4();
let file = Path::new(&dir).join(format!("aptos_tool_bin_{}.log", id.to_string()));
let file_path = absolute_path(file)
.unwrap()
.into_os_string()
Expand Down Expand Up @@ -216,9 +218,6 @@ fn exec_func(
match res {
None => execution_res.return_values = vec![],
Some(vals) => {
// let deser_vals = vals.into_iter().map(|val| {
// MoveValue::simple_deserialize(&*val.0, &val.1).unwrap()
// }).collect();
execution_res.return_values = vals
}
}
Expand Down Expand Up @@ -267,10 +266,9 @@ fn exec_func_internal(
return Some(pretty_print_values);
}
Err(err) => {
error!("Error! {}", err.to_string())
panic!("Error while executing the function! {}", err.to_string())
}
}
return None;
}

fn get_gas_status(cost_table: &CostTable, gas_budget: Option<u64>) -> Result<GasStatus> {
Expand Down

0 comments on commit 2dd4e76

Please sign in to comment.