Skip to content

quiteReslogger does not appear to work #352

@paustint

Description

@paustint

When I have quiteReslogger, the entire response object is still logged out.

My use-case is that I need certain logging properties from the request/response to be in the root of the log so that they can be consistent with other non-node services.

I would expect that quiteReslogger would limit what is logged about the response, but it seems that it does not do anything - unless I am misunderstanding how the feature is supposed to work.

export const httpLogger = pinoHttp<express.Request, express.Response>({
  logger,
  autoLogging: {
    ignore: (req) => IGNORE_LOG_PATHS.has(req.path),
  },
  customSuccessMessage: function (req, res) {
    if (res.statusCode === 404) {
      return `[404] [${req.method}] ${req.url}`;
    }
    return `${req.method} ${req.url}`;
  },
  quietReqLogger: true,
  quietResLogger: true,
  customProps: function (req, res) {
    return {
      id: req.id,
      method: req.method,
      url: req.url,
      hostname: req.headers.host,
      userAgent: req.headers['user-agent'],
      statusCode: res.statusCode,
      tenantId: req.headers['x-tenant-id'],
      userId: req.headers['x-user-id'],
      traceId: req.headers['x-b3-traceid'],
      spanId: req.headers['x-b3-spanid'],
    };
  },
});

produces this (using pretty logging locally)

[20:20:03.633] INFO (52057):
    reqId: 1
    id: 1
    method: "GET"
    url: "/foo"
    userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
    statusCode: 200
    tenantId: "foo"
    userId: "foo"
    res: {
      "statusCode": 200,
      "headers": {
        "x-powered-by": "Express",
        "access-control-allow-origin": "*",
        "content-type": "application/json; charset=utf-8",
        "content-length": "6516",
        "etag": "W/\"1974-3h2XR95mb88G95O2Ua94T2liCwc\""
      }
    }
    responseTime: 85
    message: "GET /foo"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions