This repository was archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrace.js
More file actions
56 lines (48 loc) · 1.38 KB
/
Copy pathtrace.js
File metadata and controls
56 lines (48 loc) · 1.38 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
//#region libs
/*Environnment variables*/
require('dotenv').config();
const config = require('./config.json');
const env = config.env;
/*Winston*/
const winston = require('winston');
/*Trace File reset*/
const fs = require('fs');
if (fs.existsSync('./logfile.log')) {
try {
fs.unlinkSync('./logfile.log');
} catch(err) {
console.error(err);
}
}
//#endregion
//#region trace module
/*Trace init*/
const logFormat = winston.format.printf(log => {
return `${log.timestamp} : [${log.level}] - ${log.message}`;
});
const traceConfig = {
level: 'debug',
/*[ 0:error | 1:warn | 2:info | 3:http | 4:verbose | 5:debug | 6:silly ]*/
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'logfile.log'}),
],
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
logFormat,
),
exitOnError: false,
};
/*env = [dev | prod]*/
if (env === 'prod') {
traceConfig.level= 'error';
}
const trace = winston.createLogger(traceConfig);
/*Trace shorts*/
module.exports.err = function(m) { return trace.error(m);};
module.exports.wrn = function(m) {return trace.warn(m);};
module.exports.inf = function(m) {return trace.info(m);};
module.exports.not = function(m) {return trace.verbose(m);};
module.exports.dbg = function(m) {return trace.debug(m);};
//#endregion