GithubHelp home page GithubHelp logo

loglevel-sentry's Introduction

loglevel-sentry

npm version npm

Introduction

This repo allows you to log + track logs using sentry

Features

  • Typescript compatible. Includes Type definitions

Installation

Bundling

This module is distributed in 3 formats

  • esm build dist/loglevelSentry.esm.js in es6 format
  • commonjs build dist/loglevelSentry.cjs.js in es5 format
  • umd build dist/loglevelSentry.umd.min.js in es5 format without polyfilling corejs minified

By default, the appropriate format is used for your specified usecase You can use a different format (if you know what you're doing) by referencing the correct file

The cjs build is not polyfilled with core-js. It is upto the user to polyfill based on the browserlist they target

Directly in Browser

CDN's serve the non-core-js polyfilled version by default. You can use a different

jsdeliver

<script src="https://cdn.jsdelivr.net/npm/@toruslabs/loglevel-sentry"></script>

unpkg

<script src="https://unpkg.com/@toruslabs/loglevel-sentry"></script>

Usage

Add @toruslabs/loglevel-sentry to your project:

To use this module:

  1. Install the package npm i @toruslabs/loglevel-sentry

  2. Create your loglevel instance and install this plugin to enable Sentry:

import loglevel from "loglevel";
import * as Sentry from "@sentry/browser";
// Node.js: import * as Sentry from "@sentry/node";
import LoglevelSentryPlugin from "@toruslabs/loglevel-sentry";

logger = loglevel.getLogger("__LOGGER_NAME__");

const plugin = new LoglevelSentryPlugin(Sentry);
sentry.install(logger);

(Optional) You can replace loglevel with other logging library by using loglevel methodFactory API:

import loglevel from "loglevel";
import pino from "pino";
import * as Sentry from "@sentry/browser";
// Node.js: import * as Sentry from "@sentry/node";
import LoglevelSentryPlugin from "@toruslabs/loglevel-sentry";

const logger = loglevel.getLogger("__LOGGER_NAME__");
logger.methodFactory = (method, level, name) => {
  const alt = pino(name, level);
  return alt[method];
};

const sentry = new LoglevelSentryPlugin(Sentry);
sentry.install(logger);

Info

Is 100% compatible with loglevel API. Events/errors will be reported for all enabled log functions.

Best practices

Though it isn't compulsory, it is recommended to call log functions with following signatures:

  • log.trace, log.debug, log.info, and log.warn: (msg: string, ...others: any[]).

  • log.error: (err: Error, ...others: any[]).

If you always want to monitor a specific event regardless of configured log level, use the plugin API:

const sentry = new LoglevelSentryPlugin(Sentry);
sentry.install(logger);

sentry.trace("this", "message", "will always be reported.");

Requirements

  • This package requires a peer dependency of @babel/runtime
  • Node 18+

loglevel-sentry's People

Contributors

chaitanyapotti avatar phuctm97 avatar himanshuchawla009 avatar arch1995 avatar tetratorus avatar metallicalfa2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.