zuora-access-logger
v0.0.8
Published
A logger which can be used out-of-box.
Downloads
12
Readme
zuora-access-logger
This is a log solution which could be used out-of-box.
Features
- add an access log item automatically for each request.
- filter un-interested access, like healthcheck, assets
- auto-rotate
- configurable
- on-demand debug
zuora-request-id
support.
How to Use
Create wrapper module
const Logger = require('zuora-access-logger');
const path = require('path');
// the following logger will skip requests for healthcheck and static asset accesses.
// and only append debug items when there is a `zuora-log-level` header and its value is either `debug` or `trace`.
const logger = new Logger({
logPath: path.join(__dirname, '../log'),
excluded: ["/auth/api/healthcheck", new RegExp(/\/auth\/static\/.*/)],
debugWhen: function(req) {
var logLevel = (req.headers["zuora-log-level"] || "info").toLowerCase();
return (logLevel === "debug" || logLevel === "trace");
}
});
exports = module.exports = logger;
excluded
is an array, item value could be string
or instance of RegExp
.
Register the logger middleware to your express app.
const {loggerMiddleware} = require('./logger');
app.use(loggerMiddleware);
Log
const {log, debug} = require('./logger');
...
log('key', 1234);
debug('key2', 'debug info');
Then you will see something like the following in your access.log
file.
2017-10-19T01:38:52.077Z, method=POST, url=/auth/api/login, zuora-request-id=2839823-238293-2382, status=200, remoteAddr=::1, executeTime=39.174, agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36, key=1234, key2=debug info
To log an error
const {gack} = require('./logger');
try {
...
} catch (error) {
gack(error, req);
}
And then, you will be able to find the error details in error.log
.