UNPKG

1.63 kBJavaScriptView Raw
1const chalk = require('chalk');
2const { format } = require('util');
3
4/**
5 * Prefix.
6 */
7const prefix = '[ice-devtools]';
8
9/**
10 * Log a `message` to the console.
11 *
12 * @param {String} message
13 */
14exports.log = function (...args) {
15 const msg = format.apply(format, args);
16 console.log(chalk.white(prefix), msg);
17};
18
19/**
20 * info log
21 *
22 * @param {String} message
23 */
24exports.info = function (...args) {
25 const msg = format.apply(format, args);
26 console.log(chalk.green(prefix), msg);
27};
28
29/**
30 * debug log
31 */
32exports.verbose = function (...args) {
33 if (process.env.LOG_LEVEL !== 'verbose') {
34 return;
35 }
36
37 const msg = format.apply(format, args);
38 console.log(chalk.white(prefix), msg);
39};
40
41/**
42 * Log an error `message` to the console and exit.
43 *
44 * @param {String} message
45 */
46exports.fatal = function (...args) {
47 console.log();
48 if (args[0] instanceof Error) {
49 const errorName = args[0].name ? ` ${args[0].name}:` : '';
50 console.error(chalk.red(prefix + errorName + args[0].message.trim()));
51 console.error(args[0]);
52 } else {
53 console.error(chalk.red(prefix), ...args);
54 }
55 console.log();
56 process.exit(1);
57};
58
59/**
60 * Log a success `message` to the console and exit.
61 *
62 * @param {String} message
63 */
64exports.success = function (...args) {
65 const msg = format.apply(format, args);
66 console.log();
67 console.log(chalk.white(prefix), msg);
68 console.log();
69};
70
71
72/**
73 * Log a warn `message` to the console.
74 *
75 * @param {String} message
76 */
77exports.warn = function (...args) {
78 const msg = format.apply(format, args);
79 console.log();
80 console.log(chalk.yellow(prefix), msg);
81 console.log();
82};