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

loggy-log

v2.2.2

Published

A little logger which depends on environ variable

Downloads

2

Readme

Loggy-Log

npm version npmVersion

Loggy-log makes it easy to create logs in pipes (like in ramda) based on a pino logger (formatted with pino-pretty)

Install

$ yarn add loggy-log

or

$ npm install loggy-log

Usage

Set offset of logs level

The values supported are trace, debug, info, warn and error.

PINO_LEVEL=info

you can do it easily with dotenv

By setting the level to info, you allow the logs of info and those above, i. e. warn and error

The default value is trace

Set logger title

You can set your log title when require loggy-log module

// test.js
const L = require('loggy-log')("Log Demo");
L.info('Initial message : %s')('hello world');

it will produce as result

[2020-02-22 13:13:42.196 +0000] INFO  (Log Demo): Initial message : hello world

But if you don't set a title, the default title is your filename:

// test.js
const L = require('loggy-log')();
L.info('Initial message : %s')('hello world');

it will produce as result

[2020-02-22 13:13:42.196 +0000] INFO  (test): Initial message : hello world

Utilisation

The logs functions are tap so can be use in pipe. there is an example with ramda:

const R = require('ramda');
const L = require('loggy-log')();

const main = R.pipe(
  L.info('Processing start'),
  L.debug('Initial value : %d'),
  R.add(5),
  L.debug('Add value : %d'),
  R.multiply(4),
  L.debug('Multiply value : %d'),
  R.objOf('data'),
  L.info('Final Object : %o')
);

main(2);
[2020-02-22 15:22:03.139 +0000] INFO  (test): Processing start
[2020-02-22 15:22:03.142 +0000] DEBUG (test): Initial value : 2
[2020-02-22 15:22:03.142 +0000] DEBUG (test): Add value : 7
[2020-02-22 15:22:03.142 +0000] DEBUG (test): Multiply value : 28
[2020-02-22 15:22:03.143 +0000] INFO  (test): Final Object : {"data":28}

But if you want to use the classic Pino logger, you can get it with L.getPino()

const L = require('loggy-log')();
const pino = L.getPino();
const a = 1;
const b = 2;
const c = a + b;
pino.info('%d + %d = %d', a, b, c);
[2020-02-22 15:23:55.207 +0000] INFO  (test): 1 + 2 = 3

Exposed functions

error, warn, info, debug, trace

a -> a -> a

Takes a, logs it, and returns a

Note about log

Got the same methods as before, but take another argument, placed first, which is the log level.

Extra feature

I thought than print object in log could be interesting but I found it difficult to read an object logged with "%o". So I created a new data type with "%fo". I will print out object using json-colorizer with option { pretty: true } So for exemple:

const R = require('ramda');
const L = require('loggy-log')();

const main = R.pipe(
  L.info('Processing start'),
  L.debug('Initial value : %d'),
  R.add(5),
  L.debug('Add value : %d'),
  R.multiply(4),
  L.debug('Multiply value : %d'),
  R.objOf('data'),
  L.info('Final Object : \n%fo')
);

main(2);

the result will be like that

[2020-03-08 16:12:46.142 +0000] INFO  (test): Processing start
[2020-03-08 16:12:46.150 +0000] DEBUG (test): Initial value : 2
[2020-03-08 16:12:46.150 +0000] DEBUG (test): Add value : 7
[2020-03-08 16:12:46.151 +0000] DEBUG (test): Multiply value : 28
[2020-03-08 16:12:46.153 +0000] INFO  (test): Final Object : 
{
  "data": 28
}