-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
99 lines (83 loc) · 2.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const events = require('events');
const mixin = require('mixin');
const util = require('util');
require('console-stamp')(console, 'HH:MM:ss.l');
function inhertits(target, source) {
for (var k in source.prototype) {
target.prototype[k] = source.prototype[k];
}
}
function messaging() {
}
messaging.prototype = {
_logger: function(title, message) {
if(!title.match(/console\..*/g)) {
if(message) {
console.log(util.format('event:%s, data:%s', title, util.inspect(message, {showHidden: false, depth: null})));
}
else {
console.log(util.format('event:%s', title));
}
}
else {
if(title == "console.log") {
console.log(message);
}
else if(title == "console.info") {
console.info(message);
}
else if(title == "console.warn") {
console.warn(message);
}
else if(title == "console.error") {
console.error(message);
}
else if(title == "console.assert") {
console.assert(0, message);
}
return;
}
},
_post: function() {
var args = arguments;
args[0] = "xsj." + args[0];
setImmediate(()=> {
if(this.preProcessor) {
this.preProcessor(args);
}
this._logger(args[0], args[1]);
this.emit.apply(this, args);
if(this.postProcessor) {
this.postProcessor(args);
}
});
},
_send:function() {
var args = arguments;
args[0] = "xsj." + args[0];
if(this.preProcessor) {
this.preProcessor(args);
}
this._logger(args[0], args[1]);
this.emit.apply(this, args);
if(this.postProcessor) {
this.postProcessor(args);
}
}
}
function load (module) {
var addon = require(module);
for(var ix in addon) {
var a = addon[ix];
if(typeof(a) != 'function')
continue;
//a = mixin(a, messaging);
//a = mixin(a, events);
inhertits(a, messaging);
inhertits(a, events);
exports[a.name] = a;
}
return addon;
}
load('./xsj-trans.js');
//console.log('exports', exports.XfsMgr.prototype);