1

I would like to log every single request that express gateway receives, but it seems I can't decide what to log .

I tried to integrate morgan('immediate') From https://github.com/expressjs/morgan

 /* Create a sub app */
  const subApp = express();
  subApp.use(registration({ container }));
  subApp.use(guestRequest({ container }));
  subApp.use(statistics({ container }));
  subApp.use(deleteUser({ container }));
  subApp.use(relationRequest({ container }));

  subApp.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
  subApp.use(morgan('immediate'))
  subApp.use(cors({ origin: true, credentials: true }));
  subApp.set('view engine', 'ejs');
  subApp.set('views', viewsPath);

but it looks like its not being used.

Anyone successfully integrated advanced logging in express gateway ?

I also tried Longjohn and same issue.

Dany Y
  • 6,833
  • 6
  • 46
  • 83

1 Answers1

2

You can do this using Express Gateway out-of-the box.

First, define an apiEndpoint for all requests:

    apiEndpoints:
      all:
        host: "*"
        paths: "*"

Then, set up a pipeline which logs all requests hitting this apiEndpoint:

    policies:
      log

    pipelines:
      logRequest:
        apiEndpoints:
        - all
        policies:
        - log
          - action:
              message: "{req.method} {req.originalUrl} ${JSON.stringify(req.headers)}"

If you need to log more, consider enabling Express Gateway and/or Express diagnostic logging using the environment variables:

  • LOG_LEVEL=debug (for Express Gateway)
  • DEBUG=express:* (for Express.js)
James McLeod
  • 2,381
  • 1
  • 17
  • 19
  • Thank you, I already added this but its not enough i want more logs, and I'm getting the error `[EG:policy] socket hang up` that i want to debug, so i need more flexibility to get everything i want – Dany Y Apr 14 '21 at 04:45
  • Actually Thank you, your answer was really helpful, I wasn't doing it on "all" endpoint, and now I'm getting somewhere, but is this all the flexibility I can get? if I want to go deeper into node is it possible ? – Dany Y Apr 14 '21 at 06:58
  • @DanyY, can you update your question to include what you have tried and what you need? – James McLeod Apr 14 '21 at 11:06
  • @DanyY, I have added a section on enabling debug logging which might help. – James McLeod Apr 14 '21 at 11:15
  • Sorry for the late reply, I actually used this thank you. – Dany Y Apr 25 '21 at 10:44