-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
91 lines (74 loc) · 2.73 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
const colors = require('colors');
//Error Log
const autoLogE = (message, vars) => {
// If the process is running in 'production', stop logging.
if (process.env.NODE_ENV === "production") return;
//Creating Error to get name of function
let stack = new Error().stack
let caller = stack.split('\n')[2].trim();
caller = caller.slice(3, caller.length)
let arr = caller.split(" ");
const nameOfFunction = arr[0];
if (message !== (undefined || '')) {
console.log(`${nameOfFunction}`.cyan + ` |`.green + ` Error: ${message}`.red.bold);
} else {
console.log(`${nameOfFunction} Called`.cyan);
}
//Printing varibales
if (vars !== undefined) {
console.log("Variables Used : ".green.bold);
for (let varname in vars) {
console.log(varname.yellow.bold + ": " + JSON.stringify(vars[varname]).green);
}
}
}
//Info Log
const autoLogI = (message, vars) => {
// If the process is running in 'production', stop logging.
if (process.env.NODE_ENV === "production") return;
//Creating Error to get name of function
let stack = new Error().stack
let caller = stack.split('\n')[2].trim();
caller = caller.slice(3, caller.length)
let arr = caller.split(" ");
const nameOfFunction = arr[0];
if (message !== (undefined || '')) {
console.log(`${nameOfFunction}`.cyan + ` |`.green + ` Info: ${message}`.blue.bold);
} else {
console.log(`${nameOfFunction} Called`.cyan);
}
//Printing varibales
if (vars !== undefined) {
console.log("Variables Used : ".green.bold);
for (let varname in vars) {
console.log(varname.yellow.bold + ": " + JSON.stringify(vars[varname]).green);
}
}
}
//Warning Log
const autoLogW = (message, vars) => {
// If the process is running in 'production', stop logging.
if (process.env.NODE_ENV === "production") return;
//Creating Error to get name of function
let stack = new Error().stack
let caller = stack.split('\n')[2].trim();
caller = caller.slice(3, caller.length)
let arr = caller.split(" ");
const nameOfFunction = arr[0];
if (message !== (undefined || '')) {
console.log(`${nameOfFunction}`.cyan + ` |`.green + ` Warning: ${message}`.yellow.bold);
} else {
console.log(`${nameOfFunction} Called`.cyan);
}
//Printing varibales
if (vars !== undefined) {
console.log("Variables Used : ".green.bold);
for (let varname in vars) {
console.log(varname.yellow.bold + ": " + JSON.stringify(vars[varname]).green);
}
}
}
module.exports.autoLog = autoLogE;
module.exports.autoLogE = autoLogE;
module.exports.autoLogI = autoLogI;
module.exports.autoLogW = autoLogW;