Skip to content
Paul Freeman edited this page Aug 20, 2013 · 4 revisions

formatter

borrowed to https://github.com/mikeal/logref/blob/master/main.js#L6-15

log

this.log is a logref compatible logger, with a bit of enhanced API.

It also have EventEmitter like ability, so you can call on / emit on it, namely used to increase or decrease the padding.

All logs are done against STDERR, letting you stdout for meaningfull value and redirection, should you need to generate output this way.

Log functions take two arguments, a message and a context. For any other kind of paramters, console.error is used, so all of the console format string goodies you're used to work fine.

  • msg - The message to show up
  • context - The optional context to escape the message against

Retunrns the logger

log#write

A simple write method, with formatted message. If msg is ommitted, then a single \n is written.

Returns the logger

log#writeln

Same as log.write() but automatically appends a \n at the end of the message.

log#ok

Convenience helper to write sucess status, this simply prepends the message with a gren .

log#status

Each predefined status has its logging method utility, handling status color and padding before the usual .write()

Example

this.log
  .write()
  .info('Doing something')
  .force('Forcing filepath %s', 'some path')
  .conflict('on %s', 'model.js')
  .write()
  .ok('This is ok');

The list of status and mapping colors

skip       yellow
force      yellow
create     green
invoke     bold
conflict   red
identical  cyan
info       grey

Returns the logger

log#table

A basic wrapper around cli-table package, resetting any single char to empty strings, this is used for aligning options and arguments without too much Math on our side.

  • opts - A list of rows or an Hash of options to pass through cli table.

Returns the table reprensetation

Clone this wiki locally