-
-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathlogger.ts
35 lines (29 loc) · 879 Bytes
/
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
import { createLogger } from '@module-federation/sdk';
const LOG_CATEGORY = '[ Federation Runtime ]';
// FIXME: pre-bundle ?
const logger = createLogger(LOG_CATEGORY);
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function assert(condition: any, msg: string): asserts condition {
if (!condition) {
error(msg);
}
}
export function error(msg: string | Error | unknown): never {
if (msg instanceof Error) {
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
throw msg;
}
throw new Error(`${LOG_CATEGORY}: ${msg}`);
}
export function warn(msg: Parameters<typeof console.warn>[0]): void {
if (msg instanceof Error) {
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
logger.warn(msg);
} else {
logger.warn(msg);
}
}
export function log(...args: unknown[]) {
logger.log(...args);
}
export { logger };