GithubHelp home page GithubHelp logo

isabella232 / common-log-object Goto Github PK

View Code? Open in Web Editor NEW

This project forked from npm/common-log-object

0.0 0.0 0.0 41 KB

Dead stupid function to generate a common-log-format-ish string from request & response objects.

License: ISC License

JavaScript 100.00%

common-log-object's Introduction

common-log-string

Dead stupid function to generate a common-log-format-ish string from request & response objects. Not guaranteed to work with anything other than node-restify.

on npm Tests

I wrote this because I wanted something that didn't attempt to write things to a log file and could be plugged into restify as middleware. Sample output:

- - [12/Mar/2015:08:54:46 -0700] "GET /_monitor/ping HTTP/1.1" 200 6 "" "HTTPie/0.8.0"

How to use:

var restify = require('restify');
var logstring = require('common-log-string');

var server = restify.createServer();
server.on('after', request, response, route, error)
{
    var output = logstring(request, response);
    request.logger.info(output);
});

Order of fields:

  1. client ip
  2. client id as per RFC 1413; (unfilled)
  3. userid as determined by http auth (unfilled by this implementation)
  4. timestamp
  5. http request line
  6. response status code
  7. length of response body, if available
  8. referrer string, from request headers
  9. user agent string, from request headers
  10. accept string, from request headers
  11. elapsed time in milliseconds

The second to last is non-standard but useful.

Options

You may optionally pass an options object as the third parameter to the function. One option is currently respected:

ipHeader: report the client IP from this header instead of the address of the remote socket. Useful if you wish to log X-Forwarded-For IPs instead of the IP of an intermediate proxy.

LICENSE

ISC.

common-log-object's People

Contributors

ceejbot avatar jefflembeck avatar rockbot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.