Reputation: 179
I did an error filter for my Nest application that outputs my error object with logger.error(). The issue is that logger.error() is not working. I tried to call Logger from multiple locations, nothing worked. The strange part is that other options like verbose and warn work just fine.
Take this code for example:
import { Logger } from '@nestjs/common'
export class InstiController{
constructor(private instiService: InstiService) {}
private logger = new Logger('InstiController')
@Get()
foo(@GetLoggedUser() user: Usuarios) {
this.logger.error('This is an error')
this.logger.warn('This is a warning')
this.logger.verbose('This is a verbose')
return this.instiService.listUserInsti(user)
}
}
Output:
UPDATE: When I start Nest directly (outside a Docker container) error outputs correctly:
Upvotes: 1
Views: 4073
Reputation: 179
@Mic Fung solutions should work in theory however it still didn't work for me. I noticed my other computer (using Docker Desktop 3.3.2 and docker engine 20.10.5 was displaying error logs just fine).
So, I assumed the issue was specific to 3.3.3 and updated Docker Desktop to 3.4.0. Now my issue is fixed. Error messages display again and it didn't require any new configuration
Upvotes: 0
Reputation: 5692
The default docker GUI logging level is info so the error log is not showing.
To override the logging level, go to
"logging": "fatal"
The error log should be able to show.
P.S. The logging level in docker GUI is ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
Image from Docker GUI after setting logging level: https://i.sstatic.net/v64OS.png
Way 02:
add log level setting though command
in docker-compose.yml
.
Then, remove the container and rebuild it with docker-compose up -d
...
services:
xxx:
build:
context: .
target: development
dockerfile: ./Dockerfile
command:
- "--log.level=FATAL"
....
Upvotes: 2
Reputation:
You can try setting it manually while bootstrapping.
const app = await NestFactory.create(AppModule, {
logger: ['error', 'warn'],
});
Values in the array can be any combination of 'log', 'error', 'warn', 'debug', and 'verbose'.
Upvotes: 0