4IT580: Docs
4IT580 WebGitLab

7. Backend Logging

Using NestJS Built-in Logger

NestJS provides a built-in Logger class that you can import and use in any service or controller. By default, logs are written to the console output (stdout/stderr).

Importing and Using the Logger

Where to Find the Log Output

Logs are displayed in your terminal console where you run the application:

OR, in case of using the school server, in file in the backend directory. This is a limitation of the school server. Use this command to see the logs in real-time:

The logs include:

Log Levels

The application is configured with specific log levels in :

Available log levels:

Using Different Log Levels

Best Practices for Logging

  1. Log important actions:
  1. Log errors with stack traces:
  1. Use appropriate log levels:
  1. Include context in logs:

Fixing the logger for bootup

You might want to try rewriting the current Quacker setup for logging in to this:

Otherwise the logging might not output some boot errors (e.g. missing module imports). You can try that by using in a module which doesn't import (should output error properly).