-
Notifications
You must be signed in to change notification settings - Fork 0
/
chindings.js
43 lines (33 loc) · 1.03 KB
/
chindings.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
const os = require('os');
const { bindings: formatter } = require('./formatters');
const { stringify } = require('./utils');
const { pid } = process
const hostname = os.hostname()
const name = undefined;
const chindings = asChindings({ chindings: '' }, { hostname, pid, name })
module.exports = { asChindings, chindings };
function asChindings(instance, bindings) {
// implementing this can be quite easy.
const stringifiers = {};
const serializers = {}
const invalidKeys = [
'level',
'serializers',
'formatters',
'customLevels'
];
let data = instance.chindings;
let value;
bindings = formatter(bindings);
for (let key in bindings) {
value = bindings[key];
const valid = !invalidKeys.includes(key) && bindings.hasOwnProperty(key) &&value !== undefined
if(valid) {
value = serializers[key] ? serializers[key](value) : value;
value = (stringifiers[key] || stringify)(value)
if (value === undefined) continue
data += ',"' + key + '":' + value
}
}
return data;
}