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

juta

v1.7.7

Published

Another logging package with no dependencies

Downloads

4

Readme

Juta

Another logging package without dependencies

Basic Usage

Juta exposes 4 basic logging functions, that log any arguments passed prefixed with date and colored:

  • log(): alias for console.log(), but treated at debug level
  • debug(): prints a blue debug message
  • info(): prints a white info message
  • warn(): prints a yellow warning message
  • error(): prints a red error message

Nodejs

var Juta = require('juta');

Juta.debug('debug message', { key : 'value' });
// prints: [03/16/17 15:48:02.0987] debug message { key : 'value' }
// (will not be printed if NODE_ENV is 'production')

Juta.info('this is an info message', 123, 'and more');
// prints: [03/16/17 15:48:02.0987] this is an info message 123 and more

Juta.warn('wow, warning message', 'another string');
// prints: [03/16/17 15:48:02.0987] wow, warning message another string

Juta.error('this is an error message');
// prints: [03/16/17 15:48:02.0987] this is an error message

Juta.error(new Error('here is the error'), 123);
// prints: [03/16/17 15:48:02.0987] ERROR: here is the error 123

Browser

TODO

Async logging

By default, Juta logs asynchronously through process.nextTick(). To disable this behaviour, use config or a configurable instance (see later).

Time

Juta offers a simple timer utility:

var timer = Juta.tic('my label');

var logTimerResult = true;

var end = timer.toc(logTimerResult)
// prints: [03/16/17 15:48:02.0987] my label timer: 0,0012312ms

Juta.debug(end+1)
// prints [03/16/17 15:48:02.0988] 1,0012312

The printed message is by default a debug message.

Global config

By calling Juta.set(config, value) it is possible to configure the global Juta instance. Here the possible configuration:

  • minLevel : minimum logging level (Juta.DEBUG, Juta.WARNING, etc)
    • Options: Juta.DEBUG, Juta.INFO, Juta.WARNING, Juta.ERROR
    • Nodejs default : Juta.DEBUG in development, Juta.INFO in production
    • Browser default : Juta.DEBUG
  • async : whether async logging should be enabled
    • Options: true or false
    • Nodejs default: true
    • Browser default: false
  • asyncFn : which async function to use
    • Options: setTimeout or process.nextTick
    • Nodejs default: process.nextTick
    • Browser default: setTimeout
  • colors : whether the colors should be enabled
    • Options: true or false
    • Nodejs default: true in develpment, false in production
    • Browser default: (not available)
  • showLine : whether to show the line in the log
    • Options: true or false
    • Nodejs default: true in develpment, false in production
    • Browser default: false
  • timestamp : type of timestamp
    • Options: Juta.OFFSET (ms since previous log), Juta.TIME, Juta.DATE
    • Nodejs default: Juta.TIME in develpment, Juta.DATE in production
    • Browser default: Juta.OFFSET
  • override : whether console should be overridden. If activated, all calls to console.* will actually go to the Juta implementation.
    • Options: true or false
    • Nodejs default: (not available)
    • Browser default: false

Configurable instances

It is possible to instanciate and object of type Juta that takes parameters in the constructor:

var Juta = require('juta');
var log = new Juta({namespace : 'ThisScript',
                    async : true,
                    minLevel : Juta.WARNING })

log.debug('debug message', { key : 'value' });
// doesn't print anything, minLevel is warning

log.info('this is an info message', 123, 'and more');
// doesn't print anything, minLevel is warning

log.warn('warning', 'message');
// prints: [03/16/17 15:48:02.0987] [ThisScript] warning message

log.error('error message');
// prints: [03/16/17 15:48:02.0987] [ThisScript] error message

var timer = log.tic('something');
time.toc(true);
// prints: [03/16/17 15:48:02.0987] [ThisScript] something timer: 0,0012312ms

Note: the instances expose the same functions and settings as the base class but can have independent configuration and namespaces