Extended default NestJS logger with Winston transporter for Google Cloud Logging.
// main.ts
import {WinstonLoggerServiceApp} from 'nestjs-cloud-logging';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useLogger(app.get(WinstonLoggerServiceApp));
await app.listen(3000);
}
bootstrap();
// app.module.ts
import {WinstonLoggerModule} from 'nestjs-cloud-logging';
@Module({
imports: [
WinstonLoggerModule.forRoot({
isGlobal: true,
projectId: "google-cloud-project-id",
keyFilename: "path-to-key-filename",
}),
],
controllers: [],
providers: [],
})
export class AppModule {
}
import {Logger, LoggerService} from 'nestjs-cloud-logging';
@Injectable()
export class UserService {
constructor(@Logger() private readonly logger: LoggerService) {
}
getUser(id: number): Promise<User> {
this.logger.log('Your logger message');
return this.userRepository.getUser(id);
}
}