UNPKG

1.15 kBJavaScriptView Raw
1'use strict';
2
3var Debug = require('debug');
4var toArray = require('./helper/toArray');
5
6/**
7 *
8 * @class Log
9 *
10 * @param {*} args
11 * @returns {Log}
12 * @constructor
13 */
14function Log(args) {
15 var callee = Log;
16
17 callee.log.apply(callee, ['common'].concat(toArray(arguments)));
18}
19
20Log.DEBUG_KEY = 'ifnode:';
21Log.TEMPLATE = '[ifnode] [$name] $text';
22
23/**
24 *
25 * @param {string} key
26 * @param {*} args
27 */
28Log.log = function(key, args) {
29 var debug = Debug(this.DEBUG_KEY + key);
30
31 debug.apply(debug, toArray(arguments, 1));
32};
33
34/**
35 *
36 * @param {string} name
37 * @param {Error|string} warning
38 */
39Log.warning = function(name, warning) {
40 this.log(
41 'warning',
42 this.TEMPLATE
43 .replace('$name', name)
44 .replace('$text', warning)
45 );
46};
47
48/**
49 *
50 * @param {string} name
51 * @param {Error|string} error
52 */
53Log.error = function(name, error) {
54 if(!(error instanceof Error)) {
55 error = new Error(
56 this.TEMPLATE
57 .replace('$name', name)
58 .replace('$text', error)
59 );
60 }
61
62 throw error;
63};
64
65module.exports = Log;