npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tinga

v6.0.1

Published

Small logging module made primarily for the browser.Supports multiple log levels.

Downloads

374

Readme

Tinga

Small browser logging module with the ability to send logs to the remote endpoint

Test Codecov GitHub license

Small (~1KB) logging module primarily for the browser. It has a few logging levels that can be enabled and disabled at runtime.

screen

Install

npm i tinga

Motivation

While pino is an excellent logger for the backend all the functionality is not needed for the frontend, it has a bigger file size, and the default formatting doesn't suit the browser console hence, Tinga has been created.

Usage

Usage is very simple, by default you don't need to pass in any configuration, but I recommend using at least the label property for added visibility in the browser console.

import Tinga from 'tinga'

const logger = new Tinga({ label: 'demo' })
logger.log('Hello world')
logger.error('Wrong username')

Configuration

Tinga accepts a configuration object to customize the Tinga instance.

import Tinga, { type Config } from 'tinga'

const config: Config = {
  ctx: { name: 'Ivan' }, // context
  label: 'demo',
  processData: (ctx, data, _info: { level: Level; label?: string }) => {
    return {
      ctx,
      data
    }
  }
}

const logger = new Tinga(config)
  • ctx: is additional data that will be logged with every log level.
  • label: string to be logged right next to the level.
  • processData: a function that is called just before the data is logged to the console, it should at least return an object with the data property which is an array of data to be passed to the console (as rest arguments).

Context

Context is additional data that can be set per logger instance, that will be passed to every log level. You can get and set context at runtime.

const looger = new Tinga({ ctx: { name: 'ivan' } })

logger.getContext()
logger.setContext({ name: 'Mario' })

Levels

Seven levels can be used for logging.

| Name | Value | | -------- | ----- | | trace | 10 | | debug | 20 | | info | 30 | | warn | 40 | | error | 50 | | critical | 60 | | silent | 100 |

You can get and set levels at runtime, all levels above the currently set level will be logged. silent level is the only level that is not logged, so if you want to disable logging, you can use the silent level.

logger.getLevel()
logger.setLevel('silent')
logger.getLevels() // get all levels

Child instances

You can create a child instance of an already created Tinga instance, by creating a child instance, it will inherit all the configuration properties of the parent. Child instances are useful when you want to slightly modify the original version, by for example having a different label, for modifying the parent context. For a child instance, you can directly set the new context, or by passing a function as the context property you can derive a new context from the parent context, as the example below shows.

const logger = new Tinga(config)

const childLogger = logger.child({
  label: 'new-labels',
  ctx: (parentCtx) => {
    return {
      ...parentCtx,
      newProps: 'hello from child'
    }
  }
})

childLogger.log('helo')

Examples

Check out this Next.js logging demo where I'm using (comparing) Pino and Tinga on the same page.