Skip to content

Shadey212/logtail-js-test

 
 

Repository files navigation

Logtail - JavaScript Logging Made Easy

Logtail dashboard

ISC License npm version npm version npm version

Collect logs from both the Node.js backend and your frontend.

Logtail is a hosted service that centralizes all of your logs into one place. Allowing for analysis, correlation and filtering with SQL. Actionable Grafana dashboards and collaboration come built-in. Logtail works with any language or platform and any data source.

Features

  • Simple integration. Allows for both backend and frontend logging.
  • Support for structured logging and events.
  • Automatically captures useful context.
  • Performant, light weight, with a thoughtful design.

Supported language versions

  • Node.js 12 or newer

Installation

Backend only

Install Logtail library for your Node.js backend code using the npm package manager:

npm install @logtail/node

Then you can either require it or import it into your codebase:

// require logtail class
const { Logtail } = require("@logtail/node");

// or import if you're using ES modules:
import { Logtail } from "@logtail/node";

Frontend only

Install Logtail library for your frontend code using the npm package manager:

npm install @logtail/browser

Then import the Logtail class:

// import logtail class
import { Logtail } from "@logtail/browser";

Another option is to use Content Delivery Network (CDN). You can import Logtail using the CDN by adding the following line into a page header:

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

Both backend and frontend

If your project contains both Node.js backend code and frontend code as well, you can use the universal package @logtail/js which combines the node and browser packages:

First, install the Logtail library using the npm package manager:

npm install @logtail/js

Then import or require it in your code:

// in your backend code:
const { Node: Logtail } = require("@logtail/js");

// in your frontend code:
import { Browser as Logtail } from "@logtail/js";

Example project

To help you get started with using Logtail in your projects, we have prepared a simple program that showcases the usage of Logtail logger. Before proceeding make sure you have npm and Node.js installed.

Download and install the example project

You can download the example project from GitHub directly or you can clone it to a select directory. Then run the following command to install all dependencies (@logtail/js):

npm install

Run the example project

To run the example application, simply run the following command:

node index.js <source-token>

Don't forget to replace with your actual source token which you can find by going to logtail.com -> sources -> edit.

You should see the following output:

Output:
All done! You can check your logs now.

This will generate a total of 4 logs, which will be displayed in your Logtail live tail view.

Explore how example project works

Learn how to setup JavaScript logging by exploring the workings of the example project in detail.


Get in touch

Have any questions? Please explore the Logtail documentation or contact our support.

About

The Logtail JavaScript library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 92.7%
  • JavaScript 7.3%