-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlogHelper.js
75 lines (64 loc) · 1.68 KB
/
logHelper.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
const os = require('os');
const packageFile = require('../package.json');
const getPluginVersion = () => packageFile.version;
const getSystemInfo = appVersion => {
return (
'' +
`Date: ${new Date()}` +
'\n' +
`Application version: ${appVersion}` +
'\n' +
`Plugin version: ${getPluginVersion()}` +
'\n\n' +
`System information:` +
'\n' +
` Hostname: ${os.hostname()}` +
'\n' +
` Platform: ${os.platform()} ${os.arch()}` +
'\n' +
` Release: ${os.release()}` +
'\n' +
` Uptime: ${toTime(os.uptime())}` +
'\n' +
` Total RAM: ${(os.totalmem() / 1073741824).toFixed(2)} GB` +
'\n' +
` CPU Model: ${os.cpus()[0].model}` +
'\n' +
` CPU Clock: ${maxClock(os.cpus())} MHZ` +
'\n' +
` CPU Cores: ${os.cpus().length} cores` +
'\n\n'
);
};
const maxClock = cpus => {
return cpus.reduce((highestClock, cpu) => Math.max(highestClock, cpu.speed), 0);
};
const prefixZero = number => (number < 10 ? '0' + number : number);
const toTime = number => {
return Math.floor(number / 3600) + ':' + prefixZero(parseInt((number / 3600 - Math.floor(number / 3600)) * 60));
};
const createLogger = ({ title, logger, hiddenKeys }) => {
return {
info(message, infoTitle) {
logger.log('info', message, infoTitle || title, hiddenKeys);
},
progress(message, dbName = '', tableName = '') {
logger.progress({ message, containerName: dbName, entityName: tableName });
},
error(error) {
logger.log('error', createError(error), title);
},
};
};
const createError = error => {
const message = error.message || error.msg || error.errmsg;
return {
message,
code: error.code,
stack: error.stack,
};
};
module.exports = {
createLogger,
getSystemInfo,
};