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

loggerwhale

v1.3.0

Published

Simple logger supporting output patterns, text formatting, message severity levels, etc.

Downloads

2

Readme

loggerwhale

Simple logger supporting output patterns, text formatting, message severity levels, etc.

Installation

npm

 npm install loggerwhale

yarn

yarn add loggerwhale

Usage

Example

const log = require('loggerwhale');

// Configuring the logger configuration
// This will change the template property that is responsible for the output template
log.config = {
	template: '%rfp > %t',
};

// Display text to the console
log('Also, Powell and Donovan find food, but it\'s all baked beans and milk.');

Output

folder\file.js > Also, Powell and Donovan find food, but it's all baked beans and milk.

Table of contents

Properties

log.config

log.config - configuration for your log. Has four possible properties:

template - String. Template for future conclusions. Read more. minLevel - Number or function. Minimum required output level. maxLevel - Number or function. Maximum required output level. timeFormat - The format of the output time in the moment format. Read more.

Example

log.config = {
	template: '[%ft] %t',
	minLevel: 6,
	maxLevel: 11,
	timeFormat: 'H:mm:ss',
};

// Logging
log('So Lanning calls Calvin in and they call Byerley.', 5);
log('And Quinn doesn\'t like Stephen Byerley.', 11);
log('So Byerley does hit him.', 12);

Output

[9:02:45] And Quinn doesn't like Stephen Byerley.

log.defaultConfig

log.defaultConfig - The standard configuration that will be used for new loggerwhale connections in other files. Changes to log.defaultConfig immediately apply to the usual log.config and accepts the same properties as it does.

Example

file.js:

const log = require('loggerwhale');
log.defaultConfig = {
  	template: 'Question from %ffn: %t',
};
require('./anotherFile.js');

log('Or would that break the First Law?');

anotherFile.js

const log = require('loggerwhale');

log('Could a robot do that?');

Output

Question from anotherFile.js: Could a robot do that?
Question from test.js: Or would that break the First Law?

Methods

log

log - main function that loggerwhale exports. Has 3 arguments: the text of the log, it's level and the styles string. None of this is necessary. Returns itself, which allows you to make chains. Standard level - 0.

Example

log.config = {
   	template: '[%l] %t'
};

// This message is displayed with cyan  background and black text.
log('It\'s 2032.', 42, 'bgCyanBright black');

Output

[42] It's 2032.

log.log

log.log - Same as regular log. It is necessary for convenience of creation of chains.

Example

log('Three Laws of Robotics:');

log.config = {
	template: '%c. %t',
};

log
	.log('A robot may not injure a human being or, through inaction, allow a human being to come to harm.')
	.log('A robot must obey the orders given it by human beings except where such orders would conflict with the First Law')
	.log('A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.');

Output

Three Laws of Robotics:
1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.
2. A robot must obey the orders given it by human beings except where such orders would conflict with the First Law
3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.

log.info

log.info - preset with a ready set of styles. Displays the text in blue. Standard level - 0. Has the same arguments as the normal log.

Example

// This message is displayed in blue
log.info('We have no idea what that means, but it sounds good.');

log.warn

log.warn - preset with a ready set of styles. Displays the yellow text with an underscore. Standard level - 1. Has the same arguments as the normal log.

Example

//This message is displayed in yellow and with an underscore
log.warn('So Lanning calls Calvin in and they call Byerley.');

log.error

log.error - preset with a ready set of styles. Displays the text in red. Standard level - 2. Has the same arguments as the normal log.

Example

//This message is displayed in red
log.error('So Byerley does hit him.');

log.success

log.success - preset with a ready set of styles. Displays the text in bright green. Standard level - 2. Has the same arguments as the normal log.

Example

//This message is displayed in red
log.info('But we don't get to hear the plan.');

log.done

log.done - preset with a ready set of styles. Displays the text in green. Standard level - 3. Has the same arguments as the normal log.

Example

//This message is displayed in red
log.done('That's the way this story ends — without any real evidence.');

log.resetCounter

log.resetCounter -a function that resets the internal counter value for the %c tag. Accepts one optional argument from which the counter will start counting.

Example

log.config = {
	template: 'Meanwhile, it was 196%c.',
};

log()
log()
log()

log.resetCounter(7);

log()
log()
log()

Output

Meanwhile, it was 1960
Meanwhile, it was 1961
Meanwhile, it was 1962
Meanwhile, it was 1967
Meanwhile, it was 1968
Meanwhile, it was 1969

log.addPreset

log.addPreset - The method that will give its preset a similarity to log.info and log.error. It takes 3 arguments: it has a mark, a standard level and itэs styles.

Example

log.addPreset('note', 1, 'inverse');

// Displays text with white background and black text
log.note('A towel is perhaps the most necessary item!');

Output template

The template property specifie inside the log.config object and represents the log output template. At each call to the loggerwhale, replace the special template tags with their properties.

Template tags %% - outputs a literal "%" %t - outputs the text of the log %afp - outputs the absolute path to the file

C:\applications\greatesApp\app.js

%rfp - outputs the relative path to the file

router\index.js

%ft - the date formatted using the moment

5/17/18 12:34:56 AM

%st - outputs the number of milliseconds passed from the start of the application %llt - outputs the number of milliseconds passed since the last log %ffn - outputs full file name

master.min.js

%sfn - outputs simplified file name

master

%l - outputs the level of log %c - outputs displays the current value of the counter

Example

log.config = {
	template: 'from %rfp at %ft > %t',
};

log('First, Byerley went to the Eastern Region.');

Output

from tests\template.js at 3/17/07 5:12:36:322 PM > First, Byerley went to the Eastern Region.

Output styles

A string of style names that is passed by the third argument to the log function. Loggerwhale stylizes logs with chalk and style names are the same as. Read more.

Example

// Displays text with bright yellow background
log('If you can believe it, that\'s how the story ends.', 0, 'yellowBright');

// Displays invisible text
log('I will see no more.', 0, 'hidden');

// Displays text with strikethrough (not widely supported)
log('My life is over.', 0, 'strikethrough');