-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslog.ts
32 lines (24 loc) · 933 Bytes
/
slog.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
import { config } from '../../../packages/config/index.js';
import { logToELK } from './services/elk.js';
import { AppLogComponent, LogObject } from './types.js';
const { isProd, isTests, isDebug } = config.env;
type LogFn = (component: AppLogComponent, message: string, data?: LogObject) => void;
const elklog = (component: AppLogComponent, message: string, data?: LogObject) =>
logToELK({ component, message, ...data });
const consolelog = (component: AppLogComponent, message: string, data?: LogObject) =>
console.log(component, message, data || '');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const nulllog = (component: AppLogComponent, message: string, data?: LogObject) => {};
let log: LogFn;
if (isProd) {
log = elklog;
} else if ((isTests && isDebug) || (!isTests && !isProd)) {
log = consolelog;
} else {
log = nulllog;
}
export const slog: {
log: LogFn;
} = {
log
};