1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const lodash = require("lodash");
|
4 | const common_1 = require("@nestjs/common");
|
5 | const logger_provider_1 = require("./logger.provider");
|
6 | const decoratedTokenPrefix = 'Logger:';
|
7 | const decoratedLoggers = new Set();
|
8 | function 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 | }
|
16 | exports.InjectLogger = InjectLogger;
|
17 | function 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 | }
|
27 | function createProvidersForDecorated() {
|
28 | return [...decoratedLoggers.values()].map(context => createDecoratedLoggerProvider(context));
|
29 | }
|
30 | exports.createProvidersForDecorated = createProvidersForDecorated;
|
31 |
|
\ | No newline at end of file |