Skip to content

Commit 772b65a

Browse files
Feat/logger (#5)
add logger package
1 parent 0d564dc commit 772b65a

33 files changed

+1432
-153
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ out/
2727
build
2828
dist
2929

30+
# Log
31+
logs
32+
3033

3134
# Debug
3235
npm-debug.log*
File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Config } from 'jest';
2+
import { createDefaultPreset } from 'ts-jest';
3+
4+
const config: Config = {
5+
...createDefaultPreset(),
6+
testRegex: '.*\\.e2e-spec\\.ts$',
7+
};
8+
9+
export default config;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"deleteOutDir": true
7+
}
8+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "centralized-logger-example",
3+
"version": "0.0.1",
4+
"description": "",
5+
"author": "",
6+
"private": true,
7+
"license": "UNLICENSED",
8+
"scripts": {
9+
"build": "nest build",
10+
"clean": "rimraf dist",
11+
"start": "nest start",
12+
"dev": "nest start --watch",
13+
"test": "jest --config jest.config.ts",
14+
"debug": "nest start --debug --watch"
15+
},
16+
"dependencies": {
17+
"@nestified/centralized-logger": "workspace:*",
18+
"@nestified/correlation-id": "*",
19+
"@nestjs/common": "^11.1.6",
20+
"@nestjs/config": "^4.0.2",
21+
"@nestjs/core": "^11.1.6",
22+
"@nestjs/microservices": "^11.1.6",
23+
"@nestjs/platform-express": "^11.1.6",
24+
"reflect-metadata": "^0.2.2",
25+
"rxjs": "^7.8.2"
26+
},
27+
"devDependencies": {
28+
"@eslint/js": "^9.33.0",
29+
"@nestjs/cli": "^11.0.10",
30+
"@nestjs/schematics": "^11.0.7",
31+
"@nestjs/testing": "^11.1.6",
32+
"@swc/cli": "^0.7.8",
33+
"@swc/core": "^1.13.3",
34+
"@types/express": "^5.0.3",
35+
"@types/jest": "^30.0.0",
36+
"@types/node": "^24.2.1",
37+
"@types/supertest": "^6.0.3",
38+
"globals": "^16.3.0",
39+
"jest": "^30.0.5",
40+
"source-map-support": "^0.5.21",
41+
"supertest": "^7.1.4",
42+
"ts-jest": "^29.4.1",
43+
"ts-loader": "^9.5.2",
44+
"ts-node": "^10.9.2",
45+
"tsconfig-paths": "^4.2.0",
46+
"typescript": "^5.9.2",
47+
"typescript-eslint": "^8.39.1",
48+
"vitest": "^3.2.4"
49+
}
50+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { StructuredLoggerService } from '@nestified/centralized-logger';
2+
import { NestFactory } from '@nestjs/core';
3+
import { TestAppModule } from 'test-app.module';
4+
5+
async function bootstrap() {
6+
const app = await NestFactory.create(TestAppModule, { bufferLogs: true });
7+
8+
app.useLogger(app.get(StructuredLoggerService));
9+
10+
await app.listen(process.env.PORT ?? 8000);
11+
}
12+
13+
bootstrap();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { StructuredLoggerModule } from '@nestified/centralized-logger';
2+
import {
3+
CorrelationIdMiddleware,
4+
CorrelationIdModule,
5+
CorrelationIdService,
6+
} from '@nestified/correlation-id';
7+
import {
8+
Controller,
9+
Get,
10+
MiddlewareConsumer,
11+
Module,
12+
NestModule,
13+
} from '@nestjs/common';
14+
import { MessagePattern } from '@nestjs/microservices';
15+
16+
@Controller()
17+
export class TestController {
18+
constructor(private readonly correlationIdService: CorrelationIdService) {}
19+
20+
@MessagePattern('getId')
21+
@Get()
22+
getId() {
23+
return { correlationId: this.correlationIdService.get() };
24+
}
25+
}
26+
27+
@Module({
28+
imports: [
29+
CorrelationIdModule,
30+
StructuredLoggerModule.register({
31+
serviceName: 'my-service',
32+
injectCorrelationId: true, // install and setup @nestified/correlation-id
33+
environment: 'production',
34+
level: 'info',
35+
redactFields: ['password', 'token'],
36+
logDir: 'logs',
37+
}),
38+
],
39+
controllers: [TestController],
40+
})
41+
export class TestAppModule implements NestModule {
42+
configure(consumer: MiddlewareConsumer) {
43+
consumer.apply(CorrelationIdMiddleware).forRoutes('*');
44+
}
45+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4+
}

examples/centralized-logger-example/tsconfig.build.tsbuildinfo

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist",
5+
"baseUrl": "./src"
6+
}
7+
}

0 commit comments

Comments
 (0)