Socket
Socket
Sign inDemoInstall

simple-express-logs

Package Overview
Dependencies
64
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    simple-express-logs

Simple request logging middleware for Express


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

simple-express-logs

Simple express logging middleware

Are you prototyping an Express app and want a simple way to log all requests? Good news, you're looking at it.

Install

$ npm install --save simple-express-logs

Usage

const express = require('express');
const logger = require('simple-express-logs');

const app = express();
app.use(logger());

Or, in one line:

app.use(require('simple-express-logs')());

Output

By default, simple-express-logs outputs a timestamp, whether the request was made over HTTP or HTTPS, the HTTP verb, the path, the source IP, and the reverse DNS host (if available.)

20:06 1/15/2019 UTC: https POST /api/items/ from 24.63.26.119
5:17 1/8/2019 UTC: https GET /favicon.ico from 66.249.66.152 (crawl-66-249-66-152.googlebot.com)
20:06 1/15/2019 UTC: http GET / from 24.63.26.119 (c-24-63-26-119.hsd1.ma.comcast.net) referred by https://www.google.com
20:06 1/15/2019 UTC: http GET /style.css from 24.63.26.119 (c-24-63-26-119.hsd1.ma.comcast.net)

Options

Both the the header values and request body are not logged by default, but may be enabled when adding the middleware.

app.use(logger({ headers: true }));
23:15 1/25/2019 UTC: http POST /api/test/?type=sample Headers: { host: "localhost:8080", user-agent: "HTTPie/0.9.9", accept-encoding: "gzip, deflate", accept: "application/json, */*", connection: "keep-alive", content-type: "application/json", content-length: "24" }

Logging the body relies on the body property of the request to be populated, so make sure to do that before using the logger.

app.use(bodyParser.json());
app.use(logger({ body: true }));
23:15 1/25/2019 UTC: http POST /api/test/?type=sample Body: {"VehicleColor":"Blue"}

By default, reverse DNS is used to log the request's host.

app.use(logger());
5:17 1/8/2019 UTC: https GET /favicon.ico from 66.249.66.152 (crawl-66-249-66-152.googlebot.com)

This can be disabled with the reverseDNS option.

app.use(logger({ reverseDNS: false }));
5:17 1/8/2019 UTC: https GET /favicon.ico from 66.249.66.152

License

MIT © Jesse T Youngblood

Keywords

FAQs

Last updated on 27 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc