child0x

child0x content code

cURL
curl --request GET \
  --url https://logtail.com/api/v1/sources \
  --header "Authorization: Bearer $TOKEN"

Where do you want to collect your JavaScript logs from?

Logging from Node.js

Collect logs from the backend code of your application.

1. Install

Install Logtail Node NPM package:

 
npm install @logtail/node

2. Setup

Set up Logtail client:

 
const { Logtail } = require("@logtail/node");
const logtail = new Logtail("$SOURCE_TOKEN");

Replace $SOURCE_TOKEN with your actual Logtail source token.
Get token for new or existing sources at Logtail -> Sources.

3. Start logging ๐ŸŽ‰

 
logtail.error("Something bad happend.");
logtail.info("Log message with structured data.", {
    item: "Orange Soda",
    price: 100.00
});

You should see your logs in Logtail -> Live tail.

Node.js version 12 or higher is required.

Logging from browser

Collect logs from your frontend code.

1. Install

Install Logtail Browser NPM package:

 
npm install @logtail/browser

2. Setup

Set up Logtail client:

 
import { Logtail } from "@logtail/browser";
const logtail = new Logtail("$SOURCE_TOKEN");

Replace $SOURCE_TOKEN with your actual Logtail source token.
Get token for new or existing sources at Logtail -> Sources.

Alternatively, you can use Content Delivery Network.
Import Logtail using the CDN by adding the following line into the page header:

 
<script src="https://unpkg.com/browse/@logtail/browser@latest/dist/umd/logtail.js"></script>

3. Start logging ๐ŸŽ‰

 
logtail.error("Something bad happend.");
logtail.info("Log message with structured data.", {
    item: "Orange Soda",
    price: 100.00
});

You should see your logs in Logtail -> Live tail.

Logging from browser and Node.js

Collect logs from both backend and frontend code of your Node.js application.

1. Install

Install Logtail JavaScript NPM package:

 
npm install @logtail/js

2. Setup

Set up Logtail client in backend and frontend code:

Backend code
const { Node: Logtail } = require("@logtail/js");
const logtail = new Logtail("$SOURCE_TOKEN");
Frontend code
import { Browser as Logtail } from "@logtail/js";
const logtail = new Logtail("$SOURCE_TOKEN");

Replace $SOURCE_TOKEN with your actual Logtail source token.
Get token for new or existing sources at Logtail -> Sources.

3. Start logging ๐ŸŽ‰

Log the same way in backend and frontend:

 
logtail.error("Something bad happend.");
logtail.info("Log message with structured data.", {
    item: "Orange Soda",
    price: 100.00
});

You should see your logs in Logtail -> Live tail.

Node.js version 12 or higher is required.

Need help?

Please let us know at [email protected].
We're happy to help! ๐Ÿ™

Additional information

Want to learning more about log levels and middleware? Continue to the [Advanced usage of Logtail JavaScript client][docs-logs-javascript-and-node-log-types].

New to logging? See the Intro guide to Node.js logging and the Best practices for logging in Node.js.

NPM packages

Package @logtail/js provides a convenient way to install and manage both @logtail/node and @logtail/browser NPM packages. You can install the packages separately if you wish to.