@logstream/logstream
v0.1.13
Published
The TypeScript client library for logstream
Downloads
11
Maintainers
Readme
@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.