UNPKG

2.39 kBJavaScriptView Raw
1"use strict";
2var __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};
8var LoggerModule_1;
9Object.defineProperty(exports, "__esModule", { value: true });
10const winston_1 = require("winston");
11const common_1 = require("@nestjs/common");
12const nest_config_1 = require("@jiaxinjiang/nest-config");
13const logger_provider_1 = require("./logger.provider");
14const logger_constants_1 = require("./logger.constants");
15const logger_decorator_1 = require("./logger.decorator");
16const logger_middleware_1 = require("./logger.middleware");
17let 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};
46LoggerModule = LoggerModule_1 = __decorate([
47 common_1.Global(),
48 common_1.Module({})
49], LoggerModule);
50exports.LoggerModule = LoggerModule;
51//# sourceMappingURL=logger.module.js.map
\No newline at end of file