Search code examples
node.jsloggingrestify

Filter parameters on restify log


I have a restify api set up with the audit logger plugin, I have the option to also log the body set to true, but I want to be able to either filter or remove parameters sent on the body and header, like password or token which are currently being saved on restify's logs.

Example of current log:

req: {
    "headers": {
          "authorization": "Token token=**youshouldnotseeme**,provider=**hellno**",
          "date": "Wed, 09 Oct 2013 17:10:53 GMT",
          "host": "localhost:8082",
          "connection": "keep-alive"
    }
     "body": {
          "username": "somedude",
          "password": "**youshouldnotseeme**"
     }
}

Example of what I would like:

req: {
    "headers": {
          "authorization": "Token token=**[FILTERED]**,provider=**[FILTERED]**",
          "date": "Wed, 09 Oct 2013 17:10:53 GMT",
          "host": "localhost:8082",
          "connection": "keep-alive"
    }
     "body": {
          "username": "somedude",
          "password": "**[FILTERED]**"
     }
}

So how would I be able to achieve this?

Thank you.


Solution

  • You need to create a custom audit plugin to do this. If you look at the existing code: https://github.com/mcavage/node-restify/blob/master/lib/plugins/audit.js - there really isn't much to it. Create a copy of that and change it to filter out whatever you need, and/or send the output somewhere else.