Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

feat(logs): Use debug.js library for logging [DXJ-327] #285

Merged
merged 21 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,57 @@ Once you've added the client, you can compile [Aqua](https://github.com/fluencel
}
```

## Debug

JS Client uses the [debug](https://github.com/debug-js/debug) library under the hood for logging. The log namespaces are structured on a per-component basis, following this structure:

```
fluence:<component>:trace
fluence:<component>:debug
fluence:<component>:error
```

Marine JS logs have a slightly different structure:

```
fluence:marine:<service id>:trace
fluence:marine:<service id>:debug
fluence:marine:<service id>:info
fluence:marine:<service id>:warn
fluence:marine:<service id>:error
```

Each level corresponds to a logging level in Marine JS.

Star (`*`) character can be used as a wildcard to enable logs for multiple components at once. For example, `DEBUG=fluence:*` will enable logs for all components. To exclude a component, use a minus sign before the component name. For example, `DEBUG=fluence:*,-fluence:particle:*`

### Index of components:

- `particle`: everything related to particle processing queue
- `aqua`: infrastructure of aqua compiler support
- `connection`: connection layer
- `marine`: Marine JS logs

### Enabling logs in Node.js

enable logs, pass the environment variable `DEBUG` with the corresponding log level. For example:

```sh
DEBUG=fluence:* node --loader ts-node/esm ./src/index.ts
```

### Enabling logs in the browser

To enable logs, set the `localStorage.debug` variable. For example:

```
localStorage.debug = 'fluence:*'
```

**NOTE**

In Chromium-based web browsers (e.g. Brave, Chrome, and Electron), the JavaScript console will—by default—only show messages logged by debug if the "Verbose" log level is enabled.

## Development

To hack on the Fluence JS Client itself, please refer to the [development page](./DEVELOPING.md).
Expand All @@ -159,3 +210,4 @@ Any interested person is welcome to contribute to the project. Please, make sure
## License

All software code is copyright (c) Fluence Labs, Inc. under the [Apache-2.0](./LICENSE) license.

50 changes: 48 additions & 2 deletions packages/@tests/aqua/_aqua/smoke_test.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,53 @@ import "@fluencelabs/registry/resources-api.aqua"
service HelloWorld("hello-world"):
hello(str: string) -> string

func smokeTest(label: string) -> ?string, *string, string:
func resourceTest(label: string) -> ?string, *string:
res, errors <- createResource(label)
<- res, errors

func helloTest() -> string:
hello <- HelloWorld.hello("Fluence user")
<- res, errors, hello
<- hello

service CalcService:
add(num: f64) -> f64
clear_state()
divide(num: f64) -> f64
multiply(num: f64) -> f64
state() -> f64
subtract(num: f64) -> f64
test_logs()

data ServiceCreationResult:
success: bool
service_id: ?string
error: ?string

data RemoveResult:
success: bool
error: ?string

alias ListServiceResult: []string

service Srv("single_module_srv"):
create(wasm_b64_content: string) -> ServiceCreationResult
remove(service_id: string) -> RemoveResult
list() -> ListServiceResult


func demo_calculation(service_id: string) -> f64:
CalcService service_id
CalcService.test_logs()
CalcService.add(10)
CalcService.multiply(5)
CalcService.subtract(8)
CalcService.divide(6)
res <- CalcService.state()
<- res

func marineTest(wasm64: string) -> f64:
serviceResult <- Srv.create(wasm64)
res <- demo_calculation(serviceResult.service_id!)
<- res


8 changes: 5 additions & 3 deletions packages/@tests/aqua/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "module",
"scripts": {
"build": "tsc",
"compile-aqua": "aqua -i ./_aqua -o ./src/_aqua"
"compile-aqua": "fluence aqua -i ./_aqua -o ./src/_aqua"
},
"repository": "https://github.com/fluencelabs/fluence-js",
"author": "Fluence Labs",
Expand All @@ -22,7 +22,9 @@
"base64-js": "1.5.1"
},
"devDependencies": {
"@fluencelabs/aqua": "0.9.4",
"@fluencelabs/registry": "0.7.0"
"@fluencelabs/cli": "0.3.9",
"@fluencelabs/registry": "0.8.2",
"@fluencelabs/aqua-lib": "0.6.0",
"@fluencelabs/trust-graph": "3.1.2"
}
}
Loading