Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-ltsv-logger

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-ltsv-logger

ltsv formated access logger for connect based application

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Introduction

LTSV format logger for (connect|express).

This is just a wrapper of connect.middleware.logger.

Usage

var express = require("express"),
    ltsvlogger = require('connect-ltsv-logger');

// define output WriteStream
var out = fs.createWriteStream("ltsv-access.log",{flags: 'a+'}),

// define tokens
var ltsv = [];
ltsv.push("host");
ltsv.push("ident");
ltsv.push("user");
ltsv.push("time");
ltsv.push("req");
ltsv.push("status");
ltsv.push("size");
ltsv.push("referer");
ltsv.push("ua");

var app = express();
app.configure(function(){
	// app.set(/*snip*/)
	// ...

	app.use(ltsvlogger({format:ltsv,stream:out}));

	// app.use(/*snip*/)
	// ...
});

tail -f ltsv-access.log
host:127.0.0.1<TAB>ident:-<TAB>user:-<TAB>time:[13/Feb/2013:19:15:44 +09:00]<TAB>req:GET /stylesheets/style.css HTTP/1.1<TAB>status:200<TAB>size:110<TAB>referer:http://localhost:3001/<TAB>ua:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17

Options

  • format: Format string or Token array, see below for tokens
  • stream :is the same as connect.logger.
  • buffer: is the same as connect.logger.
  • immediate: is the same as connect.logger.

Formats

Just override connect.logger's formats as ltsv

  • default

host:127.0.0.1<TAB>ident:-<TAB>user:-<TAB>time:[Wed, 13 Feb 2013 10:00:55 GMT]<TAB>req:GET / HTTP/1.1<TAB>status:200<TAB>size:110<TAB>referer:-<TAB>ua:-

  • short

host:127.0.0.1<TAB>ident:-<TAB>req:GET / HTTP/1.1<TAB>status:200<TAB>size:-<TAB>response-time:1 ms

  • tiny

req:GET /<TAB>status:200<TAB>size:-<TAB>response-time:1 ms

  • dev

concise output colored by response status for development use (Not ltsv format).

Tokens

The following tokens are available

  • time

    logger.token("time",function(){
      return "[" + moment().format("DD/MMM/YYYY:HH:mm:ss Z") + "]" ;
    });
    
  • host

    logger.token("host",function(req,res){
      return req.connection.address().address || '-';
    });
    
  • X-Forwarded-For

    logger.token("X-Forwarded-For",function(req,res){
      return res.getHeader("X-Forwarded-For") || "-";
    });
    
  • user

    logger.token("user",function(req,res){
      return '-';
    });
    
  • ident

    logger.token("ident",function(req,res){
      return '-';
    });
    
  • req

    logger.token("req",function(req,res){
      var ret = [];
      ret.push(req.method);
      ret.push(req.url);
      ret.push("HTTP/"+req.httpVersion);
      return ret.join(" ");
    });
    
  • method

    logger.token("method",function(req,res){
      return req.method;
    });
    
  • uri

    logger.token("uri",function(req,res){
      return url.parse(req.url).href;
    });
    
  • protocol

    logger.token("protocol",function(req,res){
      return url.parse(req.url).protocol;
    });
    
  • status

    logger.token("status",function(req,res){
      return res.statusCode;
    });
    
  • size

    logger.token("size",function(req,res){
      return res.getHeader("content-length");
    });
    
  • reqsize

    logger.token("reqsize",function(req,res){
      if(req.body) return req.body.length;
      return "-";
    });
    
  • referer

    logger.token("referer",function(req,res){
      return req.headers['referer'] || req.headers['referrer'];
    });
    
  • ua

    logger.token("ua",function(req,res){
      return req.headers['user-agent'];
    });
    
  • vhost

    logger.token("vhost",function(req,res){
      return req.headers["host"];
    });
    
  • reqtime

    logger.token("reqtime",function(req,res){
      return new Date - req._startTime;;
    });
    
  • X-Cache

    logger.token("X-Cache",function(req,res){
      return res.getHeader('X-Cache');
    });
    
  • X-Runtime

    logger.token("X-Runtime",function(req,res){
      return res.getHeader('X-Runtime');
    });
    

Install

npm do

npm install connect-ltsv-logger

License

Source code can be found on github, licenced under MIT.

Author

Developed by Takeharu.Oshida

Contributor

Keywords

FAQs

Package last updated on 24 Feb 2013

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc