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

@haxtra/logger

v0.9.1

Published

Configurable console logger with support for multiple independent groups

Downloads

1

Readme

logger

Configurable console logger with support for multiple independent groups.

Screenshot

Install

npm i @haxtra/logger

Usage

Basic

const Logger = require('@haxtra/logger')

const log = Logger()
log.info('Hello world!')
// > 2027-09-20 19:50:57.810 [app|info] Hello world!

Multiple loggers

// equivalent
const apilog = Logger('api')
const apilog = log.spawn('api')

Set name and level at creation time

// equivalent
Logger('api', 'warning')
Logger({group:'api', level:'warning'})

log.spawn('api', 'warning')
log.spawn({group:'api', level:'warning'})

Log arbitrary objects

log.info('Mysterious object', {foo:'bar'})
// > 2027-09-20 19:50:57.810 [app|info] Mysterious object
// > { foo: 'bar' }

Config

Global

Configure global settings

// showing defaults
Logger.config({
	level: 'trace',   // global log level, for instances that follow global setting (see Levels below)
	group: true,      // display group name, ie [app|info] vs [info]
	timestamp: true,  // display timestamps
	milli: true,      // display timestamps with millisecond resolution
	color: true,      // use colors in logging
	icons: false,     // use icons instead of level names, ie [I] vs [info]
})

Global settings can also be changed via logger instance

log.setGlobalConfig(object)

Instance

Set level

log.setLevel(level)

Set global level

log.setGlobalLevel(level)

Change group name

log.setGroup(groupName)

Log Levels

By default, instances have a level of null, and they follow the global setting. But you can, for example, set error as the global level and then trace for a particular instance to get a detailed log from just that one particular module.

// info, logs to stdout
log.trace
log.debug
log.dev
log.success
log.ok
log.info
log.notice

// errors, logs to stderr
log.warning
log.alert
log.error
log.exception
log.critical
log.fatal

Set levels by:

log.setLevel(level)       // instance level
log.setGlobalLevel(level) // global level

Pausing output

Logging can be paused anytime by:

// cycle instance logging
log.pause()
log.resume()

// cycle global logging
log.pauseGlobal()
log.resumeGlobal()

Remove logger

Delete logger instance by:

log.dispose()

Haxxor Tricks

Access underlying state via these objects:

log.$ // active instances
log.localConfig
log.globalConfig

File logging

Currently logger does not support file logging, but you can redirect stdout and stderr to a file, by using the commands below. Note: you might want to disable color output, or strip ansi control codes on the fly with tools like ansi2txt or sed.

# log stdout and stderr to one file
node app.js >> app.log 2>&1

# log stdout and stderr to separate files
node app.js >> stdout.log 2>> stderr.log

License

MIT