-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
38 lines (32 loc) · 1.04 KB
/
index.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
import 'dotenv/config'
import infoLogger from './src/infoLogger'
import warnLogger from './src/warnLogger';
import errorLogger from './src/errorLogger';
import { ErrorTypes } from './src/types/errorTypes';
import { ContextValue } from './src/types/contextTypes';
import testLogger from './src/testLogger';
const logger = (context: ContextValue, message: string, bypassProd: boolean = false): void => {
const env = process.env.NODE_ENV;
const errorTypes: ErrorTypes = {
info: infoLogger,
warn: warnLogger,
error: errorLogger,
test: testLogger
}
if (env === 'production') {
if (bypassProd) errorTypes[context](message);
if (context !== 'error') return;
errorTypes.error(message);
return;
}
if (
context !== 'info'
&& context !== 'warn'
&& context !== 'error'
&& context !== 'test'
) {
throw new Error('Error context not accepted (valid values: info, warn, error)')
}
errorTypes[context](message);
}
export default logger;