UNPKG

973 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.KafkaLogger = void 0;
4const kafka_interface_1 = require("../external/kafka.interface");
5const KafkaLogger = (logger) => ({ namespace, level, label, log }) => {
6 let loggerMethod;
7 switch (level) {
8 case kafka_interface_1.logLevel.ERROR:
9 case kafka_interface_1.logLevel.NOTHING:
10 loggerMethod = 'error';
11 break;
12 case kafka_interface_1.logLevel.WARN:
13 loggerMethod = 'warn';
14 break;
15 case kafka_interface_1.logLevel.INFO:
16 loggerMethod = 'log';
17 break;
18 case kafka_interface_1.logLevel.DEBUG:
19 default:
20 loggerMethod = 'debug';
21 break;
22 }
23 const { message, ...others } = log;
24 if (logger[loggerMethod]) {
25 logger[loggerMethod](`${label} [${namespace}] ${message} ${JSON.stringify(others)}`);
26 }
27};
28exports.KafkaLogger = KafkaLogger;