https://github.com/resurfaceio/logger-nodejs
Log API calls with Node.js
https://github.com/resurfaceio/logger-nodejs
api-logger apollo-server apollo-server-express express-middleware http-logger logger-nodejs nodejs
Last synced: about 1 month ago
JSON representation
Log API calls with Node.js
- Host: GitHub
- URL: https://github.com/resurfaceio/logger-nodejs
- Owner: resurfaceio
- License: apache-2.0
- Created: 2017-03-01T05:21:52.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T20:31:11.000Z (about 1 year ago)
- Last Synced: 2025-03-28T00:45:05.874Z (about 2 months ago)
- Topics: api-logger, apollo-server, apollo-server-express, express-middleware, http-logger, logger-nodejs, nodejs
- Language: JavaScript
- Homepage:
- Size: 212 KB
- Stars: 16
- Watchers: 5
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# resurfaceio-logger-nodejs
Easily log API requests and responses to your own security data lake.[](https://badge.fury.io/js/resurfaceio-logger)
[](https://www.codefactor.io/repository/github/resurfaceio/logger-nodejs)
[](https://github.com/resurfaceio/logger-nodejs/blob/master/LICENSE)
[](https://github.com/resurfaceio/logger-nodejs/blob/master/CONTRIBUTING.md)## Contents
- Dependencies
- Installing With npm
- Logging From Express Middleware
- Logging From Apollo Server on Express
- Logging From Specific Express Routes
- Logging With API
- Protecting User Privacy
## Dependencies
Requires Node.js 10.x or later, and Axios http client. No other dependencies to conflict with your app.
## Installing With npm
```
npm install resurfaceio-logger --save
```
## Logging From Express Middleware
After installing the module, add a `HttpLoggerForExpress` instance to your app, after
any body parsers in use.
```js
const express = require('express');
const app = express();
// add body parsers
const resurfaceio = require('resurfaceio-logger');
resurfaceio.HttpLoggerForExpress.add(app, {
url: 'http://localhost:7701/message',
rules: 'include debug'
});
// define routes
```
## Logging From Koa Middleware
After installing the module, add a `HttpLoggerForKoa` instance to your app, after
any body parsers in use.
```js
const Koa = require('koa');
const app = new Koa();
// add body parsers
const resurfaceio = require('resurfaceio-logger');
resurfaceio.HttpLoggerForKoa.add(app, {
url: 'http://localhost:7701/message',
rules: 'include debug'
});
```
## Logging From Apollo Server on Express
After installing the module, add a `HttpLoggerForExpress` instance before calling `applyMiddleware`.
```js
const app = express();
const resurfaceio = require('resurfaceio-logger');
resurfaceio.HttpLoggerForExpress.add(app, {
url: 'http://localhost:7701/message',
rules: 'include debug'
});
const server = new ApolloServer({ ... });
server.applyMiddleware({ app });
```
## Logging From Specific Express Routes
After installing the module, create a logger and call it from the routes of interest.
```js
const express = require('express');
const app = express();
const resurfaceio = require('resurfaceio-logger');
const logger = new resurfaceio.HttpLogger({
url: 'http://localhost:7701/message',
rules: 'include debug'
});
app.get('/', function (request, response) {
response.render('pages/index', function (e, html) {
response.status(200).send(html);
resurfaceio.HttpMessage.send(logger, request, response, html);
});
});
```
## Logging With API
Loggers can be directly integrated into your application using our [API](API.md). This requires the most effort compared with
the options described above, but also offers the greatest flexibility and control.
[API documentation](API.md)
## Protecting User Privacy
Loggers always have an active set of rules that control what data is logged
and how sensitive data is masked. All of the examples above apply a predefined set of rules (`include debug`),
but logging rules are easily customized to meet the needs of any application.
---
© 2016-2024 Graylog, Inc.