open-index/open-npm huggingface dataset:
npm package: @logrrr/js-sdk
Description: JavaScript SDK for the Logrrr API. For use in browser and other runtime environments.
Author: Paulo Queiroz
Latest version: 0.0.2

# @logrrr/js-sdk

This is the JavaScript SDK for the Logrrr API. It can be used in browsers,
Node.js, and other runtimes such as Bun and Deno.

## Installation

```bash
npm install @logrrr/js-sdk
```

## Usage

```javascript
import { LogrrrClient } from "@logrrr/js-sdk";

const logrrr = new LogrrrClient({
  apiKey: "<your api key>",
  apiEndpoint: "<api endpoint>",
});

const onButtonClicked = () => {
  const value = document.getElementById("input").value;
  // Simple text log
  logrrr.log("button-clicked");

  // Log with metadata
  logrrr.log("button-clicked", { value });
};

// Automatically log unhandled errors

window.addEventListener("error", (event) => {
  logrrr.error(event.error.toString());
  // Add more metadata as needed
  logrrr.error(event.error.toString(), {
    kind: "error",
    filename: event.filename,
  });
});
```

That's it! Logs are not batched, so each call to `log` will result in a network
request. This is intentional to ensure that logs are sent as soon as possible.
This also simplifies the shutdown process, as you don't need to worry about
flushing logs before the application exits (or the user leaves the page).