# @softonic/http-log-format

> Functions to transform native Node.js HTTP requests and responses to the Softonic HTTP log format

Latest version **2.0.0** (published 2020-02-03) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @softonic/http-log-format
pnpm add @softonic/http-log-format
yarn add @softonic/http-log-format
bun add @softonic/http-log-format
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-02-03 |
| First published | 2017-03-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 53.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rubén Norte |
| Maintainers | softonic |
| Keywords | http, log, softonic, request, response |

## Links

- npm: https://www.npmjs.com/package/@softonic/http-log-format
- Repository: https://github.com/softonic/node-http-log-format
- Issues: https://github.com/softonic/node-http-log-format/issues
- npm.io page: https://npm.io/package/@softonic/http-log-format

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [http-headers](https://npm.io/package/http-headers.md) ^3.0.2

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-02-03
- 1.1.2 — 2017-03-17
- 1.1.1 — 2017-03-17
- 1.1.0 — 2017-03-17
- 1.0.0 — 2017-03-14

## README

# @softonic/http-log-format

Functions to transform native Node.js HTTP requests and responses to the Softonic HTTP log format

## Installation

```bash
npm install @softonic/http-log-format
```

## Usage

```js
// CommonJS
// const http = require('http');
// const {
//   formatRequest,
//   formatResponse,
//   stringifyRequest,
//   stringifyResponse,
// } = require('@softonic/http-log-format');

// ES2015
import http from 'http';
import {
  formatRequest,
  formatResponse,
  stringifyRequest,
  stringifyResponse,
} from '@softonic/http-log-format';

http.createServer((req, res) => {
  // send response...

  const formattedRequest = formatRequest(req, {
    // whitelist and blacklist should not be used together
    whitelistHeaders: ['accept', 'accept-language', 'host'],
    blacklistHeaders: ['cookie'],
  });
  const formattedResponse = formatResponse(res, {
    // whitelist and blacklist should not be used together
    whitelistHeaders: ['content-type', 'content-language', 'content-length'],
    blacklistHeaders: ['set-cookie'],
  });

  const message = `${stringifyRequest(req) ${stringifyResponse(res)}}`;

  // Some logger instance
  logger.info({
    request: formattedResponse,
    response: formattedResponse,
  }, message);
});

http.request(options, (res) => {
  // process response...

  const formattedRequest = formatRequest(res.req, {
    // whitelist and blacklist should not be used together
    whitelistHeaders: ['accept', 'accept-language', 'host'],
    blacklistHeaders: ['cookie'],
  });
  const formattedResponse = formatResponse(res, {
    // whitelist and blacklist should not be used together
    whitelistHeaders: ['content-type', 'content-language', 'content-length'],
    blacklistHeaders: ['set-cookie'],
  });

  const message = `${stringifyRequest(res.req) ${stringifyResponse(res)}}`;

  // Some logger instance
  logger.info({
    request: formattedResponse,
    response: formattedResponse,
  }, message);
});
```

## Testing

Clone the repository and execute:

```bash
npm test
```

## Contribute

1. Fork it: `git clone https://github.com/softonic/node-http-log-format.git`
2. Create your feature branch: `git checkout -b feature/my-new-feature`
3. Commit your changes: `git commit -am 'Added some feature'`
4. Check the build: `npm run build`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

---
_Source: https://npm.io/package/@softonic/http-log-format · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
