1
- # Canister logs
2
-
3
- ## Prerequisites
1
+ ---
2
+ keywords : [beginner, motoko, canister logs, logging]
3
+ ---
4
4
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
8
6
9
- ## Step 1: Setup project environment
7
+ [ View this sample's code on GitHub ] ( https://github.com/dfinity/examples/tree/master/motoko/canister_logs )
10
8
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:
12
11
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/ `
16
15
17
16
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:
21
22
22
23
``` shell
23
24
# 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
25
27
26
28
# Terminal B -- for deploying the canister and calling its methods.
27
- cd examples/motoko/canister_logs
29
+ $ cd examples/motoko/canister_logs
28
30
29
31
# Terminal C -- for polling logs.
30
- cd examples/motoko/canister_logs
32
+ $ cd examples/motoko/canister_logs
31
33
```
32
34
33
- ## Step 2: Deploy the canister
35
+ ### Step 2: Deploy the canister:
34
36
35
37
``` shell
36
38
# Terminal B
37
- dfx deploy
39
+ $ dfx deploy
38
40
```
39
41
40
- ## Step 3: Check canister logs
42
+ ### Step 3: Check canister logs:
41
43
42
44
Expect to see logs from timer traps.
43
45
44
46
``` shell
45
47
# Terminal B
46
- dfx canister logs CanisterLogs
48
+ $ dfx canister logs CanisterLogs
47
49
[0. 2024-05-23T08:32:26.203980235Z]: right before timer trap
48
50
[1. 2024-05-23T08:32:26.203980235Z]: [TRAP]: timer trap
49
51
[2. 2024-05-23T08:32:31.836721763Z]: right before timer trap
50
52
[3. 2024-05-23T08:32:31.836721763Z]: [TRAP]: timer trap
51
53
```
52
54
53
- ## Step 4: Call ` print ` method and check the logs
55
+ ### Step 4: Call ` print ` method and check the logs:
54
56
55
57
``` shell
56
58
# Terminal B
57
- dfx canister call CanisterLogs print hi
59
+ $ dfx canister call CanisterLogs print hi
58
60
()
59
61
60
62
# Expect to see new log entry.
61
- dfx canister logs CanisterLogs
63
+ $ dfx canister logs CanisterLogs
62
64
...
63
65
[8. 2024-05-23T08:32:46.598972616Z]: right before timer trap
64
66
[9. 2024-05-23T08:32:46.598972616Z]: [TRAP]: timer trap
@@ -68,7 +70,7 @@ dfx canister logs CanisterLogs
68
70
...
69
71
```
70
72
71
- ## Step 5: Start constantly polling logs
73
+ ### Step 5: Start constantly polling logs:
72
74
73
75
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:
74
76
@@ -84,7 +86,7 @@ $ ./poll_logs.sh
84
86
...
85
87
```
86
88
87
- ## Step 6: Call ` print ` , ` trap ` and other canister methods
89
+ ### Step 6: Call ` print ` , ` trap ` and other canister methods:
88
90
89
91
``` shell
90
92
# Terminal B
0 commit comments