1 | import { logLevels } from '../constants';
|
2 | import {
|
3 | type Logger,
|
4 | type MessageContext,
|
5 | type MessageEventHandler,
|
6 | } from '../types';
|
7 |
|
8 | const createChildLogger = (log: Logger, logLevel: number) => {
|
9 | return (a, b, c, d, e, f, g, h, index, index_) => {
|
10 | log.child({
|
11 | logLevel,
|
12 | })(a, b, c, d, e, f, g, h, index, index_);
|
13 | };
|
14 | };
|
15 |
|
16 | export const createMockLogger = (
|
17 | onMessage: MessageEventHandler,
|
18 | parentContext?: MessageContext,
|
19 | ): Logger => {
|
20 |
|
21 | const log: Logger = () => {
|
22 | return undefined;
|
23 | };
|
24 |
|
25 | log.adopt = async (routine) => {
|
26 | return routine();
|
27 | };
|
28 |
|
29 | log.child = () => {
|
30 | return createMockLogger(onMessage, parentContext);
|
31 | };
|
32 |
|
33 | log.getContext = () => {
|
34 | return {};
|
35 | };
|
36 |
|
37 | log.debug = createChildLogger(log, logLevels.debug);
|
38 | log.debugOnce = createChildLogger(log, logLevels.debug);
|
39 | log.error = createChildLogger(log, logLevels.error);
|
40 | log.errorOnce = createChildLogger(log, logLevels.error);
|
41 | log.fatal = createChildLogger(log, logLevels.fatal);
|
42 | log.fatalOnce = createChildLogger(log, logLevels.fatal);
|
43 | log.info = createChildLogger(log, logLevels.info);
|
44 | log.infoOnce = createChildLogger(log, logLevels.info);
|
45 | log.trace = createChildLogger(log, logLevels.trace);
|
46 | log.traceOnce = createChildLogger(log, logLevels.trace);
|
47 | log.warn = createChildLogger(log, logLevels.warn);
|
48 | log.warnOnce = createChildLogger(log, logLevels.warn);
|
49 |
|
50 | return log;
|
51 | };
|