Trace any inbounding and outbounding http requests from your Node.js application.
This module aims to ease logging of outbounding and inbounding http requests.
Each http client library like Axios or Request are using http and https Node.js internal modules.
So basically, Hinout
adds listeners to those modules and emits an event once the request is gone or when the application receives a response.
As soon as the event is fired, a formatter formats the event and passes the result to console.log
which is used by default as logging function.
Simply import the module in any file of your application:
import Hinout from 'hinout'
Then start collecting using :
Hinout.collect()
Each http request will be logged using console.log
by default.
outbound
event:
{
eventType: 'OUTBOUND',
timestamp: 1577367889,
host: 'https://foo.bar.com',
method: 'GET',
path: '/'
}
inbound
event:
{
eventType: 'INBOUND',
elapsedTimeInMs: 0,
httpVersion: '1.1',
statusCode: 200,
statusMessage: 'OK',
data: '{"foo":"bar"}',
timestamp: 1577367889
}
collect()
Listen and log every http requests using console.log
as default logging function
Returns an instance of Hinout
setLoggingFunction(loggingFunction)
Override default logging function (console.log
)
Hinout.setLoggingFunction(yourLoggger.info)
// yourLogger.info() will now be used as logging function
Returns an instance of Hinout
This project is in its early stage, so feel free to contribute ! :)