1 | 'use strict';
|
2 |
|
3 | var Debug = require('debug');
|
4 | var toArray = require('./helper/toArray');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function Log(args) {
|
15 | var callee = Log;
|
16 |
|
17 | callee.log.apply(callee, ['common'].concat(toArray(arguments)));
|
18 | }
|
19 |
|
20 | Log.DEBUG_KEY = 'ifnode:';
|
21 | Log.TEMPLATE = '[ifnode] [$name] $text';
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | Log.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 |
|
37 |
|
38 |
|
39 | Log.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 |
|
51 |
|
52 |
|
53 | Log.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 |
|
65 | module.exports = Log;
|