-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.ts
59 lines (52 loc) · 1.96 KB
/
logger.ts
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
let environment: string = 'development';
let config: any;
try {
// Attempt to dynamically import the logger.config file
// @ts-ignore
config = require('../../logger.config')?.default;
} catch (error) {
console.warn(
'No environment config found, defaulting to "development".\n ' +
'If using React Native, create a file "logger.config.js" in the root directory'
);
}
// Checking if the global environment variable is set
if (globalThis.__APP_ENV__) {
environment = globalThis.__APP_ENV__ as string; // Type assertion
} else if (config?.ENV) {
environment = config.ENV;
}
console.log('Project Environment set to:', environment);
const isDev: boolean = (environment.toLowerCase() === "development");
interface Logger {
info: (taq: string, indicator: string, message?: string) => void;
debug: (taq: string, indicator: string, message?: string) => void;
dLog: (taq: string, indicator: string, data?: any) => void;
warn: (taq: string, indicator: string, message?: string) => void;
error: (taq: string, indicator: string, message?: string) => void;
}
const Logger: Logger = {
info: (taq: string, indicator: string, message: string = "UNIVERSAL") => {
console.log(`[INFO][${taq}][${indicator}]`, message);
},
debug: (taq: string, indicator: string, message: string = "UNIVERSAL") => {
if (isDev) {
console.log(`[DEV][${taq}][${indicator}]`, message);
}
},
dLog: (taq: string, indicator: string, data: any = " ") => {
if (isDev) {
console.log('---------------------------------\n');
console.log(`[DEV][${taq}]`, indicator);
console.log(data);
console.log('---------------------------------\n');
}
},
warn: (taq: string, indicator: string, message: string = "UNIVERSAL") => {
console.warn(`[WARN][${taq}][${indicator}]`, message);
},
error: (taq: string, indicator: string, message: string = "UNIVERSAL") => {
console.error(`[ERROR][${taq}][${indicator}]`, message);
}
};
export default Logger;