loggingexpress-gateway

In express-gateway i want to log consumerid, I get the example ${req.ip} works fine but how do i reference the eg specific elements like consumerId?


How do I reference consumerId in order to log in express-gateway - are the eg- specific 'elements' documented anywhere?

mytest:
 apiEndpoints:
  - test
 policies:
  - log:
     action:
       message: ${req.consumerId} ${req.ip} ${req.method} ${req.originalUrl}
  - key-auth:
  - proxy:
     action:
      serviceEndpoint: testscore
      changeOrigin: true
      stripPath: true

gets me a Null response


Solution

  • I could get the consumer id using: ${egContext.consumer.id} Note that it is available only after authorization policy like: oauth2