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 🙏

© 2026 – Pkg Stats / Ryan Hefner

bark-logger

v1.0.2

Published

Simple log framework for browser and server

Readme

bark-logger

A small, zero-dependency logger for Node.js and the browser. It prints colored, timestamped lines to the console, filters by level, and lets you plug in your own outputs.

[14:37:39] INFO  (main) Server started on port 3000
[14:37:41] WARN  (db) Slow query: 1250ms
[14:37:42] ERROR (api) Request failed: ECONNRESET

Install

npm install bark-logger

TypeScript types are included. The package works with both import and require.

Quick start

import { getLogger } from 'bark-logger';
// or: const { getLogger } = require('bark-logger');

const log = getLogger();

log.info('Server started on port 3000');
log.warn('Disk space is getting low');
log.error('Something went wrong');

Log levels

There are six levels, from least to most severe:

| Level | Method | Value | | ------- | --------------- | ----- | | TRACE | log.trace(msg) | 0 | | DEBUG | log.debug(msg) | 1 | | INFO | log.info(msg) | 2 | | WARN | log.warn(msg) | 3 | | ERROR | log.error(msg) | 4 | | FATAL | log.fatal(msg) | 5 |

You can also pass the level explicitly with log.log(msg, Levels.WARN). Without a level, log.log(msg) logs at TRACE.

Named loggers

Give each part of your app its own name so you can tell where a line came from. The name appears in parentheses after the level.

const dbLog = getLogger('db');
const apiLog = getLogger('api');

dbLog.warn('Slow query: 1250ms');       // [14:37:41] WARN  (db) Slow query: 1250ms
apiLog.error('Request failed');         // [14:37:42] ERROR (api) Request failed

getLogger(name) returns the same instance every time you ask for the same name, so you can call it from any file without passing loggers around. The default name is main. Use new Logger(name) instead if you want a fresh, uncached instance.

The level methods are bound to their logger, so destructuring works:

const { info, error } = getLogger('worker');
info('Job queued');

Choosing which levels to show

Messages below the threshold are ignored. The default threshold is INFO, so TRACE and DEBUG messages are hidden unless you lower it.

With an environment variable (Node.js)

Set LOGLEVEL to a level name (any case) or its number:

LOGLEVEL=debug node app.js
LOGLEVEL=4 node app.js

An unrecognized value falls back to INFO. The variable is read once, when the library is first loaded.

In code

import { config, Levels } from 'bark-logger';

config.threshold = Levels.DEBUG;

The config is shared by every logger in the process, including loggers created in other modules or by other packages that use bark-logger. Changing it in one place changes it everywhere, at any time.

Custom outputs (actions)

Every message that passes the threshold is handed to each function in config.actions. By default the list holds a single console printer. Add your own functions to send logs somewhere else:

import { config, Levels } from 'bark-logger';

config.actions.push((timestamp, level, name, message) => {
  if (level >= Levels.ERROR) {
    errorList.push(`${timestamp.toISOString()} [${Levels[level]}] ${name}: ${message}`);
  }
});

Each action receives:

| Argument | Type | Description | | ----------- | -------- | -------------------------------------------------------- | | timestamp | Date | When the message was logged | | level | Levels | The level number; Levels[level] gives its name | | name | string | The logger's name | | message | string | The message text |

Actions can be async, for example to post logs to a server:

config.actions.push(async (timestamp, level, name, message) => {
  await fetch('https://logs.example.com/ingest', {
    method: 'POST',
    body: JSON.stringify({ timestamp, level: Levels[level], name, message })
  });
});

A failing action never breaks your app. If an action throws or its promise rejects, the error is reported with console.error and the remaining actions still run.

To replace the console output entirely, assign a new list. Keep a copy of the defaults if you might want them back:

const defaultActions = [...config.actions];

config.actions = [myAction];            // only your action
config.actions = [...defaultActions];   // console output restored

In TypeScript, the action type is available as:

type LogAction = typeof config.actions[number];

Browser use

bark-logger runs in the browser through any bundler. There's no LOGLEVEL environment variable there, so set config.threshold in code. Output uses ANSI color codes, which most terminals render. Support in browser developer consoles varies, and unsupported consoles show the codes as raw text.

Development

npm test

| Script | What it does | | --------------- | ----------------------------------------------------------------- | | npm test | Compiles with tsc, then runs the Jest tests in build/tests | | npm run build | Compiles to build/ | | npm run local | Compiles in watch mode | | npm run link | Builds the package into out/ and runs npm link for local testing | | npm run clean | Deletes build/ and out/ | | npm run prerelease | Builds the package into out/ and publishes it to npm under the next tag |

Pushing to main runs the tests on Node 22, 24 and 26. If the version in package.json isn't on npm yet, CI publishes it and creates a matching GitHub release.

License

MIT