Implement basic logging
This commit is contained in:
parent
5ca0a076e2
commit
cd7bcf77e4
7 changed files with 16 additions and 19 deletions
|
@ -1,5 +1,4 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm'; // DEBUG: Is this necessary? Docs unclear.
|
||||
import { DevtoolsModule } from '@nestjs/devtools-integration';
|
||||
import { AppController } from './app.controller';
|
||||
|
@ -7,8 +6,6 @@ import { AppService } from './app.service';
|
|||
import { Cat } from './cats/cats.entity';
|
||||
import { CatsModule } from './cats/cats.module';
|
||||
|
||||
console.debug(`[AppModule] Starting...`)
|
||||
|
||||
let dbConfig: TypeOrmModuleOptions;
|
||||
|
||||
if ( process.env.NODE_ENV === 'production' ) {
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
private readonly logger = new Logger(AppService.name);
|
||||
|
||||
getHello(): string {
|
||||
this.logger.log("[getHello] Starting...");
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,10 @@ import { Cat } from "./cats.entity";
|
|||
|
||||
@Controller('cats')
|
||||
export class CatsController {
|
||||
constructor(private catsService: CatsService) {
|
||||
console.debug("[cats controller] Starting...");
|
||||
}
|
||||
constructor(private catsService: CatsService) {}
|
||||
|
||||
@Get()
|
||||
findAll(): Promise<Cat[]> {
|
||||
console.debug("[ctrl findAll] Starting...");
|
||||
return this.catsService.findAll();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
console.debug('[cats entity] Starting...')
|
||||
|
||||
@Entity()
|
||||
export class Cat {
|
||||
@PrimaryGeneratedColumn()
|
||||
|
|
|
@ -4,8 +4,6 @@ import { CatsController } from "./cats.controller";
|
|||
import { CatsService } from "./cats.service";
|
||||
import { Cat } from "./cats.entity";
|
||||
|
||||
console.debug("[cats module] Starting...");
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Cat])],
|
||||
providers: [CatsService],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { Cat } from "./cats.entity";
|
||||
|
@ -8,20 +8,22 @@ export class CatsService {
|
|||
constructor(
|
||||
@InjectRepository(Cat)
|
||||
private catsRepository: Repository<Cat>,
|
||||
) {
|
||||
console.debug("[cats service] Starting...");
|
||||
}
|
||||
) {}
|
||||
|
||||
private readonly logger = new Logger(CatsService.name);
|
||||
|
||||
findAll(): Promise<Cat[]> {
|
||||
console.log("[svc findAll] Starting...")
|
||||
this.logger.log("[findAll] Starting...");
|
||||
return this.catsRepository.find();
|
||||
}
|
||||
|
||||
findOne(id: number): Promise<Cat | null> {
|
||||
this.logger.log("[findOne] Starting...");
|
||||
return this.catsRepository.findOneBy({ id });
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
this.logger.log("[remove] Starting...");
|
||||
await this.catsRepository.delete(id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,10 @@ import { NestFactory } from '@nestjs/core';
|
|||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
console.debug("[bootstrap] Starting...")
|
||||
const app = await NestFactory.create(AppModule, { snapshot: true });
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
snapshot: true,
|
||||
logger: ['verbose']
|
||||
});
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
|
Loading…
Reference in a new issue