Skip to content

Commit 6703cf8

Browse files
authored
Merge pull request #93 from monstar-lab-oss/sivan/logger-service-final
feat: logger service funtions
2 parents 5f6de23 + 7b8f88b commit 6703cf8

18 files changed

+74
-89
lines changed

src/app.controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { RequestContext } from './shared/request-context/request-context.dto';
66

77
describe('AppController', () => {
88
let moduleRef: TestingModule;
9-
const mockedLogger = { setContext: jest.fn(), logWithContext: jest.fn() };
9+
const mockedLogger = { setContext: jest.fn(), log: jest.fn() };
1010

1111
beforeEach(async () => {
1212
moduleRef = await Test.createTestingModule({

src/app.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class AppController {
1515

1616
@Get()
1717
getHello(@ReqContext() ctx: RequestContext): string {
18-
this.logger.logWithContext(ctx, 'Hello world from App controller');
18+
this.logger.log(ctx, 'Hello world from App controller');
1919

2020
return this.appService.getHello(ctx);
2121
}

src/app.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class AppService {
99
}
1010

1111
getHello(ctx: RequestContext): string {
12-
this.logger.logWithContext(ctx, 'Hello world from App service');
12+
this.logger.log(ctx, 'Hello world from App service');
1313

1414
return 'Hello World!';
1515
}

src/auth/controllers/auth.controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('AuthController', () => {
1919
refreshToken: jest.fn(),
2020
};
2121

22-
const mockedLogger = { setContext: jest.fn(), logWithContext: jest.fn() };
22+
const mockedLogger = { setContext: jest.fn(), log: jest.fn() };
2323

2424
beforeEach(async () => {
2525
moduleRef = await Test.createTestingModule({

src/auth/controllers/auth.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class AuthController {
5656
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5757
@Body() credential: LoginInput,
5858
): BaseApiResponse<AuthTokenOutput> {
59-
this.logger.logWithContext(ctx, `${this.login.name} was called`);
59+
this.logger.log(ctx, `${this.login.name} was called`);
6060

6161
const authToken = this.authService.login(ctx);
6262
return { data: authToken, meta: {} };
@@ -98,7 +98,7 @@ export class AuthController {
9898
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9999
@Body() credential: RefreshTokenInput,
100100
): Promise<BaseApiResponse<AuthTokenOutput>> {
101-
this.logger.logWithContext(ctx, `${this.refreshToken.name} was called`);
101+
this.logger.log(ctx, `${this.refreshToken.name} was called`);
102102

103103
const authToken = await this.authService.refreshToken(ctx);
104104
return { data: authToken, meta: {} };

src/auth/services/auth.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('AuthService', () => {
6363

6464
const mockedConfigService = { get: jest.fn() };
6565

66-
const mockedLogger = { setContext: jest.fn(), logWithContext: jest.fn() };
66+
const mockedLogger = { setContext: jest.fn(), log: jest.fn() };
6767

6868
beforeEach(async () => {
6969
const moduleRef: TestingModule = await Test.createTestingModule({

src/auth/services/auth.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class AuthService {
3131
username: string,
3232
pass: string,
3333
): Promise<UserAccessTokenClaims> {
34-
this.logger.logWithContext(ctx, `${this.validateUser.name} was called`);
34+
this.logger.log(ctx, `${this.validateUser.name} was called`);
3535

3636
// The userService will throw Unauthorized in case of invalid username/password.
3737
const user = await this.userService.validateUsernamePassword(
@@ -49,7 +49,7 @@ export class AuthService {
4949
}
5050

5151
login(ctx: RequestContext): AuthTokenOutput {
52-
this.logger.logWithContext(ctx, `${this.login.name} was called`);
52+
this.logger.log(ctx, `${this.login.name} was called`);
5353

5454
return this.getAuthToken(ctx, ctx.user);
5555
}
@@ -58,7 +58,7 @@ export class AuthService {
5858
ctx: RequestContext,
5959
input: RegisterInput,
6060
): Promise<RegisterOutput> {
61-
this.logger.logWithContext(ctx, `${this.register.name} was called`);
61+
this.logger.log(ctx, `${this.register.name} was called`);
6262

6363
// TODO : Setting default role as USER here. Will add option to change this later via ADMIN users.
6464
input.roles = [ROLE.USER];
@@ -71,7 +71,7 @@ export class AuthService {
7171
}
7272

7373
async refreshToken(ctx: RequestContext): Promise<AuthTokenOutput> {
74-
this.logger.logWithContext(ctx, `${this.refreshToken.name} was called`);
74+
this.logger.log(ctx, `${this.refreshToken.name} was called`);
7575

7676
const user = await this.userService.findById(ctx, ctx.user.id);
7777
if (!user) {
@@ -85,7 +85,7 @@ export class AuthService {
8585
ctx: RequestContext,
8686
user: UserAccessTokenClaims | UserOutput,
8787
): AuthTokenOutput {
88-
this.logger.logWithContext(ctx, `${this.getAuthToken.name} was called`);
88+
this.logger.log(ctx, `${this.getAuthToken.name} was called`);
8989

9090
const subject = { sub: user.id };
9191
const payload = {

src/auth/strategies/local.strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class LocalStrategy extends PassportStrategy(Strategy, STRATEGY_LOCAL) {
3131
): Promise<UserAccessTokenClaims> {
3232
const ctx = createRequestContext(request);
3333

34-
this.logger.logWithContext(ctx, `${this.validate.name} was called`);
34+
this.logger.log(ctx, `${this.validate.name} was called`);
3535

3636
const user = await this.authService.validateUser(ctx, username, password);
3737
// Passport automatically creates a user object, based on the value we return from the validate() method,

src/cli.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ConfigService } from '@nestjs/config';
33

44
import { AppModule } from './app.module';
55

6-
import { AppLogger } from './shared/logger/logger.service';
76
import { UserService } from './user/services/user.service';
87
import { ROLE } from './auth/constants/role.constant';
98
import { CreateUserInput } from './user/dtos/user-create-input.dto';
@@ -12,8 +11,6 @@ import { RequestContext } from './shared/request-context/request-context.dto';
1211
async function bootstrap() {
1312
const app = await NestFactory.createApplicationContext(AppModule);
1413

15-
app.useLogger(new AppLogger());
16-
1714
const configService = app.get(ConfigService);
1815
const defaultAdminUserPassword = configService.get<string>(
1916
'defaultAdminUserPassword',

src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import { ValidationPipe } from '@nestjs/common';
44
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
55

66
import { AppModule } from './app.module';
7-
import { AppLogger } from './shared/logger/logger.service';
87
import { RequestIdMiddleware } from './shared/middlewares/request-id/request-id.middleware';
98

109
async function bootstrap() {
1110
const app = await NestFactory.create(AppModule);
1211
app.setGlobalPrefix('api/v1');
1312

14-
app.useLogger(new AppLogger());
1513
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
1614
app.use(RequestIdMiddleware);
1715
app.enableCors();

0 commit comments

Comments
 (0)