@logstream/logstream
TypeScript icon, indicating that this package has built-in type declarations

0.1.13 • Public • Published

@logstream/logstream

This is a TypeScript client library for logstream. It allows you to log information from your JavaScript applications to your logstream server directly.

Installation

npm install @logstream/logstream

Importing Logstream

Firstly, you would need to import the Logstream from the @logstream/logstream library.

import { Logstream } from "@logstream/logstream";

Initializing Logstream

To initialize logstream, create a new instance of Logstream. As an argument, you need to pass the forwarding URL to your logstream organisation.

const logstream = new Logstream("https://logstream.ai/v1/stdin?token=123..");

Creating a Log Channel

Next, create a new Log Channel using the channel method of the logstream object and passing in the channel name.

const channel = logstream.channel("Test log");

Logging Data

The log data can be of any data type including objects and arrays.

channel.log({
  address: {
    street: "123 Main St",
    city: "Exampleville",
  },
});

Logging Errors

To log errors, use the built-in functions: warn, error, and critical.

channel.warn(new Error("This is a warning message"));
channel.error(new Error("This is an error message"));
channel.critical(new Error("This is a critical message"));

The warn, error, and critical functions each represent different levels of esception and they work similarly to the log function.

Package Sidebar

Install

npm i @logstream/logstream

Weekly Downloads

0

Version

0.1.13

License

ISC

Unpacked Size

22.4 kB

Total Files

7

Last publish

Collaborators

  • walteradapta