hot-console
v1.0.0
Published
Console logging with colors and more details
Downloads
3
Readme
Hot Console
Hot Console is a console log replacer for node that includes colors and shows more detailed results. Such as data types, string lengths, and displays arrays and objects in a more readable format.
It's fast and very easy to use!
var log = require('hot-console')
log('Hello World!') // Use instead of console.log
log(34, { color: 'red', background: 'black' })
log([1, 2, [[4, 5], 'nr 3']], { color: 'yellow' })
log('The %s is %d\n', 'time', Date.now(), { color: 'green' })
Installation
$ npm install hot-console
Examples
var log = require('hot-console')
log.setColor('yellow')
.setBackground('red')
.setStyle('bold')
log('This text has yellow color, red background and is in bold')
log('This too but has blue backgound', { background: 'blue' })
log('This has changed alot', { color: 'green', background: 'yellow', style: 'italic' })
// Clear all styles
log.clear()
// Quick functions for just red and green text
log.error('Red text')
.success('Green text')
// Different argument examples
var d = new Date()
log('Today is: %d-%d-%d', d.getFullYear(), d.getMonth(), d.getDate())
log('The', 'weekday', 'is', d.getDay(), { color: 'yellow' })
log('The hour is: %d and the minute is:', d.getHours(), d.getMinutes())
Extra! Console loading animation
var timeout = log.startLoading('loading', { color: 'yellow' })
// loading...
setTimeout(function () {
log.clear(timeout)
.success('Finished loading!')
}, 2000)
Functions
Log
log(s, ...arguments, style) // The console log function
s
: The string/object to console log (can be any datatype)....arguments
: When s is a string any amount of arguments can be added in "printf style", or just added to the end (uses util.format).style
: Style object with 3 valid properties (color, background, style) which has to be the last argument (available colors are listed below).
SetColor, setBackground, setStyle and clear
log.setColor(s) // Sets color to use
.setBackground(s) // Sets background color to use
.setStyle(s) // Sets style to use
.clear() // Clears all styles
s
: String of which color to use in the console.- Colors: "red", "black", "green", "yellow", "blue", "magenta", "cyan", "white" or "grey" (grey doesn't work for background color). Null to reset.
- Styles: "italic", "bold", "underline", "reset", "dim", "inverse", "hidden", "strikethrough". Null to reset.
- Colors and styles are based on the Colors package (safe version). So check there for more colors/styles.
Error and success
log.error(s, ...arguments) // Quick way to console log in red color
.success(s, ...arguments) // Quick way to console log in green color
Same arguments as log(), but no style object
StartLoading
var timeout = log.startLoading(s, style) // Starts a console loading animation
log.clear(timeout) // Stops the loading animation
s
: String to use with the loading symbol.timeout
: Can be anything really, if clear is called with an argument it stops an ongoing animation instead of clearing styles.
SetLoader
log.setLoader(symbol) // Changes loading symbol
symbol
: String of which console loading symbol to use ("rotater", "numbers" or "dots").
SetLoopDepth
log.setLoopDepth(depth)
depth
: Number for max recursion level depth to use when looping through objects and arrays. Default is 10.
ShowStringDetails
log.showStringDetails(show)
show
: Boolean to show/hide all strings datatype and length info in console. Is false by default.- String details are always shown inside arrays and in objects though.
Tests
$ npm test
Author
License
Changelog
1.0.0 (Aug 5, 2016)
- Initial public release