Skip to content

Commit

Permalink
fix"
Browse files Browse the repository at this point in the history
"
  • Loading branch information
jessiemongeon1 committed Dec 19, 2024
1 parent 323c768 commit 918e219
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions motoko/canister_logs/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:

Expand All @@ -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
Expand Down

0 comments on commit 918e219

Please sign in to comment.