UNPKG

1.13 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const lodash = require("lodash");
4const common_1 = require("@nestjs/common");
5const logger_provider_1 = require("./logger.provider");
6const decoratedTokenPrefix = 'Logger:';
7const decoratedLoggers = new Set();
8function InjectLogger(context) {
9 const isString = (value) => lodash.isString(value);
10 if (!isString(context)) {
11 context = context.name || '';
12 }
13 decoratedLoggers.add(context);
14 return common_1.Inject(`${decoratedTokenPrefix}${context}`);
15}
16exports.InjectLogger = InjectLogger;
17function createDecoratedLoggerProvider(context) {
18 return {
19 provide: `${decoratedTokenPrefix}${context}`,
20 useFactory: (logger) => {
21 logger.setContext(context);
22 return logger;
23 },
24 inject: [logger_provider_1.LoggerProvider],
25 };
26}
27function createProvidersForDecorated() {
28 return [...decoratedLoggers.values()].map(context => createDecoratedLoggerProvider(context));
29}
30exports.createProvidersForDecorated = createProvidersForDecorated;
31//# sourceMappingURL=logger.decorator.js.map
\No newline at end of file