Log All the Things
Mostly (but not only!) a simple wrapper for the ubiquitous Chalk package that allows you to log color to your terminal with a single function call.
Chalk Wrapper Functionality
Basic Usage
const log = // console.log('hello')log // console.log(chalk.green('hello'))log`{green hello}` // console.log(chalk`{green hello}`)
Chalk Tagged Template Literal Syntax
Also supports Chalk's tagged template literal syntax:
const var1 = "hello"const var2 = "hello" log`{green }{rgb(255,131,0) }`
Additional Functionality
Call-Chaining
All calls to log()
return the log
function itself, so you can issue multiple log calls on a single line:
'baz' // RESULT:// foo -> white// bar -> green// baz -> white
A common use-case for this is to simply add an extra line break in your terminal output:
// RESULT:// hello//// world
Plugins
Add additional methods to the log
object via the extend
method:
const log = const asTable = loglog // RESULT:// col1 col2// ----------// foo bar
extend
takes three arguments:
functionName: string
: The name of the method onlog
you will call.function: (...args: any[]) => unknown
: The function that will be called. Its return value will be automatically logged to the console unless theautoLog
argument isfalse
.autoLog?: boolean
: Optional third parameter. Passfalse
to prevent the return value of thefunction
argument from automatically being logged to the console. Useful if the function you're providing will handle logging itself.