-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (74 loc) · 2.16 KB
/
Copy pathindex.js
File metadata and controls
80 lines (74 loc) · 2.16 KB
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
let Logger = require('./Logger');
let _config = null;
function _mergeDeep(...objects) {
const isObject = obj => obj && typeof obj === 'object';
return objects.reduce((prev, obj) => {
Object.keys(obj).forEach(key => {
const pVal = prev[key];
const oVal = obj[key];
if (Array.isArray(pVal) && Array.isArray(oVal)) {
prev[key] = pVal.concat(...oVal);
}
else if (isObject(pVal) && isObject(oVal)) {
prev[key] = _mergeDeep(pVal, oVal);
}
else {
prev[key] = oVal;
}
});
return prev;
}, {});
}
module.exports = {
fastify: (config = {}) => {
_config = (!_config) ? config : _mergeDeep(_config, config);
let l = Logger(_config);
let instance = {};
Object.getOwnPropertyNames(_config.meth_dict)
.map((item) => {
instance[item] = (message) => {
l.log(_config.meth_dict[item], {"Title": item, "Message": message});
}
});
return instance;
},
pastash: (config = {}) => {
_config = (!_config) ? config : _mergeDeep(_config, config);
let l = Logger(_config);
let instance = {};
Object.getOwnPropertyNames(_config.meth_dict)
.map((item) => {
instance[item] = (message) => {
let _m = {"Title": item, "LogLevel": item}
if (typeof message === "object") {
if (message.hasOwnProperty('Message')) {
_m = Object.assign(message, _m);
} else {
_m.Message = JSON.stringify(message);
}
} else {
_m.Message = message;
}
l.log(_config.meth_dict[item], _m);
}
});
return instance;
},
winstonTransport: () => {
const Transport = require('winston-transport');
class AmqpPoolTransport extends Transport {
constructor(opts) {
super(opts.winstonConfig);
console.log(opts)
_config = (!_config) ? opts.amqp : _mergeDeep(_config, opts.amqp);
this.l = Logger(_config);
}
log(info, callback) {
// do whatever you want with log data
this.l.log(info.level, info.message);
callback();
}
}
return AmqpPoolTransport;
}
};