simple-express-json-logger
A simple middleware for express that logs in a json format.
Last updated 5 years ago by slooker .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install simple-express-json-logger 
SYNC missed versions from official npm registry.

simple-express-json-logger

simple-express-json-logger is a simple express middleware that will output a very simple log in JSON format.

requestTimeLength is in milliseconds.

Usage

var express = require('express');
var simpleJsonLogger = require('simple-express-json-logger');
// Setup your express app
var app = express();
app.use(simpleJsonLogger.logger);

Now on every request, you'll get something similar to this:

{"path":"/","method":"GET","requestTimeLength":"6.55","ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36","ip":"::1","time":"2015-10-21 13:35:37"}

Logstash UDP support

If you supply a host and a port when you initiate simple-express-json-logger, you'll get log entries to your UDP server.

var express = require('express');
var simpleJsonLogger = require('simple-express-json-logger');
// Setup your express app
var app = express();
// Send message via udp to logstash.server.com:12345
app.use(simpleJsonLogger.logger('logstash.server.com', 12345));

Setup your logstash server like so:

input {
  udp {
    port => 12345
    type => 'node-logs' // Or whatever you want the logs to show up as
    codec => 'json'
  }
  output {
    // Whatever you want
  }
}

You can also use the optional flag to turn off the console.log message so you can get only the UDP message sent.

app.use(simpleJsonLogger.logger('logstash.server.com', 12345, { disableConsole: true }));

You can log environmental variables as well, like by adding them to the array in your options:

app.use(simpleJsonLogger('logstash.server.com', 12345, {
  loggedFromEnv: ['envVar1', 'envVar2']
));

You can also add arbitrary tags that will get forwarded to your logs.

app.use(simpleJsonLogger.logger('logstash.server.com', 12345, {
  tags: ['web server 1', 'staging environment']
));

License

simple-express-json-logger is licensed under ISC.

About

simple-express-json-logger was developed by the team at Wedgies.

Wedgies is a digital survey platform that gives media, journalists and brands in-line survey capabilities inside social media, their website, and their apps — where they can collect millions of opinions from their readers and users. Wedgies is the leading social survey platform that enables publishers to collect survey respondents directly within social media streams.

Wedgies, a darling of Tony Hsieh’s Las Vegas’ Vegas Tech Fund, is backed by an all-star list of investors including Greycroft, Advancit Capital, MESA Ventures, Knight Foundation, kbs+ Ventures, Battle Born Ventures, Twilio, 500 Startups and SV Angel.

Wedgies founding team consists of top talent in developer tools and community management with experience that includes Zappos.com, Overstock.com, and Backcountry.com.

Built with Wedgies

Current Tags

  • 1.1.4-beta4                                ...           beta (5 years ago)
  • 1.1.3                                ...           latest (5 years ago)

26 Versions

  • 1.1.4-beta4                                ...           5 years ago
  • 1.1.4-beta3                                ...           5 years ago
  • 1.1.4-beta2                                ...           5 years ago
  • 1.1.4-beta1                                ...           5 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.18                                ...           5 years ago
  • 1.0.17                                ...           5 years ago
  • 1.0.16                                ...           5 years ago
  • 1.0.15                                ...           5 years ago
  • 1.0.14                                ...           5 years ago
  • 1.0.13                                ...           5 years ago
  • 1.0.12                                ...           5 years ago
  • 1.0.11                                ...           5 years ago
  • 1.0.10                                ...           5 years ago
  • 1.0.9                                ...           5 years ago
  • 1.0.8                                ...           5 years ago
  • 1.0.7                                ...           5 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |