1- # logdash - JS SDK
1+ # @ logdash/node
22
3- Logdash is a zero-config observability platform. This package serves an javascript interface to use it.
3+ Logdash is a zero-config observability platform. This package serves a Node.js/Bun/Deno/Browser interface to use it.
44
55## Pre-requisites
66
@@ -9,39 +9,48 @@ Setup your free project in less than 2 minutes at [logdash.io](https://logdash.i
99## Installation
1010
1111```
12- npm install @logdash/js-sdk
12+ npm install @logdash/node
1313```
1414
1515## Logging
1616
1717``` typescript
18- import { createLogDash } from ' @logdash/js-sdk ' ;
18+ import { Logdash } from ' @logdash/node ' ;
1919
20- const { logger } = createLogDash ({
21- // optional, but recommended to see your logs in the dashboard
22- apiKey: ' <your-api-key>' ,
23- });
20+ const logdash = new Logdash (' <your-api-key>' );
2421
25- logger .info (' Application started successfully' );
26- logger .error (' An unexpected error occurred' );
27- logger .warn (' Low disk space warning' );
22+ logdash .info (' Application started successfully' );
23+ logdash .error (' An unexpected error occurred' );
24+ logdash .warn (' Low disk space warning' );
25+ ```
26+
27+ ## Namespaced Logging
28+
29+ ``` typescript
30+ const authLogdash = logdash .withNamespace (' auth' );
31+ authLogdash .info (' User logged in' );
32+ authLogdash .error (' Authentication failed' );
2833```
2934
3035## Metrics
3136
3237``` typescript
33- import { createLogDash } from ' @logdash/js-sdk ' ;
38+ import { Logdash } from ' @logdash/node ' ;
3439
35- const { metrics } = createLogDash ({
36- // optional, but recommended as metrics are only hosted remotely
37- apiKey: ' <your-api-key>' ,
38- });
40+ const logdash = new Logdash (' <your-api-key>' );
3941
4042// to set absolute value
41- metrics . set (' users' , 0 );
43+ logdash . setMetric (' users' , 0 );
4244
4345// to modify existing metric
44- metrics .mutate (' users' , 1 );
46+ logdash .mutateMetric (' users' , 1 );
47+ ```
48+
49+ ## Graceful Shutdown
50+
51+ ``` typescript
52+ // Ensure all logs and metrics are sent before exiting
53+ await logdash .flush ();
4554```
4655
4756## View
@@ -53,20 +62,20 @@ To see the logs or metrics, go to your project dashboard
5362
5463## Configuration
5564
56- | Parameter | Required | Default | Description |
57- | --------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------ |
58- | ` apiKey ` | no | - | Api key used to authorize against logdash servers. If you don't provide one, logs will be logged into local console only |
59- | ` host ` | no | - | Custom API host, useful with self-hosted instances |
60- | ` verbose ` | no | - | Useful for debugging purposes |
65+ ``` typescript
66+ new Logdash (apiKey ? , options ? )
67+ ` ` `
68+
69+ | Parameter | Required | Default | Description |
70+ | ----------------- | -------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
71+ | ` apiKey ` | no | - | Api key used to authorize against logdash servers. If you don't provide one, logs will be logged into local console only |
72+ | ` options .host ` | no | ` https : // api.logdash.io` | Custom API host, useful with self-hosted instances |
73+ | ` options.verbose ` | no | ` false ` | Useful for debugging purposes |
6174
6275## License
6376
6477This project is licensed under the MIT License .
6578
66- ## Contributing
67-
68- Contributions are welcome! Feel free to open issues or submit pull requests.
69-
7079## Support
7180
7281If you encounter any issues , please open an issue on GitHub or let us know at [contact @logdash .io ](mailto :contact @logdash .io ).
0 commit comments