Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger has been moved and implemented as an internal lib #449

Merged
merged 8 commits into from
Sep 22, 2023
Merged
2 changes: 1 addition & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/shortener/shortener.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/shortener/shortener.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 18 additions & 0 deletions libs/logger/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/logger/README.md
Original file line number Diff line number Diff line change
@@ -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).
11 changes: 11 additions & 0 deletions libs/logger/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'logger',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/logger',
};
30 changes: 30 additions & 0 deletions libs/logger/project.json
Original file line number Diff line number Diff line change
@@ -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": []
}
2 changes: 2 additions & 0 deletions libs/logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lib/logger.module';
export * from './lib/logger.service';
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions libs/logger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
11 changes: 11 additions & 0 deletions libs/logger/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -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"]
}
9 changes: 9 additions & 0 deletions libs/logger/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -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"]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
Expand Down