1 | 'use strict'
|
2 |
|
3 | var chalk = require('chalk')
|
4 | var util = require('util')
|
5 | var map = require('../lib/common/array/map')
|
6 |
|
7 | var newLine = '\n'
|
8 |
|
9 | exports.warn = function (x, y, z) { return helper('yellow', x, y, z) }
|
10 | exports.log = function (x, y, z) { return helper('green', x, y, z) }
|
11 | exports.info = function (x, y, z) { return helper('blue', x, y, z) }
|
12 | exports.debug = function (x, y, z) { return helper('cyan', x, y, z) }
|
13 |
|
14 | exports.error = function () {
|
15 | var i, j, argument, output, lines, error, trace
|
16 | for (i = 0, j = arguments.length; i < j; i++) {
|
17 | argument = arguments[i]
|
18 | if (argument instanceof Error) {
|
19 | output = argument.stack || argument.name
|
20 | lines = output.split(newLine)
|
21 | error = lines[0]
|
22 | trace = map(lines.slice(1), formatLine).join(newLine)
|
23 |
|
24 | helper('red', error)
|
25 | if (trace.length) helper('gray', trace)
|
26 |
|
27 | continue
|
28 | }
|
29 | helper('red', argument)
|
30 | }
|
31 | }
|
32 |
|
33 | function formatLine (line) {
|
34 | return ' ' + line.trim()
|
35 | }
|
36 |
|
37 | function helper (color, x, y, z) {
|
38 | var output = map([x, y, z], function (argument) {
|
39 | return typeof argument === 'object' ?
|
40 | util.inspect(argument, { depth: null }) :
|
41 | argument
|
42 | }).join(' ')
|
43 |
|
44 | map(output.split(newLine), function (line) {
|
45 | if (line.trim())
|
46 | console.log('# ' + chalk[color](line))
|
47 | })
|
48 | }
|