1 | ;
|
2 |
|
3 | const chalk = require('chalk');
|
4 |
|
5 | let isDebug = false;
|
6 |
|
7 | module.exports = {
|
8 | /**
|
9 | * Set debug mode.
|
10 | *
|
11 | * @param {boolean} val
|
12 | */
|
13 | setDebug(val) {
|
14 | isDebug = val;
|
15 | },
|
16 | /**
|
17 | * Print debug info.
|
18 | *
|
19 | * @param {string|Object} text
|
20 | */
|
21 | print(text) {
|
22 | if (isDebug) {
|
23 | if (typeof text === 'object') {
|
24 | console.log(chalk.cyan('[DEBUG]'));
|
25 | Object.keys(text).forEach(function(key) {
|
26 | console.log(chalk.cyan(' ' + key + ': ') + text[key]);
|
27 | });
|
28 | } else {
|
29 | console.log(chalk.cyan('[DEBUG]') + ' ' + text);
|
30 | }
|
31 | }
|
32 | }
|
33 | };
|