FabricioG
FabricioG

Reputation: 3320

Why is NestJS logger not logging to terminal window?

Currently I have the following code:

import { Injectable, Logger } from '@nestjs/common';

@Injectable()
export class CategoriesService {
  logger: Logger;

  constructor(@InjectModel(Categories.name) private categoriesModel: Model<CategoriesDocument>) {
    this.logger = new Logger();
  }
...

In a method I then attempt to log:

getCategories({ text, first, page, hasType, parent }: GetCategoriesArgs) {
    this.logger.log('getCategories is triggered');
...

I don't get an error but I don't see the log message in terminal window. Any ideas what I'm missing? Also console.log() also doesn't appear.

Upvotes: 2

Views: 1880

Answers (1)

jboothe
jboothe

Reputation: 1193

I had the same issue - strangely, it appeared to be a cacheing issue. In my case I had to:

  • delete the /dist folder and
  • re-run npm run start:dev

Both console.log(...) and this.logger.log(...) instance I setup began working.

Upvotes: 1

Related Questions