winstonjs / winston

A logger for just about everything.
http://github.com/winstonjs/winston
MIT License
22.89k stars 1.81k forks source link

log all calls to external APIS in express nodejs app using morgan and winston #1696

Open bitquality opened 5 years ago

bitquality commented 5 years ago

I am Not able to find a place to log all calls to external APIS in express nodejs app using morgan and winston. I am not sure if this feature is available or not.

I have tried the code from the link below to successfully intercept requests and responses coming to expressjs server from ui. I was also able to import the logger and use it wherever i want to log the messages in my axios api calls.

https://stackoverflow.com/questions/27906551/node-js-logging-use-morgan-and-winston

But is that possible to log/intercept http requests going to external apis or 3rd party apis from one single place in my express js app instead of me writing logger methods everywhere like shown in below code wherever i am making calls using axios app.

    `axios({
      method: 'post',
      url: 'myurl',
      data: bodyFormData,
      config: { headers: {'Content-Type': 'multipart/form-data' }}
      })
      .then(function (response) {
          logger.info(.....);
          console.log(response);
      })
      .catch(function (response) {
          logger.error(.....);
          console.log(response);
      });`
BrsJsk commented 5 years ago

I don't think this is a issue related to winston logger. However, you could try to use next() options in nodejs to call external functions.