diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index 63802839..a3dcc2bc 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -4,7 +4,7 @@ import { ThrottlerModule } from '@nestjs/throttler'; import { AuthModule } from './auth/auth.module'; import { AppCacheModule } from './cache/cache.module'; import { AppConfigModule, AppConfigService } from '@reduced.to/config'; -import { AppLoggerModule } from './logger/logger.module'; +import { AppLoggerModule } from '@reduced.to/logger'; import { NovuModule } from './novu/novu.module'; import { PrismaService } from '@reduced.to/prisma'; import { UniqueConstraint } from './shared/decorators/unique/unique.decorator'; diff --git a/apps/backend/src/shortener/shortener.controller.spec.ts b/apps/backend/src/shortener/shortener.controller.spec.ts index c8b35088..c44db0dc 100644 --- a/apps/backend/src/shortener/shortener.controller.spec.ts +++ b/apps/backend/src/shortener/shortener.controller.spec.ts @@ -5,7 +5,7 @@ import { ShortenerController } from './shortener.controller'; import { Test } from '@nestjs/testing'; import { ShortenerDto } from './dto'; import { Request } from 'express'; -import { AppLoggerModule } from '../logger/logger.module'; +import { AppLoggerModule } from '@reduced.to/logger'; describe('ShortenerController', () => { let shortenerController: ShortenerController; diff --git a/apps/backend/src/shortener/shortener.controller.ts b/apps/backend/src/shortener/shortener.controller.ts index 51180aaf..85a06087 100644 --- a/apps/backend/src/shortener/shortener.controller.ts +++ b/apps/backend/src/shortener/shortener.controller.ts @@ -4,7 +4,7 @@ import { ShortenerDto } from './dto'; import { ShortenerService } from './shortener.service'; import { UserContext } from '../auth/interfaces/user-context'; import { OptionalJwtAuthGuard } from '../auth/guards/optional-jwt-auth.guard'; -import { AppLoggerSerivce } from '../logger/logger.service'; +import { AppLoggerSerivce } from '@reduced.to/logger'; @Controller({ path: 'shortener', diff --git a/libs/logger/.eslintrc.json b/libs/logger/.eslintrc.json new file mode 100644 index 00000000..9d9c0db5 --- /dev/null +++ b/libs/logger/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/logger/README.md b/libs/logger/README.md new file mode 100644 index 00000000..116bb4a1 --- /dev/null +++ b/libs/logger/README.md @@ -0,0 +1,7 @@ +# logger + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test logger` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/logger/jest.config.ts b/libs/logger/jest.config.ts new file mode 100644 index 00000000..15a6db0f --- /dev/null +++ b/libs/logger/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: 'logger', + preset: '../../jest.preset.js', + testEnvironment: 'node', + transform: { + '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../coverage/libs/logger', +}; diff --git a/libs/logger/project.json b/libs/logger/project.json new file mode 100644 index 00000000..74ddc27f --- /dev/null +++ b/libs/logger/project.json @@ -0,0 +1,30 @@ +{ + "name": "logger", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/logger/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["libs/logger/**/*.ts"] + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/logger/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + } + }, + "tags": [] +} diff --git a/libs/logger/src/index.ts b/libs/logger/src/index.ts new file mode 100644 index 00000000..99729a77 --- /dev/null +++ b/libs/logger/src/index.ts @@ -0,0 +1,2 @@ +export * from './lib/logger.module'; +export * from './lib/logger.service'; diff --git a/apps/backend/src/logger/logger.module.ts b/libs/logger/src/lib/logger.module.ts similarity index 100% rename from apps/backend/src/logger/logger.module.ts rename to libs/logger/src/lib/logger.module.ts diff --git a/apps/backend/src/logger/logger.service.spec.ts b/libs/logger/src/lib/logger.service.spec.ts similarity index 100% rename from apps/backend/src/logger/logger.service.spec.ts rename to libs/logger/src/lib/logger.service.spec.ts diff --git a/apps/backend/src/logger/logger.service.ts b/libs/logger/src/lib/logger.service.ts similarity index 77% rename from apps/backend/src/logger/logger.service.ts rename to libs/logger/src/lib/logger.service.ts index 8080d577..09e10b71 100644 --- a/apps/backend/src/logger/logger.service.ts +++ b/libs/logger/src/lib/logger.service.ts @@ -4,20 +4,18 @@ import { AppConfigService } from '@reduced.to/config'; @Injectable() export class AppLoggerSerivce implements LoggerService { + private readonly logger: Logger; + constructor(private readonly config: AppConfigService) { - if (!this.logger) { - this.logger = new Logger({ - transports: [ - new ConsoleTransport({ - threshold: this.config.getConfig().logger.console.threshold, - }), - ], - }); - } + this.logger = new Logger({ + transports: [ + new ConsoleTransport({ + threshold: this.config.getConfig().logger.console.threshold, + }), + ], + }); } - private readonly logger: Logger; - log = (message: any, ...optionalParams: any[]) => this.logger.info(message, ...optionalParams); error = (message: any, ...optionalParams: any[]) => this.logger.error(message, ...optionalParams); warn = (message: any, ...optionalParams: any[]) => this.logger.warn(message, ...optionalParams); diff --git a/libs/logger/tsconfig.json b/libs/logger/tsconfig.json new file mode 100644 index 00000000..19b9eece --- /dev/null +++ b/libs/logger/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs" + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/logger/tsconfig.lib.json b/libs/logger/tsconfig.lib.json new file mode 100644 index 00000000..3f06e802 --- /dev/null +++ b/libs/logger/tsconfig.lib.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], + "include": ["src/**/*.ts"] +} diff --git a/libs/logger/tsconfig.spec.json b/libs/logger/tsconfig.spec.json new file mode 100644 index 00000000..f6d8ffcc --- /dev/null +++ b/libs/logger/tsconfig.spec.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] +} diff --git a/package-lock.json b/package-lock.json index b783adca..18170cb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12873,9 +12873,9 @@ "devOptional": true }, "node_modules/graphql": { - "version": "16.8.0", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.0.tgz", - "integrity": "sha512-0oKGaR+y3qcS5mCu1vb7KG+a89vjn06C7Ihq/dDl3jA+A8B3TKomvi3CiEcVLJQGalbu8F52LxkOym7U5sSfbg==", + "version": "16.8.1", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.1.tgz", + "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } diff --git a/tsconfig.base.json b/tsconfig.base.json index e1bf2755..30575df6 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -16,6 +16,7 @@ "baseUrl": ".", "paths": { "@reduced.to/config": ["libs/config/src/index.ts"], + "@reduced.to/logger": ["libs/logger/src/index.ts"], "@reduced.to/prisma": ["libs/prisma/src/index.ts"], "@reduced.to/queue-manager": ["libs/queue-manager/src/index.ts"] }