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

@arpinum/log

v6.0.0

Published

Simple module to log on stdout or stderr

Downloads

696

Readme

@arpinum/log Build Status

We are drowning in information but starved for knowledge.
John Naisbitt

@arpinum/log is a simple module to log on stdout or stderr.

Installation

npm install @arpinum/log --save

Default logger

Just import default logger and start yelling messages:

import { logger } from "@arpinum/log";

logger.info("Something happened");

Which outputs :

2017-01-30T09:15:04.821Z - info: [default] Something happened

Logging methods

Available methods are:

  • debug
  • info
  • warn
  • error

Each level uses corresponding method on console global object and fallback to console.log if missing for runtime environment.

Custom logger

You can create a fine tuned logger:

import { createLogger } from "@arpinum/log";

const logger = createLogger({ level: "error" });
logger.info("Something happened");
logger.error("Some error");

Which outputs :

2017-01-30T09:23:33.417Z - error: [default] Some error

Options

You can pass those options during logger creation:

  • level
    • minimum logging level amongst all, debug, info, warn, error, off
    • default is info
    • ARP_LOG_LEVEL env var may be used to set level
  • category
    • the category displayed in message, useful to filter logs
    • default is default
  • fileName
    • a category can be created from a base name without extension of a file
  • filter
    • a regex to filter matching categories
    • default is .* (open bar)
    • ARP_LOG_FILTER env var may be used to set filter
  • getDateString
    • a function to get a formatted date
    • default function returns new Date().toISOString()
    • provide null if you do not want a date at all
  • getLogInputs
    • a function to get inputs given to console methods
    • used to format message as you want
    • see Customize message below

Filtering logs

If you have multiple logger instances with various categories, you can filter logs using filter options or ARP_LOG_FILTER env var.

Example:

// program.js
const mainLogger = createLogger({ category: "main" });
const serviceLogger = createLogger({ category: "service" });

mainLogger.info("Application started");
serviceLogger.info("Doing some stuff");

May be run with LOG_FILTER=serv node program.js to output:

2017-01-30T09:32:31.351Z - info: [service] Doing some stuff

About category:

File name usage:

import { createLogger } from "@arpinum/log";

const logger = createLogger({ fileName: __filename });
logger.info("Something happened");

Which outputs :

2017-01-30T09:32:31.351Z - info: [MySuperClass] Something happened

Customize message

getLogInputs will be called for each log with an object containing:

  • date: the current date string
  • category: the configured category
  • level: the logger level
  • args: all the provided args

Example:

const logger = createLogger({
  getLogInputs: ({ date, category, level, args }) => [
    `${date}|${category}|${level}`,
    ...args,
  ],
});

logger.info("My", "message");

// 2019-11-19T16:45:58.419Z|default|info My message

License

MIT