Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node templating engine for colored output to console

How to render colored text to the console produced by a templating engine which supports looping and variable substitution.

I've done some tests with swig, but it simply escapes the \u001b[32m stuff.

Is there something in between sprintf and a real HTML templating engine?

Update:
I've tried swig for a while now and just using console.log would've actually been more maintainable/readable :)

Am I the only one that would find something for outputting text to the console based on a model useful? Or am I approaching this from the wrong angle?

like image 923
Laoujin Avatar asked Apr 30 '15 19:04

Laoujin


1 Answers

Although this doesn't solve the problem of a templating system, it might help you towards what it is you are trying to achieve. There are two different modules that I would suggest you have a look at:

chalk - "Terminal string styling done right. Much color."

There is a node module called chalk that allows you to define colors/styles though a very simple api.

It is compatible with sprintf substitution and can be combined with console.log to log pretty colored formatted output.

bunyan - "a JSON logging library for node.js services"

If however you are wanting to use it for logs, I'd suggest having a look at bunyan. It allows you to basically send anything to your logs formatted as JSON. It adds extra data like timestamps and error levels, so you don't have to. The output is just JSON, so it can easily be consumed programatically.

By piping the std.out into bunyan, it will colorise and format the output, making it easier to inspect.

like image 58
mrkiffie Avatar answered Nov 04 '22 01:11

mrkiffie