Version: 2.0.0 (latest)

Logging & Debugging

You are reading the documentation for version 2 of FoalTS. Instructions for upgrading to this version are available here. The old documentation can be found here.

HTTP Request Logging#

FoalTS uses morgan to log the HTTP requests. You can specify the output format using the environment variable SETTINGS_LOGGER_FORMAT or the config/default.json file:

loggerFormat: tiny

Disabling HTTP Request Logging#

In some scenarios and environments, you might want to disable http request logging. You can achieve this by setting the loggerFormat configuration option to none.

loggerFormat: none

Disabling Error Logging#

In some scenarios, you might want to disable error logging (error stack traces that are displayed when an error is thrown in a controller or hook). You can achieve this by setting the allErrors configuration option to false.

allErrors: false

Logging Hook#

FoalTS provides a convenient hook for logging debug messages: Log(message: string, options: LogOptions = {}).

interface LogOptions {
body?: boolean;
params?: boolean;
headers?: string[]|boolean;
query?: boolean;


import { Get, HttpResponseOK, Log } from '@foal/core';
@Log('AppController', {
body: true,
headers: [ 'X-CSRF-Token' ],
params: true,
query: true
export class AppController {
index() {
return new HttpResponseOK();

Advanced Logging#

If you need advanced logging, you might be interested in using winston, a popular logger in the Node.js ecosystem.

Here's an example on how to use it with Foal:


import * as winston from 'winston';
export class LoggerService {
private logger: any;
constructor() {
this.logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({
filename: 'logs.txt'
info(msg: string) {;
warn(msg: string) {
error(msg: string) {

LogUserId hook

import { Hook } from '@foal/core';
// LoggerService import.
export function LogUserId() {
return Hook((ctx, services) => {
const logger = services.get(LoggerService);`UserId is: ${}`);


import { Get } from '@foal/core';
// LogUserId import.
export class ProductController {
readProducts() {


import { dependency, Post } from '@foal/core';
// LoggerService import.
export class AuthController {
logger: LoggerService;
signup() {
...'Someone signed up!');