diff --git a/apps/anvil/package.json b/apps/anvil/package.json index 0b36341..9ada8de 100644 --- a/apps/anvil/package.json +++ b/apps/anvil/package.json @@ -71,6 +71,8 @@ "tailwindcss": "^3.4.3", "tough-cookie": "^4.1.3", "typescript-memoize": "^1.1.1", + "winston": "^3.13.0", + "winston-daily-rotate-file": "^5.0.0", "zod": "^3.22.4" }, "devDependencies": { diff --git a/apps/anvil/src/app.module.ts b/apps/anvil/src/app.module.ts index 1f5dc1d..3a39f06 100644 --- a/apps/anvil/src/app.module.ts +++ b/apps/anvil/src/app.module.ts @@ -1,7 +1,7 @@ import { EdgeDBModule } from "@/edgedb/edgedb.module"; import { TrainingService } from "@/training/training.service"; import { BullModule } from "@nestjs/bull"; -import { Module } from "@nestjs/common"; +import { Logger, Module } from "@nestjs/common"; import { ConfigModule } from "@nestjs/config"; import { APP_PIPE } from "@nestjs/core"; import { ScheduleModule } from "@nestjs/schedule"; @@ -59,6 +59,7 @@ import { UsersModule } from "./users/users.module"; EmailService, RootService, GoogleService, + Logger, ], controllers: [SignInController, RootController, TrainingController], }) diff --git a/apps/anvil/src/main.ts b/apps/anvil/src/main.ts index f908b47..49cfcc1 100644 --- a/apps/anvil/src/main.ts +++ b/apps/anvil/src/main.ts @@ -1,12 +1,16 @@ import { ValidationPipe, VersioningType } from "@nestjs/common"; import { NestFactory } from "@nestjs/core"; import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; +import { WINSTON_MODULE_NEST_PROVIDER, WinstonModule } from "nest-winston"; import * as cookieParser from "cookie-parser"; import helmet from "helmet"; import { AppModule } from "./app.module"; import type { users } from "@ignis/types"; import * as Express from "express"; +import * as winston from "winston"; +import "winston-daily-rotate-file"; +import { utilities as nestWinstonModuleUtilities } from "nest-winston/dist/winston.utilities"; declare global { // biome-ignore lint/suspicious/noRedeclare: @@ -16,7 +20,27 @@ declare global { } async function bootstrap() { - const app = await NestFactory.create(AppModule); + // Setup Logger + const instance = winston.createLogger({ + transports: [ + new winston.transports.Console({ + format: winston.format.combine(winston.format.timestamp(), nestWinstonModuleUtilities.format.nestLike()), + }), + new winston.transports.DailyRotateFile({ + filename: "logs/anvil-%DATE%.log", + datePattern: "YYYY-MM-DD", + zippedArchive: true, + maxSize: "20m", + maxFiles: "14d", + format: winston.format.combine(winston.format.timestamp(), winston.format.json()), + }), + ], + }); + const app = await NestFactory.create(AppModule, { + logger: WinstonModule.createLogger({ + instance, + }), + }); app.enableShutdownHooks(); app.enableCors({ origin: process.env.FRONT_END_URL as string, @@ -41,7 +65,6 @@ async function bootstrap() { const document = SwaggerModule.createDocument(app, options); SwaggerModule.setup("api", app, document); - await app.listen(process.env.ANVIL_PORT || 3000); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ce26851..58e2d78 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -164,6 +164,12 @@ importers: typescript-memoize: specifier: ^1.1.1 version: 1.1.1 + winston: + specifier: ^3.13.0 + version: 3.13.0 + winston-daily-rotate-file: + specifier: ^5.0.0 + version: 5.0.0(winston@3.13.0) zod: specifier: ^3.22.4 version: 3.22.4 @@ -4902,6 +4908,9 @@ packages: resolution: {integrity: sha512-ej8ksPF4x6e5wvK9yevct0UCXh8TTFlWGVLlgjZuoBH1HwjIfKE/IdL5mq89sFA7zELi1VhKpmtDnrs7zWyeyg==} engines: {node: '>=14'} + file-stream-rotator@0.6.1: + resolution: {integrity: sha512-u+dBid4PvZw17PmDeRcNOtCP9CCK/9lRN2w+r1xIS7yOL9JFrIBKTvrYsxT4P0pGtThYTn++QS5ChHaUov3+zQ==} + fill-range@7.0.1: resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} engines: {node: '>=8'} @@ -6473,6 +6482,9 @@ packages: resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==} hasBin: true + moment@2.30.1: + resolution: {integrity: sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==} + ms@2.0.0: resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} @@ -8526,6 +8538,12 @@ packages: resolution: {integrity: sha512-o0cyEG0e8GPzT4iGHphIOh0cJOV8fivsXxddQasHPHfoZf1ZexrfeA21w2NaEN1RHE+fXlfISmOE8R9N3u3Qig==} engines: {node: '>=12'} + winston-daily-rotate-file@5.0.0: + resolution: {integrity: sha512-JDjiXXkM5qvwY06733vf09I2wnMXpZEhxEVOSPenZMii+g7pcDcTBt2MRugnoi8BwVSuCT2jfRXBUy+n1Zz/Yw==} + engines: {node: '>=8'} + peerDependencies: + winston: ^3 + winston-transport@4.7.0: resolution: {integrity: sha512-ajBj65K5I7denzer2IYW6+2bNIVqLGDHqDw3Ow8Ohh+vdW+rv4MZ6eiDvHoKhfJFZ2auyN8byXieDDJ96ViONg==} engines: {node: '>= 12.0.0'} @@ -13809,6 +13827,10 @@ snapshots: escape-string-regexp: 5.0.0 is-unicode-supported: 1.3.0 + file-stream-rotator@0.6.1: + dependencies: + moment: 2.30.1 + fill-range@7.0.1: dependencies: to-regex-range: 5.0.1 @@ -16052,6 +16074,8 @@ snapshots: dependencies: minimist: 1.2.8 + moment@2.30.1: {} + ms@2.0.0: {} ms@2.1.2: {} @@ -18368,6 +18392,14 @@ snapshots: dependencies: string-width: 5.1.2 + winston-daily-rotate-file@5.0.0(winston@3.13.0): + dependencies: + file-stream-rotator: 0.6.1 + object-hash: 3.0.0 + triple-beam: 1.4.1 + winston: 3.13.0 + winston-transport: 4.7.0 + winston-transport@4.7.0: dependencies: logform: 2.6.0