Skip to content

Commit 918e219

Browse files
fix"
"
1 parent 323c768 commit 918e219

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

motoko/canister_logs/README.md

+28-26
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,66 @@
1-
# Canister logs
2-
3-
## Prerequisites
1+
---
2+
keywords: [beginner, motoko, canister logs, logging]
3+
---
44

5-
- [x] Install the [IC
6-
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.
7-
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
5+
# Canister logs
86

9-
## Step 1: Setup project environment
7+
[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/motoko/canister_logs)
108

11-
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
9+
## Prerequisites
10+
This example requires an installation of:
1211

13-
```shell
14-
dfx start --clean
15-
```
12+
- [x] DFX version 0.19.0 or newer
13+
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/).
14+
- [x] Download the following project files from GitHub: `git clone https://github.com/dfinity/examples/`
1615

1716
You will need to have 3 terminal windows:
18-
- Terminal A: Running a `dfx` instance and separating its output from anything else.
19-
- Terminal B: Deploying a canister and seeing its output.
20-
- Terminal C: Reading logs interactively.
17+
- Terminal A: Running a DFX instance and separating its output from anything else
18+
- Terminal B: Deploying a canister and seeing its output
19+
- Terminal C: Reading logs interactively
20+
21+
### Step 1: Navigate into the folder containing the project's files and start a local instance of the replica with the command:
2122

2223
```shell
2324
# Terminal A -- for running DFX and separating its output from anything else.
24-
cd examples/motoko/canister_logs
25+
$ cd examples/motoko/canister_logs
26+
$ dfx start --clean
2527

2628
# Terminal B -- for deploying the canister and calling its methods.
27-
cd examples/motoko/canister_logs
29+
$ cd examples/motoko/canister_logs
2830

2931
# Terminal C -- for polling logs.
30-
cd examples/motoko/canister_logs
32+
$ cd examples/motoko/canister_logs
3133
```
3234

33-
## Step 2: Deploy the canister
35+
### Step 2: Deploy the canister:
3436

3537
```shell
3638
# Terminal B
37-
dfx deploy
39+
$ dfx deploy
3840
```
3941

40-
## Step 3: Check canister logs
42+
### Step 3: Check canister logs:
4143

4244
Expect to see logs from timer traps.
4345

4446
```shell
4547
# Terminal B
46-
dfx canister logs CanisterLogs
48+
$ dfx canister logs CanisterLogs
4749
[0. 2024-05-23T08:32:26.203980235Z]: right before timer trap
4850
[1. 2024-05-23T08:32:26.203980235Z]: [TRAP]: timer trap
4951
[2. 2024-05-23T08:32:31.836721763Z]: right before timer trap
5052
[3. 2024-05-23T08:32:31.836721763Z]: [TRAP]: timer trap
5153
```
5254

53-
## Step 4: Call `print` method and check the logs
55+
### Step 4: Call `print` method and check the logs:
5456

5557
```shell
5658
# Terminal B
57-
dfx canister call CanisterLogs print hi
59+
$ dfx canister call CanisterLogs print hi
5860
()
5961

6062
# Expect to see new log entry.
61-
dfx canister logs CanisterLogs
63+
$ dfx canister logs CanisterLogs
6264
...
6365
[8. 2024-05-23T08:32:46.598972616Z]: right before timer trap
6466
[9. 2024-05-23T08:32:46.598972616Z]: [TRAP]: timer trap
@@ -68,7 +70,7 @@ dfx canister logs CanisterLogs
6870
...
6971
```
7072

71-
## Step 5: Start constantly polling logs
73+
### Step 5: Start constantly polling logs:
7274

7375
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:
7476

@@ -84,7 +86,7 @@ $ ./poll_logs.sh
8486
...
8587
```
8688

87-
## Step 6: Call `print`, `trap` and other canister methods
89+
### Step 6: Call `print`, `trap` and other canister methods:
8890

8991
```shell
9092
# Terminal B

0 commit comments

Comments
 (0)