⛓🔈 fliplog
all-in-one logging tool
usage
yarn add fliplognpm i fliplog --save
const log =
🔠 description
fluent logging with verbose insight, colors, tables, emoji, deep cleaning, filtering, spinners, progress bars, timestamps, capturing, stack traces, clearing, boxen, stringifying, code highlighting, notifications, beeping, sparkles, slow-mode, formatting, bar charts, & presets
🗝️ legend:
- 👋 basics
- 🎀 stringifying
- 🙊 silencing
- 🎨 color
- function
- 😊 emoji
- ☕ filtering
- 🛑 quick
- ⬛ table
- 🛁 cleaner
- ⚖️ diff
- 🌀 spinner
- 📈 progress
- 🛎 notify
- 🗺 stack traces
- 🔎 finding logs
- ⚾ catch errors
- ®️ .register
- trace
- 🆑 clear
- 🕳 deep
- 💈 highlight
- 🍰 presets
- ⌛ timestamps
- from
- 🎢 fun
- 🌲 tree
- 📊 bar chart
- 📦 box
- 📯 beep
- 🎇 sparkly
- 🔣 formatting
- 🐌 slow
- ⏲ timer
- ⚡ performance (lightweight configurable dependencies)
- resources
👋 basics
log dataanyKindOfData: true // .json, .stringify, .tosource, .verbose text'text to use, this is what gets colored' color'bold' // any cli-color, chalk, available as shorthands // outputs the log, .return to return the formatted values
🆕 NEW!
📝📚 all of these new ones need more docs
📖 read the wip docs for new stuff on the wiki
+
== .echo
log+ // ^ same as `log.italic('so short!').echo()`
🎀 stringifying
json
// optional second arg for options passed into pretty jsonlog
stringify
// args are the same as javascript-stringifylog
🙊 silencing
- to disable outputting a log,
.silence()
(optionaltrue
/false
arg) - to disable all logs,
.shush()
- to enable all logs,
.unshush()
capture all
capture output of all console logs everywhere
log consolelog // captured data is available hereconst saved = logsavedLog
return
return only echos from fliplogs, useful for getting formatted data.
// formatted dataconst text data = log datacatchMeIfYouCan: true text'gingerbread man' // this returns everything inside, it will call .filter firstconst everything = log color'blue.underline' datacanYouHandleIt: true text'M'
🎨 color
chalk
all chalk colors available with .color
logtext'\n========================================\n'color'bold'
shorthands
log
xterm
all cli-color are available by calling .xterm
log text' orange!!! '
function
because it's javascript, the log is an object... but it can be called as a function for convenience
stack
😊 emoji
names using emoji-commits are available with .emoji
(currently 🚧 not all have been ported yet)
log text'et' data'phone home'
☕ filtering
comma separated strings, or arrays
a function can also be passed in, the argument will be an object containing the entries see flipchain/ChainedMap.entries
🔢 level
filter by log level as a number with simple comparison operators
logloglog
🎯 matcher
filter using an Array
made up of Function
s, String
s, and RegExp
s!
loglog
more advanced
loglogloglog
❗ important to note, if only a function is passed in, it will have the entire log instance passed to the argument, rather than the array of tags (for compatibility & simplicity.)
filter & tags
verbose
enables everythingsilent
silences everything!
means disabled
log log log
🚩 flags
this can also be done using cli flags compat with debug flags
yourprogram --DEBUG="!nope,yes"yourprogram --DEBUG=verbose
🛑 quick
quickly log data and exit if you want to stop execution at a certain point for debugging
log // orlogdatanow: 'die'
⬛ tables
extending cli-table2
log log
⚖️ diff
(uses a fork of ava-format which is a fork of jest-diff which is a fork of google's diff-match-patch)
Compare two pieces of data. Data will be cloned so it can be mutated if needed, and then compared.
let oneOneTwoTwo = 'one-one was a race horse 🐎 'logloglog
(previously deep-diff & cli-table was used.)
const royalty = posh: trueconst lowlyPeasant = pauper: truelogconst abomination = Objectloglog
🛁 cleaner
extremely powerful tool built with chain-able using a fork of js-traverse
can take next-to-unusable output such as this
and clean it usable
...or you could clean out certain phrases from every log
var obj = property: {}objcircularReference = objobjSymbol'foo' = 'foo'objmap = objmapobjarray = 1 NaN Infinity log const cleaner = log dataobj
🌀 spinner
- extends cli-spinner
- uses cli-spinners
.Spinner
is available on fliplog as the instantiated spinner
easy
// easy to color spinnerslog
advanced
// instance available on log.Spinnerlog console log
🌀🌀 multiple
- uses node-multispinner
// instance available on log.spinnerslog // arg is optionally a string for frames // or an object for multi-spinner options // string arg removes by name // empty args removes all
ora
.ora
is available as a method with the same options- adds
.fliplog
to theora
instance to allow chaining back to fliplog - returns
ora
instance
// call .oralogstart // orlog
📈 progress
default
log
interval callback
total, cb(bar, interval), interval time
log
advanced
let contentLength = 128 * 1024const bar = logprogressBar { if !contentLength return bar if !barcomplete }
🛎 notify
- allows passing in the same options from node-notifier
string title and [description]
or a string
for title
log
shorthand (echo immediate)
log
🗺 stack traces
⚾ catch errors
will output the stack trace formatted and inspected deeply with the error preset
const ForeverAndEver = Promise
🔎 find logs
in your entry point, calling log.track()
will output the location all of the next logs output from.
log // later on... log
you can also track every console.log anywhere
log // becomes `eh 'at your-file#the-line-number'`console
trace
calling .trace
will output a shortened stack trace to the current location.
logdatabigData: 'oh'
®️ register
registerConsole
defines properties on the console
global and automatically calls echo
where applicable, for easier access:
log consoleconsoleconsoleconsoleconsole // also available// verbose, info, error, track, trace, note, warning, spinner, time, timeEnd, timeLap timeLapEcho, box, beep, timer, table, diff, diffs, stringify, stack, json, filter, tags, quick, exit, reset, sleep, slow, red, yellow, cyan, underline, magenta, bold
registerCatch
catches uncaught promises and errors, displays them verbosely.
log throw 'eh'Promise
🆑 clear
this will clear the terminal (at least, move it down so it is clear)
logclear
🕳 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 data numbers: 1000 booleans: true {} strings: 'wacky wavy fun'
tosource
see the code source using tosource for nodejs you can look at the source of a variable
log data numbers: 1000 booleans: true {} strings: 'wacky wavy fun'
💈 highlight
- cli-highlight (but will not output wrapping html tags around the code, other options are disabled, default themes are used)
{ return 'notice me' }log datahighlitedWithColors
🍰 presets
add your own
log
use built-ins
log data'nananenano!' log data'prettyfull!'
⌛ timestamps
log color'cyan' text'🕳 so deep, so colorful, so meta 🎨 ' datalog
from
to use logging from a pure js object, .from
is available
log
^ is the same as
log text'eh' data'data' color'bold'
🎢 fun
these will all be silent by default, so you can easily disable them by filtering your logs or setting silent output which can be exceedingly helpful.
🌲 tree
log color'green' text'🌲 treeify'
🎇 sparkly
- options from sparkly can be passed in
- will output a random sparkle if it is not set
log
📊 bar
- will output a random bar chart if not set
- options from babar can be passed in
random
log
bar
const points = for var i = 0; i < MathPI * 2; i += MathPI / 1000 points;log
styles and bar
log
📯 beep
all options from beeper
log
📦 box
- all boxen options
colors
// with bold colorslog // echos right awaylog // use boxen box styleslog
🔣 formatting
logdata{} // returns the currently formatted text and dataconst text data = log // returns every single setting as an object, resetsconst everything = log
🛰 space
will output number
of spaces after your log
logtext'followed by 2 empty lines'
🐌 slow
slow mode allows debugging each log step-by-step, and will force a sleep
usable across all environments using sleepfor
loglogconst start = Datelogconst end = Date - start
⏲ timer
start, stop, lap, and timer instance using fliptime
log
or for more customized usage
log log const fliptime = log
💱 formatter
allows final formatting of the data before echoing
✍ interesting to note, this is how most plugins do their formatting
{ if !data || typeof data !== 'object' return data Object return data} const fixture = str: 'I have too many spaces' arr: name: 'eh' noname: 'just undefined' logdatafixture
⚡ performance
⚙ config
to keep the module lightweight, almost all functionality is added through plugins.
requiring
all non-core dependencies are required when functions are called & the filtering passes. this way, only the used-functionality is loaded.
additionally, almost all of the functions are not formatted until .echo()
, so they will not have dependencies loaded when echoing is false which means code does not have to be changed for production.
if echo(false)
or filtering disables the output, they are never called.
🔗 resources
- for more on the library used for fluent apis, see ⛓ flipchain
📝 TODO
- to file 📒
- to stream
- middleware alongside .return
- configure which keys are persistent across instances