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

@torgeilo/logger

v0.0.1

Published

Tiny, customizable logger for the browser

Downloads

10

Readme

@torgeilo/logger

Tiny, customizable logger, designed for the browser.

It's less than 400 bytes minified.

Features

  • Namespaces.
  • Pluggable log handlers.
  • Typed and customizable log levels (called tags internally).
  • Basic minimal console log handler (default).
  • Styled console log handler (separate bundle).
  • No dependencies.

Getting started

Install:

npm install @torgeilo/logger

Use:

import { getLogger } from '@torgeilo/logger';

const logger = getLogger('my namespace');

logger.log('Hello');
logger.debug('world');

Default console output of the above (with levels log and debug):

my namespace: Hello
my namespace: world

Default levels: debug, log, info, warn, error.

Customizing

Disable logging

Empty the logHandlers array however you prefer. A clear() method is added for convenience:

import { logHandlers } from '@torgeilo/logger';

logHandlers.clear();

Styled console log handler

Import and add the styled console log handler to the logHandlers array.

import { logHandlers } from '@torgeilo/logger';
import { StyledConsoleLogHandler } from '@torgeilo/logger/styled-console-log-handler.js';

logHandlers.clear(); // Remove the default log handler.
logHandlers.push(new StyledConsoleLogHandler());

Custom log levels/tags

import { getLogger } from '@torgeilo/logger';

const logger = getLogger<'Finn' | 'Jake'>('Together Again');

logger.Finn('Oh, man, are they angry!');
logger.Jake('Angry and fresh outta ice cream!');

Default console output (with level log):

Together Again/Finn: Oh, man, are they angry!
Together Again/Jake: Angry and fresh outta ice cream!

Custom log handler

Implement the LogHandler interface and add your implementation to the logHandlers array. The interface:

export interface LogHandler {
  log(namespace: string, tag: string, message: unknown, ...messages: unknown[]): void;
}

The tag is typically the log level.

Possibilities

You could:

  • Make a log handler which only outputs errors or warnings.
  • Make a log handler which shows the log in an HTML element on screen.
  • Make a log handler which sends errors to a remote error tracker.
  • Make a log handler which sends a custom tag to a remote tracker, like logger.metric(123);.
  • Make a test reporter which logs the test run output, and a log handler which sends it somewhere useful, in addition to the console.

Contributing

Smaller bug reports are welcome.

I don't have capacity for much else. You're probably better off forking if you want to change things.