JSPM

  • Created
  • Published
  • Downloads 430
  • Score
    100M100P100Q97362F

fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, clearing, & presets

Package Exports

  • fliplog
  • fliplog/debugFor
  • fliplog/debugFor.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fliplog) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

⛓🔈 fliplog

fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, clearing, & presets

NPM version MIT License fliphub

Screenshot

usage

yarn add fliplog
npm i fliplog --save
const log = require('fliplog')

📋 legend:

👋 basics

log
  .data({anyKindOfData: true}) // .json, .stringify, .tosource, .verbose
  .text('text to use, this is what gets colored')
  .color('bold') // any cli-color, chalk, available as shorthands
  .echo() // outputs the log, .return to return the formatted values

🎀 stringifying

json

prettyjson

// optional second arg for options passed into pretty json
log.json({eh: 'prettified'})

stringify

javascript-stringify

// args are the same as javascript-stringify
log.stringify({data: 'can stringify deep things'})

🙊 silencing

  • to disable outputting a log, .silence() (optional true/false arg)
  • to disable all logs, .shush()
  • to enable all logs, .unshush()

capture all

capture output of all console logs everywhere

log.startCapturing()

console.log('this will be captured')
log.stopCapturing()

// captured data is available here
const saved = log.savedLog

return

return only echos from fliplogs, useful for getting formatted data.

// formatted data
const {text, data} = log
  .data({catchMeIfYouCan: true})
  .text('gingerbread man')
  .returnVals()

// this returns everything inside, it will call .filter first
const everything = log
  .color('blue.underline')
  .data({canYouHandleIt: true})
  .text('M')
  .return()

🎨 color

chalk

chalks

all chalk colors available with .color

log
.text('\n========================================\n')
.color('bold')
.echo()

shorthands

log
  .bold('same as calling .color(bold).text(all this text)')
  .echo()

xterm

cli-colors

all cli-color are available by calling .xterm

log
  .time(true)
  .xterm(202, 236).text(' orange!!! ')
  .echo()

function

because it's javascript, the log is an object... but it can be called as a function for convenience

log({data: true}, 'text', 'color')

stack

emoji

names using emoji-commits are available with .emoji (currently 🚧 not all have been ported yet)

log
  .emoji('phone')
  .text('et')
  .data('phone home')
  .echo()

☕ filtering

can use comma separated strings, or arrays

filter & tags

log
  .filter('!nope, yes')

log
  .tag('unrelated,nope')
  .cyan('you will never see me :-(')
  .echo()

log
  .tag('yes')
  .underline('yay!')
  .echo()

⏲ quick

quickly log data and exit if you want to stop execution at a certain point for debugging

log.quick({give: 'me'}, 'everything', 'and quit')

// or
log.data({now: 'die'}).exit(1)

⬛ tables

Screenshot extending cli-table2

log
  .table(['header1', 'header2'], ['row1', 'row2'])
  .echo()

log
  .table(['header1', 'header2'])
  .row({'key1': 'val1'})
  .row({'key2': 'val2'})
  .echo()

⚖️ diff

using deep-diff, you can compare before and after data differences as tables. Data will be cloned so it can be mutated and then compared.

const royalty = {
  posh: true,
}
const lowlyPeasant = {
  pauper: true,
}

log.diff(royalty)
const abomination = deepmerge(royalty, lowlyPeasant)
log
  .diff(abomination)
  .doDiff()
  .echo()

🌀 spinner

extends cli-spinner

// instance available on log.Spinner
log.startSpinner('spinner message', {
  // optional spinner args
  onTick: () => {},

  // where to output the logs, default process.stdout
  stream: () => {}

  // default 60
  delay: 80,
})

console.log('log this, then spinner shows up again - it is sticky.')

log.stopSpinner()

🗺 stack traces

⚾ catch errors

will output the stack trace formatted and inspected deeply with the error preset

const ForeverAndEver = new Promise(resolve => Promise.resolve())
  .then(() => Promise.reject('💍'))
  .catch(log.catch)

🔎 find logs

in your entry point, calling log.track() will output the location all of the next logs output from.

log.track()

// later on...

log.bold('I cannot be found... oh wait, I was tracked.').echo()

trace

calling .trace will output a shortened stack trace to the current location.

log.data({bigData: 'oh'}).trace().echo()

✘ clear

this will clear the terminal (at least, move it down so it is clear)

log.clear()

🕳 deep

vs

goal winner
code source tosource
deep inside objects verbose
colors verbose

verbose

using inspector-gadget, objects are inspected and colorized as deep as configured

log
  .bold('verbose:')
  .data({
    numbers: 1000,
    booleans: true,
    functions: () => {},
    strings: 'wacky wavy fun',
  })
  .verbose(/* optional number for how deep to go */)
  .echo()

tosource

see the code source using tosource for nodejs you can look at the source of a variable

log
  .bold('tosource:')
  .data({
    numbers: 1000,
    booleans: true,
    functions: () => {},
    strings: 'wacky wavy fun',
  })
  .tosource()
  .echo()

🍰 presets

add your own

log.addPreset('warning', (chain) => {
  return chain.text('⚠  warning:').color('bgYellow.black').verbose(10)
})

use built-ins

log
  .preset('warning')
  .data('nananenano!')
  .echo()

log
  .preset('error')
  .data(new Error('prettyfull!'))
  .echo()

⌛ timestamps

log
  .time(true)
  .color('cyan')
  .text('🕳  so deep, so colorful, so meta  🎨  ')
  .data(log)
  .verbose()
  .echo()

from

to use logging from a pure js object, .from is available

log.from({
  data: 'data',
  text: 'eh',
  color: 'bold',
  echo: true,
})

^ is the same as

log
  .text('eh')
  .data('data')
  .color('bold')
  .echo()

🚧

  • progress bar,
  • to file,
  • to stream
  • middleware alongside .return