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

trunks-log

v2.0.3

Published

Simple JS logging to stdout!

Downloads

16

Readme

Trunks

npm version

trunks is a simple logger for NodeJS projects. It writes to stdout. I wrote trunks because I couldn't find a lightweight logger that did the bare minimum.

Installation

npm install --save trunks-log

Usage

trunks has 5 built in logging levels, debug, info, success, warn, error with predefined coloring in their output to make them easier to spot in a slew of logs.

  • debug prints in yellow
  • warn prints in yellow
  • info prints in cyan
  • success prints in green
  • error prints in red (including a passed error's stacktrace)

You can also use the generic log() function to print a log with a custom tag in it, this will be printed in magenta.

trunks supports variable replacement, meaning we can pass a template and a list of args to the functions to format the string.

trunks.info('Hello from {}!', 'trunks')

Will output: Hello from trunks! in the message section of the log.

trunks also supports passing objects into the template, they will be output as the result of a JSON.stringify() call.

Logging Levels

trunks currently supports 2 logging levels, PROD and DEBUG.

Any more ideas for further support of logging levels is greatly appreciated

  • DEBUG will log everything
  • PROD will NOT log debug level logs, or the stacktrace from error calls. (This is open to change)

Setting the level to prod should not effect performance as the level check occurs prior to the building of the template.

Instances

As of V2.0.0 trunks now supports the ability to namespace an instance of trunks via the constructor. This will change the second section of output in the console. The constructor is as follows:

trunks (
  namespace = 'APP',
  namespaceColor = 'magenta',
  level = 'DEBUG'
)

The trunks instance will default to a DEBUG logging level with the namespace APP and print the namespace in the color MAGENTA (as determined by your terminal).

  • namespace can be any string
  • namespaceColor must be one of: ['yellow', 'red', 'blue', 'green'], with the default as magenta
  • level must be one of ['debug', 'prod']

Example

const trunks = require('../trunks')

const ex = new trunks()

ex.warn('Hello from a trunks {} log!', 'warning')
ex.debug('Hello from a trunks {} log!', 'debug')
ex.log('test', 'Hello from a trunks {} log!', 'custom')
ex.info('Hello from a trunks {} log!', 'info')
ex.success('Hello from a trunks {} log!', 'success')
ex.error(new Error('Test error'), 'Hello from a trunks {} log!', 'error')

Will produce:

trunks example

Contributing

Please feel free to contribute to this project! I am open to any and all suggestions. Simply fork it and make a pr and we can discuss the changes there!

Roadmap

In the future versions of trunks I would like to add:

  • support for use in browsers