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

typedlog

v1.1.1

Published

Tiny logging utility with Typescript support

Readme

typedlog - Minimalistic log implementation with TypeScript support

This library was created due to my dissatisfaction with ulog's lack of Typescript support. This allows one to create logging modules to use in their programs. When minified, typedlog takes up around 2.36 kB of space. When minzipped, typedlog takes up 1.05 kB of space.

Installation

If you would like to use typedlog in a Node program, install it via npm or yarn.

$ npm i --save typedlog
# ...or, if you use yarn
$ yarn add typedlog

If you would like to use typedlog inside of the web browser, pull it from unpkg.

<script src="https://unpkg.com/typedlog" type="text/javascript />
<script type="text/javascript">
// your code here
</script>

Usage

const logger = require("typedlog").logger("my-module-name");
// alternatively, if you're using typed log in a web browser, do:
const logger = typedlog.logger("my-module-name");

logger.info("Starting up!");
logger.debug(`The result of 2+2 is ${2+2}`);
logger.warn("Be aware of what I'm doing");
logger.log("Reached this point in the program");

if (err) {
  logger.error("An error occurred: ", err);
  logger.trace("Made it this far.");
}

Log Level

The "log level" of each module can be set, using one of three strategies:

1). Set it manually in the logger

const tlog = require("typedlog");
const logger = tlog.logger("my-module-name");

logger.level = tlog.LogLevel.Warn;

logger.error("Outputs an error to the console");
logger.info("Does not output anything");

2). Set it in an environment variable

$ LOG=warn node program.js

3). Set it in the query

https://mysite.com/mypage?log=warn

Custom Transforms

Transforms take the following function signature:

type Transform = (args: any[], level: LogLevel, modname: string) => void;

For instance, in order to add a transform to preprend the module name to the output:

const logger = tlog.logger("my-module-name");
logger.transforms.push((args: any[], level: tlog.LogLevel, modname: string) => {
  args.unshift(`[${modname}]`);
});

logger.log("Hello world!"); // [my-module-name] Hello world!

Transforms are applied in the order that they are appended to the transforms array.

Custom console object

By default, typedlog will simply forward logging requests to the console global object. However, if a different object is desired, it will have to implement the following interface:

type LogFunction = (...args: any[]) => void;

interface ConsoleLikeObject {
  error: LogFunction;
  warn: LogFunction;
  info: LogFunction;
  log: LogFunction;
  debug: LogFunction;
  trace: LogFunction;
}

An example of this, using a custom object to write to a file.

const fs = require("fs");
const tlog = require("typedlog");
const util = require("util");

const stream = fs.createWriteStream("logs.txt");

let fileOutput = {};
fileOutput.error = fileOutput.warn = fileOutput.info = fileOutput.log = fileOutput.debug = fileOutput.trace = function(...args: any[]) {
  const output = util.format.apply({}, args);
  stream.write(output, "utf8");
}

const logger = tlog.logger("my-module-name", fileOutput);
logger.log("This should go to the file");

Test Suite

typedlog uses tape for testing. In order to run the test suite, first install typedlog's development dependencies.

$ npm ci
# ...or, if you use yarn
$ yarn install

$ npm run test

License

BSD-3-Clause