Skip to content

Commit d7f54e1

Browse files
committed
removes integrated setup in favor of more modular independent blocks
1 parent 5d18cbf commit d7f54e1

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export * from './logger/anonymizer';
2+
export * from './logger/http-inspector-inbound.middleware';
3+
export * from './logger/http-inspector-outbound.interceptor';
4+
export * from './logger/log-exception.filter';
25
export * from './logger/logger.config';
36

47
export * from './utils/compression.config';

src/logger/http-inspector-inbound.middleware.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Logger,
55
NestMiddleware,
66
} from '@nestjs/common';
7+
import { ConfigService } from '@nestjs/config';
78
import { NextFunction, Request, Response } from 'express';
89

910
@Injectable()
@@ -68,9 +69,16 @@ class HttpInspectorInboundMiddleware implements NestMiddleware {
6869
}
6970
}
7071

71-
export const configureHttpInspectorInbound = (app: INestApplication) => {
72+
export const configureHttpInspectorInbound = () => (app: INestApplication) => {
73+
const configService = app.get(ConfigService);
74+
const httpInspection = configService.get('INSPECT_HTTP_TRAFFIC', 'all');
75+
if (!['all', 'inbound'].includes(httpInspection)) {
76+
return;
77+
}
78+
7279
const inspector = new HttpInspectorInboundMiddleware();
7380
const middleware = inspector.use.bind(inspector);
81+
7482
Object.defineProperty(middleware, 'name', {
7583
value: HttpInspectorInboundMiddleware.name,
7684
});

src/logger/http-inspector-outbound.interceptor.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { INestApplication, Logger } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
23
import * as http from 'http';
34
import * as https from 'https';
45
import { logRequestError, logResponse } from './http-inspector.utils';
@@ -72,7 +73,13 @@ function mountInterceptor(logger: Logger, module: typeof http | typeof https) {
7273
}
7374
}
7475

75-
export const configureHttpInspectorOutbound = (app: INestApplication) => {
76+
export const configureHttpInspectorOutbound = () => (app: INestApplication) => {
77+
const configService = app.get(ConfigService);
78+
const httpInspection = configService.get('INSPECT_HTTP_TRAFFIC', 'all');
79+
if (!['all', 'outbound'].includes(httpInspection)) {
80+
return;
81+
}
82+
7683
const logger = new Logger('OutboundHTTPInspection');
7784
for (const module of [http, https]) {
7885
mountInterceptor(logger, module);

src/logger/log-exception.filter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ class LogExceptionFilter
5252
}
5353
}
5454

55-
export const configureExceptionLogger = (app: INestApplication) => {
55+
export const configureExceptionLogger = () => (app: INestApplication) => {
5656
const httpAdapter = app.get(HttpAdapterHost);
5757
app.useGlobalFilters(new LogExceptionFilter(httpAdapter));
58+
Logger.log('Log exceptions handler initialized', '@gedai/common/config');
5859
return app;
5960
};

src/logger/logger.config.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import {
88
} from 'nest-winston';
99
import { config, format, transports } from 'winston';
1010
import { Anonymizer, RegExpAnonymizer } from './anonymizer';
11-
import { configureHttpInspectorInbound } from './http-inspector-inbound.middleware';
12-
import { configureHttpInspectorOutbound } from './http-inspector-outbound.interceptor';
13-
import { configureExceptionLogger } from './log-exception.filter';
1411

1512
let contextService: ContextService;
1613
let anonymizer: Anonymizer;
@@ -118,7 +115,6 @@ export const configureLogger =
118115
const _env = configService.get('NODE_ENV', 'production');
119116
const appName = configService.get('SERVICE_NAME', 'nest-app');
120117
const logLevel = configService.get('LOG_LEVEL', 'info');
121-
const httpInspection = configService.get('INSPECT_HTTP_TRAFFIC', 'all');
122118
const logFormat = configService.get('LOG_FORMAT', 'json');
123119
const usePrettyFormat = logFormat === 'pretty';
124120

@@ -133,13 +129,6 @@ export const configureLogger =
133129
};
134130
const logger = WinstonModule.createLogger(loggerConfig);
135131
app.useLogger(logger);
136-
configureExceptionLogger(app);
137-
if (['all', 'inbound'].includes(httpInspection)) {
138-
configureHttpInspectorInbound(app);
139-
}
140-
if (['all', 'outbound'].includes(httpInspection)) {
141-
configureHttpInspectorOutbound(app);
142-
}
143-
Logger.log('Logger initialized', '@gedai/common');
132+
Logger.log('Logger initialized', '@gedai/common/config');
144133
return app;
145134
};

0 commit comments

Comments
 (0)