Skip to content

Commit 8c70075

Browse files
committed
feat: setup nestjs logger for nest module
1 parent ac941e1 commit 8c70075

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Logger as NativeNestLogger } from '@nestjs/common';
2+
import { Logger } from '@optask/tasker';
3+
4+
/**
5+
* Simple wrapper around the nestjs default logger, implementing the logger interface
6+
*/
7+
export class NestLogger extends NativeNestLogger implements Logger {
8+
info(...args: any[]) {
9+
// Just map calls to info -> log
10+
this.log(args);
11+
}
12+
13+
trace(...args: any[]) {
14+
// Just map calls to trace -> verbose
15+
this.verbose(args);
16+
}
17+
18+
// Construct new logger with a different name
19+
child(name?: string) {
20+
return new NestLogger(name);
21+
}
22+
}

packages/nestjs/src/task-scheduler.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { DiscoveryService } from '@golevelup/nestjs-discovery';
2-
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
2+
import { Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common';
33
import { Store, TaskScheduler } from '@optask/tasker';
44
import { TaskMetaKey } from './constants';
55
import { BaseTask, TaskMetadata } from './task.interface';
66
import { Store as StoreToken } from './store.provider';
77
import { Conditions, ProvidedConditions } from './conditions.provider';
8+
import { NestLogger } from './nestjs.logger';
89

910
@Injectable()
1011
export class TaskSchedulerService
@@ -17,6 +18,8 @@ export class TaskSchedulerService
1718
private readonly discoveryService: DiscoveryService,
1819
) {
1920
super();
21+
22+
this.setLogger(new NestLogger(TaskScheduler.name));
2023
this.registerStore(store);
2124
for (const condition of conditions.keys()) {
2225
this.addCondition(condition, conditions.get(condition));

0 commit comments

Comments
 (0)