From 918e219a3edca28575a21741279131c8f31191b2 Mon Sep 17 00:00:00 2001 From: Jessie Mongeon Date: Thu, 19 Dec 2024 15:53:58 -0600 Subject: [PATCH] fix" " --- motoko/canister_logs/README.md | 54 ++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/motoko/canister_logs/README.md b/motoko/canister_logs/README.md index 545dd99b9..ad69e31b5 100644 --- a/motoko/canister_logs/README.md +++ b/motoko/canister_logs/README.md @@ -1,64 +1,66 @@ -# Canister logs - -## Prerequisites +--- +keywords: [beginner, motoko, canister logs, logging] +--- -- [x] Install the [IC - SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required. -- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples` +# Canister logs -## Step 1: Setup project environment +[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/motoko/canister_logs) -Navigate into the folder containing the project's files and start a local instance of the replica with the command: +## Prerequisites +This example requires an installation of: -```shell -dfx start --clean -``` +- [x] DFX version 0.19.0 or newer +- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/). +- [x] Download the following project files from GitHub: `git clone https://github.com/dfinity/examples/` You will need to have 3 terminal windows: -- Terminal A: Running a `dfx` instance and separating its output from anything else. -- Terminal B: Deploying a canister and seeing its output. -- Terminal C: Reading logs interactively. +- Terminal A: Running a DFX instance and separating its output from anything else +- Terminal B: Deploying a canister and seeing its output +- Terminal C: Reading logs interactively + +### Step 1: Navigate into the folder containing the project's files and start a local instance of the replica with the command: ```shell # Terminal A -- for running DFX and separating its output from anything else. -cd examples/motoko/canister_logs +$ cd examples/motoko/canister_logs +$ dfx start --clean # Terminal B -- for deploying the canister and calling its methods. -cd examples/motoko/canister_logs +$ cd examples/motoko/canister_logs # Terminal C -- for polling logs. -cd examples/motoko/canister_logs +$ cd examples/motoko/canister_logs ``` -## Step 2: Deploy the canister +### Step 2: Deploy the canister: ```shell # Terminal B -dfx deploy +$ dfx deploy ``` -## Step 3: Check canister logs +### Step 3: Check canister logs: Expect to see logs from timer traps. ```shell # Terminal B -dfx canister logs CanisterLogs +$ dfx canister logs CanisterLogs [0. 2024-05-23T08:32:26.203980235Z]: right before timer trap [1. 2024-05-23T08:32:26.203980235Z]: [TRAP]: timer trap [2. 2024-05-23T08:32:31.836721763Z]: right before timer trap [3. 2024-05-23T08:32:31.836721763Z]: [TRAP]: timer trap ``` -## Step 4: Call `print` method and check the logs +### Step 4: Call `print` method and check the logs: ```shell # Terminal B -dfx canister call CanisterLogs print hi +$ dfx canister call CanisterLogs print hi () # Expect to see new log entry. -dfx canister logs CanisterLogs +$ dfx canister logs CanisterLogs ... [8. 2024-05-23T08:32:46.598972616Z]: right before timer trap [9. 2024-05-23T08:32:46.598972616Z]: [TRAP]: timer trap @@ -68,7 +70,7 @@ dfx canister logs CanisterLogs ... ``` -## Step 5: Start constantly polling logs +### Step 5: Start constantly polling logs: In order not to call `dfx canister logs CanisterLogs` after every canister call in a separate terminal window/pane C start a script that will constantly poll logs: @@ -84,7 +86,7 @@ $ ./poll_logs.sh ... ``` -## Step 6: Call `print`, `trap` and other canister methods +### Step 6: Call `print`, `trap` and other canister methods: ```shell # Terminal B