@nahanil/sails-hook-api-log
v1.0.0
Published
Terse Sails.js request logging middleware
Downloads
3
Maintainers
Readme
@nahanil/sails-hook-api-log
Terse request logging for Sails.js applications.
Forked from Mike McNeil's pretty awesome sails-hook-apianalytics.
Install
yarn add @nahanil/sails-hook-api-log
That's it! Next time you lift, and then send a request to the server, you should see stuff getting logged.
Configuration
Optionally, you can customize this hook in a few different ways by configuring sails.config['api-log]
.
For instance, you might create config/api-log.js
:
module.exports = {
'api-log': {
/**
* An array of route addresses to monitor.
*
* (e.g. [ 'GET /foo/bar', 'POST /foo', 'all /admin/*' ])
*
* Defaults to logging all POST, PATCH, PUT, DELETE requests, and all
* GET requests except for those that appear to be for assets
* (i.e. using "GET r|^((?![^?]*\\/[^?\\/]+\\.[^?\\/]+(\\?.*)?).)*$|")
*/
routesToLog: [
// If you want to log everything- including requests for assets, use the following:
'/*'
],
/**
* Custom log function
* Uses `console.log` by default and recieves the text string that would be logged
*/
logFn: (str) => {
console.log(`APILOG: ${str}`)
}
}
}