Changing logger to loggerService
This commit is contained in:
parent
e7503e3074
commit
d1faef35d2
5 changed files with 13 additions and 21 deletions
|
|
@ -7,11 +7,11 @@ import { LoggerService } from './service'
|
|||
export class LoggerMiddleware implements NestMiddleware {
|
||||
constructor(
|
||||
@Inject(LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
private readonly loggerService: LoggerService,
|
||||
) {}
|
||||
|
||||
use(req: Request, _res: Response, next: NextFunction) {
|
||||
this.logger.log(`${req.method} ${req.originalUrl}`)
|
||||
this.loggerService.log(`${req.method} ${req.originalUrl}`)
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,4 @@
|
|||
import { ConsoleLogger, Injectable } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class LoggerService extends ConsoleLogger {
|
||||
log(message: any, ...optionalParams: any[]) {
|
||||
super.log(message, ...optionalParams)
|
||||
}
|
||||
error(message: any, ...optionalParams: any[]) {
|
||||
super.error(message, ...optionalParams)
|
||||
}
|
||||
warn(message: any, ...optionalParams: any[]) {
|
||||
super.warn(message, ...optionalParams)
|
||||
}
|
||||
}
|
||||
export class LoggerService extends ConsoleLogger {}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export class RecurringReservationsCronService {
|
|||
private readonly recurringReservationsService: RecurringReservationsService,
|
||||
|
||||
@Inject(LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
private readonly loggerService: LoggerService,
|
||||
) {}
|
||||
|
||||
@Cron(CronExpression.EVERY_DAY_AT_4AM, {
|
||||
|
|
@ -23,7 +23,7 @@ export class RecurringReservationsCronService {
|
|||
const dayOfWeek = dayjs().get('day')
|
||||
const recurringReservationsToSchedule =
|
||||
await this.recurringReservationsService.getByDayOfWeek(dayOfWeek)
|
||||
this.logger.log(
|
||||
this.loggerService.log(
|
||||
`Found ${recurringReservationsToSchedule.length} recurring reservations to schedule`,
|
||||
)
|
||||
for (const recurringReservation of recurringReservationsToSchedule) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export class ReservationsCronService {
|
|||
private readonly reservationsQueue: Queue,
|
||||
|
||||
@Inject(LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
private readonly loggerService: LoggerService,
|
||||
) {}
|
||||
|
||||
@Cron(CronExpression.EVERY_DAY_AT_7AM, {
|
||||
|
|
@ -26,7 +26,7 @@ export class ReservationsCronService {
|
|||
})
|
||||
async handleDailyReservations() {
|
||||
const reservationsToPerform = await this.reservationService.getByDate()
|
||||
this.logger.log(
|
||||
this.loggerService.log(
|
||||
`Found ${reservationsToPerform.length} reservations to perform`,
|
||||
)
|
||||
await this.reservationsQueue.addBulk(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export class ReservationsWorker {
|
|||
private readonly brService: BaanReserverenService,
|
||||
|
||||
@Inject(LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
private readonly loggerService: LoggerService,
|
||||
) {}
|
||||
|
||||
@Process()
|
||||
|
|
@ -26,7 +26,7 @@ export class ReservationsWorker {
|
|||
const reservation = plainToInstance(Reservation, job.data, {
|
||||
groups: ['password'],
|
||||
})
|
||||
this.logger.log('Handling reservation', {
|
||||
this.loggerService.log('Handling reservation', {
|
||||
reservation: instanceToPlain(reservation),
|
||||
})
|
||||
await this.performReservation(reservation)
|
||||
|
|
@ -38,12 +38,14 @@ export class ReservationsWorker {
|
|||
) {
|
||||
switch (true) {
|
||||
case error instanceof NoCourtAvailableError: {
|
||||
this.logger.warn('No court available, adding to waiting list')
|
||||
this.loggerService.warn('No court available, adding to waiting list')
|
||||
await this.addReservationToWaitList(reservation)
|
||||
return
|
||||
}
|
||||
default:
|
||||
this.logger.error('Error while performing reservation', { error })
|
||||
this.loggerService.error('Error while performing reservation', {
|
||||
error,
|
||||
})
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue