1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var LoggerModule_1;
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const winston_1 = require("winston");
|
11 | const common_1 = require("@nestjs/common");
|
12 | const nest_config_1 = require("@jiaxinjiang/nest-config");
|
13 | const logger_provider_1 = require("./logger.provider");
|
14 | const logger_constants_1 = require("./logger.constants");
|
15 | const logger_decorator_1 = require("./logger.decorator");
|
16 | const logger_middleware_1 = require("./logger.middleware");
|
17 | let LoggerModule = LoggerModule_1 = class LoggerModule {
|
18 | static forRoot() {
|
19 | const decorated = logger_decorator_1.createProvidersForDecorated();
|
20 | return {
|
21 | imports: [nest_config_1.ConfigModule],
|
22 | module: LoggerModule_1,
|
23 | providers: [
|
24 | {
|
25 | provide: logger_constants_1.WINSTON_LOGGER,
|
26 | useFactory: (configService) => {
|
27 | const winstonConfig = configService.get('logger');
|
28 | return winston_1.createLogger(winstonConfig);
|
29 | },
|
30 | inject: [nest_config_1.ConfigService],
|
31 | },
|
32 | logger_provider_1.LoggerProvider,
|
33 | ...decorated,
|
34 | ],
|
35 | exports: [logger_constants_1.WINSTON_LOGGER, logger_provider_1.LoggerProvider, ...decorated],
|
36 | };
|
37 | }
|
38 | configure(consumer) {
|
39 | const httpAdapter = consumer.httpAdapter;
|
40 | if (!httpAdapter.constructor || httpAdapter.constructor.name !== 'FastifyAdapter') {
|
41 | return;
|
42 | }
|
43 | httpAdapter.register(logger_middleware_1.requestContextPlugin);
|
44 | }
|
45 | };
|
46 | LoggerModule = LoggerModule_1 = __decorate([
|
47 | common_1.Global(),
|
48 | common_1.Module({})
|
49 | ], LoggerModule);
|
50 | exports.LoggerModule = LoggerModule;
|
51 |
|
\ | No newline at end of file |